Skip to content

[Security Solution] modify circular deps checker to output images of circular deps graphs#75579

Merged
oatkiller merged 1 commit intoelastic:masterfrom
oatkiller:circular-deps-checker-image
Aug 21, 2020
Merged

[Security Solution] modify circular deps checker to output images of circular deps graphs#75579
oatkiller merged 1 commit intoelastic:masterfrom
oatkiller:circular-deps-checker-image

Conversation

@oatkiller
Copy link
Copy Markdown
Contributor

@oatkiller oatkiller commented Aug 20, 2020

Summary

The Security Solution team has a script that tries to block circular dependencies between typescript files. When the script detects a circular dependency it will now attempt to use graphviz to output an SVG showing a visualization of the circular dependency. This should help developers understand the circular dependency.

image

When run with `--help`
raustin-mbp:security_solution raustin$ node scripts/check_circular_deps --help

  node scripts/check_circular_deps

  Check the Security Solution plugin for circular deps. If any are found, this will throw an Error.

  Options:
    --svg,             Output SVGs of circular dependency graphs
    --verbose, -v      Log verbosely
    --debug            Log debug messages (less than verbose)
    --quiet            Only log errors
    --silent           Don't log anything
    --help             Show this message
When there is a circular dep and no flags were passed
raustin-mbp:security_solution raustin$ node scripts/check_circular_deps
=============

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.2.1 <3.5.0

YOUR TYPESCRIPT VERSION: 3.9.5

Please only submit bug reports when using the officially supported version.

=============
Run this program with the --svg flag to save an SVG showing the dependency graph.
ERROR SIEM circular dependencies of imports has been found:
       - public/timelines/store/timeline/types.ts,public/timelines/store/timeline/model.ts,public/common/store/types.ts
When graphviz is installed and there is a circular dep and `--svg` was passed:
raustin-mbp:security_solution raustin$ node scripts/check_circular_deps --svg
=============

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.2.1 <3.5.0

YOUR TYPESCRIPT VERSION: 3.9.5

Please only submit bug reports when using the officially supported version.

=============
Attempting to save SVG for circular dependency: public/timelines/store/timeline/types.ts,public/timelines/store/timeline/model.ts,public/common/store/types.ts
Saved SVG: /var/folders/1r/y028x41x3kxd8jzrgf3vf3dr0000gp/T/security_solution-circular-dep-0.svg
ERROR SIEM circular dependencies of imports has been found:
       - public/timelines/store/timeline/types.ts,public/timelines/store/timeline/model.ts,public/common/store/types.ts
when there are 2 circular deps and you use `--svg`
raustin-mbp:security_solution raustin$ node scripts/check_circular_deps --svg
=============

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.2.1 <3.5.0

YOUR TYPESCRIPT VERSION: 3.9.5

Please only submit bug reports when using the officially supported version.

=============
Attempting to save SVG for circular dependency: public/app/404.tsx,public/network/routes.tsx
Saved SVG: /var/folders/1r/y028x41x3kxd8jzrgf3vf3dr0000gp/T/security_solution-circular-dep-0.svg
Attempting to save SVG for circular dependency: public/timelines/store/timeline/types.ts,public/timelines/store/timeline/model.ts,public/common/store/types.ts
Saved SVG: /var/folders/1r/y028x41x3kxd8jzrgf3vf3dr0000gp/T/security_solution-circular-dep-1.svg
ERROR SIEM circular dependencies of imports has been found:
       - public/app/404.tsx,public/network/routes.tsx
       - public/timelines/store/timeline/types.ts,public/timelines/store/timeline/model.ts,public/common/store/types.ts
when there are two circular deps and no flags were passed
raustin-mbp:security_solution raustin$ node scripts/check_circular_deps
=============

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.2.1 <3.5.0

YOUR TYPESCRIPT VERSION: 3.9.5

Please only submit bug reports when using the officially supported version.

=============
Run this program with the --svg flag to save an SVG showing the dependency graph.
ERROR SIEM circular dependencies of imports has been found:
       - public/app/404.tsx,public/network/routes.tsx
       - public/timelines/store/timeline/types.ts,public/timelines/store/timeline/model.ts,public/common/store/types.ts
When there are circular deps, `--svg` was passed, and graphviz isn't installed
raustin-mbp:security_solution raustin$ node scripts/check_circular_deps --svg
=============

WARNING: You are currently running a version of TypeScript which is not officially supported by typescript-estree.

You may find that it works just fine, or you may not.

SUPPORTED TYPESCRIPT VERSIONS: >=3.2.1 <3.5.0

YOUR TYPESCRIPT VERSION: 3.9.5

Please only submit bug reports when using the officially supported version.

=============
Attempting to save SVG for circular dependency: public/timelines/store/timeline/types.ts,public/timelines/store/timeline/model.ts,public/common/store/types.ts
ERROR UNHANDLED ERROR
ERROR Error: Graphviz could not be found. Ensure that "gvpr" is in your $PATH.
      Error: Command failed: gvpr -V
      /bin/sh: gvpr: command not found

          at exec.catch (/Users/raustin/Code/elastic/kibana/node_modules/madge/lib/graph.js:36:10)

Checklist

For maintainers

@oatkiller oatkiller requested a review from XavierM August 20, 2020 16:47
@oatkiller oatkiller requested review from a team as code owners August 20, 2020 16:47
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Should I write one image per circular that is found?
  • Should I only run this logic if a flag is passed to the script?
  • Any other good ideas?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think having it behind a flag makes sense. Depending on the output I can go either way for individual vs grouped images

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great thanks!

@michaelolo24
Copy link
Copy Markdown
Contributor

Can you add an example of what this outputs from your other PR?

@oatkiller oatkiller force-pushed the circular-deps-checker-image branch from 0ee93a8 to d3c5b83 Compare August 20, 2020 21:03
@oatkiller oatkiller added release_note:skip Skip the PR/issue when compiling release notes v7.10.0 labels Aug 20, 2020
Copy link
Copy Markdown
Contributor

@FrankHassanabad FrankHassanabad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! 👍

Copy link
Copy Markdown
Contributor

@dplumlee dplumlee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow nice markdown

@kibanamachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

  • 💚 Build #69460 succeeded 0ee93a87b203c5e4d82ba4226ab617e2611dde86

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@oatkiller oatkiller merged commit da0da4c into elastic:master Aug 21, 2020
oatkiller pushed a commit to oatkiller/kibana that referenced this pull request Aug 21, 2020
oatkiller pushed a commit that referenced this pull request Aug 21, 2020
gmmorris added a commit to gmmorris/kibana that referenced this pull request Aug 21, 2020
* master: (71 commits)
  [Lens] Show 'No data for this field' for empty field in accordion (elastic#73772)
  Skip failing lens test
  Configure ScopedHistory consistenty regardless of URL used to mount app (elastic#75074)
  Fix returned payload by "search" usage collector (elastic#75340)
  [Security Solution] Fix missing key error (elastic#75576)
  Upgrade EUI to v27.4.1 (elastic#75240)
  Update datasets UI copy to data streams (elastic#75618)
  [Lens] Register saved object references (elastic#74523)
  [DOCS] Update links to Beats documentation (elastic#70380)
  [Enterprise Search] Convert our `public_url` route to `config_data` and collect initialAppData (elastic#75616)
  [Usage Collection Schemas] Remove Legacy entries (elastic#75652)
  [Dashboard First] Lens Originating App Breadcrumb (elastic#75470)
  Improve login UI error message. (elastic#75642)
  [Security Solution] modify circular deps checker to output images of circular deps graphs (elastic#75579)
  [Data Telemetry] Add index pattern to identify "meow" attacks (elastic#75163)
  Migrate CSP usage collector to `kibana_usage_collection` plugin (elastic#75536)
  [Console] Get ES Config from core (elastic#75406)
  [Uptime] Add delay in telemetry test (elastic#75162)
  [Lens] Use index pattern service instead saved object client (elastic#74654)
  Embeddable input (elastic#73033)
  ...
thomasneirynck pushed a commit to thomasneirynck/kibana that referenced this pull request Aug 21, 2020
@oatkiller oatkiller deleted the circular-deps-checker-image branch March 31, 2022 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_note:skip Skip the PR/issue when compiling release notes v7.10.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants