Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker: run dynamic and static analysis unconditionally #921

Merged
merged 3 commits into from
Oct 16, 2023

Conversation

maxfisher-g
Copy link
Contributor

Currently in the worker binary, the sequence of analysis actions is:

  1. run dynamic analysis
  2. run static analysis
  3. upload static analysis results to resultstore (downloading and saving package occurs as a side effect).
  4. upload dynamic analysis results to resultstore

However, after each step above if any error has occurred, the function returns immediately and the remaining steps are skipped. It makes more sense to run both dynamic analysis and static analysis without returning from any errors until both analysis types have been attempted.

Thus the new sequence of actions is

  1. run static analysis and if successful, upload results to resultstore (downloading and saving package occurs as a side effect)
  2. run dynamic analysis and if successful, upload results to resultstore
  3. if any error occurs in steps 1 or 2 (or both), return it or them

(Also inlines the if err := ... ; err != nil { } form for the notification.PublishAnalysisCompletion function)

… errors for one type of analysis cause the other to be skipped (including saving of results)

Signed-off-by: Max Fisher <[email protected]>
Comment on lines +158 to +162
// run both dynamic and static analysis regardless of error status of either
// and return combined error(s) afterwards, if applicable
staticResults, _, staticAnalysisErr := worker.RunStaticAnalysis(ctx, pkg, staticSandboxOpts, staticanalysis.All)
if staticAnalysisErr == nil {
staticAnalysisErr = worker.SaveStaticAnalysisData(ctx, pkg, resultStores, staticResults)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a rationale for changing the order of static analysis and dynamic analysis?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally I only put static after dynamic because it was conditionally run, I think it makes sense to have static analysis running first because

  1. Static analysis requires downloading the package archive and this may end up being able to be reused for dynamic analysis. The saving analyzed package feature can also potentially reuse this download
  2. For some reason, static analysis data was saved before dynamic analysis before, so now that the saving is paired with the running, it means that the order of saving results is the same.
  3. static analysis is usually faster than dynamic analysis

All that said, it shouldn't make a huge difference. If you feel strongly that the order should be kept as is, we can do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

All good. I appreciate understanding the rationale and it helps to have context in the PR for the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries and I agree it's good to have the context here too :)

Comment on lines +158 to +162
// run both dynamic and static analysis regardless of error status of either
// and return combined error(s) afterwards, if applicable
staticResults, _, staticAnalysisErr := worker.RunStaticAnalysis(ctx, pkg, staticSandboxOpts, staticanalysis.All)
if staticAnalysisErr == nil {
staticAnalysisErr = worker.SaveStaticAnalysisData(ctx, pkg, resultStores, staticResults)
Copy link
Contributor

Choose a reason for hiding this comment

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

All good. I appreciate understanding the rationale and it helps to have context in the PR for the future.

@maxfisher-g maxfisher-g merged commit 5133dd6 into main Oct 16, 2023
@maxfisher-g maxfisher-g deleted the worker_no_error_interference branch October 16, 2023 02:38
maxfisher-g added a commit that referenced this pull request Oct 16, 2023
* worker: run dynamic and static analysis unconditionally and don't let errors for one type of analysis cause the other to be skipped (including saving of results)

Signed-off-by: Max Fisher <[email protected]>

* run static analysis before dynamic analysis to preserve order of saving

Signed-off-by: Max Fisher <[email protected]>

---------

Signed-off-by: Max Fisher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants