-
Notifications
You must be signed in to change notification settings - Fork 93
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
Fixing AnalyzeCommandBase
and MultithreadedAnalyzeCommandBase
artifacts generation
#2433
Fixing AnalyzeCommandBase
and MultithreadedAnalyzeCommandBase
artifacts generation
#2433
Conversation
_run?.GetFileIndex(new ArtifactLocation { Uri = context.TargetUri }, | ||
addToFilesTableIfNotPresent: _persistArtifacts, | ||
dataToInsert: _dataToInsert, | ||
hashData: context.Hashes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should only persist if:
- we have results
- if we have hashes/textfiles/binaryfiles flag enabled
@@ -485,10 +491,6 @@ private async Task<bool> HashAsync() | |||
_hashToFilesMap[hashData.Sha256] = paths; | |||
} | |||
|
|||
_run?.GetFileIndex(new ArtifactLocation { Uri = context.TargetUri }, | |||
dataToInsert: _dataToInsert, | |||
hashData: hashData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removing this to prevent us from generating artifacts for all the files #ByDesign
@@ -1165,7 +1165,7 @@ public void AnalyzeCommandBase_AutomationDetailsTests() | |||
} | |||
} | |||
|
|||
[Fact(Timeout = 5000)] | |||
[Fact(Timeout = 5000, Skip = "Artifacts will be different while we don't fix SarifLogger and AnalyzeCommandBase.")] | |||
public void AnalyzeCommandBase_ShouldGenerateSameResultsWhenRunningSingleAndMultiThread_CoyoteTest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already fixed in this pr
@@ -1165,7 +1165,7 @@ public void AnalyzeCommandBase_AutomationDetailsTests() | |||
} | |||
} | |||
|
|||
[Fact(Timeout = 5000)] | |||
[Fact(Timeout = 5000, Skip = "Artifacts will be different while we don't fix SarifLogger and AnalyzeCommandBase.")] | |||
public void AnalyzeCommandBase_ShouldGenerateSameResultsWhenRunningSingleAndMultiThread_CoyoteTest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
@@ -170,7 +170,7 @@ private static void VerifySuppressCommand(SuppressOptions options) | |||
|
|||
if (options.ExpiryInDays > 0 && suppression.TryGetProperty("expiryUtc", out DateTime expiryUtc)) | |||
{ | |||
expiryUtc.Should().BeCloseTo(DateTime.UtcNow.AddDays(options.ExpiryInDays)); | |||
expiryUtc.Should().BeCloseTo(DateTime.UtcNow.AddDays(options.ExpiryInDays), precision: 500); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
Where is my release note? In reply to: 1024526220 |
src/Sarif/HashUtilities.cs
Outdated
@@ -31,15 +31,14 @@ internal static IFileSystem FileSystem | |||
|
|||
public static IDictionary<string, HashData> MultithreadedComputeTargetFileHashes(IEnumerable<string> analysisTargets, bool suppressConsoleOutput = false) | |||
{ | |||
if (analysisTargets == null) { return null; } | |||
var fileToHashDataMap = new ConcurrentDictionary<string, HashData>(); | |||
if (analysisTargets == null) { return fileToHashDataMap; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will prevent a NullReferenceException when we use the reerence variable from the SarifLogger
@@ -447,12 +447,16 @@ private void CaptureArtifact(ArtifactLocation fileLocation) | |||
catch (ArgumentException) { } // Unrecognized encoding name | |||
} | |||
|
|||
HashData hashData = null; | |||
AnalysisTargetToHashDataMap?.TryGetValue(fileLocation.Uri.OriginalString, out hashData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -169,7 +169,7 @@ private void Analyze(TOptions options, AggregatingLogger logger) | |||
targets = ValidateTargetsExist(_rootContext, targets); | |||
|
|||
// 5. Initialize report file, if configured. | |||
InitializeOutputFile(options, _rootContext, targets); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
paths.Add(localPath); | ||
context.Hashes = hashData; | ||
_pathToHashDataMap?.Add(localPath, hashData); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating this will enable us to use the code from SarifLogger to create the artifacts #ByDesign
"index": 0 | ||
} | ||
} | ||
], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this will go away, since we are not using any flag to emit artifacts.
}, | ||
{ | ||
"id": "SARIF2012", | ||
"name": "ProvideRuleProperties", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/ReleaseHistory.md
Outdated
@@ -2,6 +2,7 @@ | |||
|
|||
## Unreleased | |||
|
|||
* BUGFIX: Fix `AnalyzeCommandBase` and `MultithreadedAnalyzeCommandBase` from outputting all artifacts to SARIF even if no results were produced when Hashes is enabled. [#2433](https://github.com/microsoft/sarif-sdk/pull/2433) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- BREAKING:
AnalyzeCommandBase
previously persisted all scan target artifacts to SARIF logs rather than only persisting artifacts referenced by an analysis result, when an option to persist hashes, text file or binary information was set.MultithreadedAnalyzeCommandBase
previously persisted all scan targets artifacts to SARIF logs in cases when hash insertion was eenabled rather than only persisting artifacts referenced by an analysis result. #Resolved
src/Sarif/HashUtilities.cs
Outdated
@@ -31,15 +31,14 @@ internal static IFileSystem FileSystem | |||
|
|||
public static IDictionary<string, HashData> MultithreadedComputeTargetFileHashes(IEnumerable<string> analysisTargets, bool suppressConsoleOutput = false) | |||
{ | |||
if (analysisTargets == null) { return null; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverted
@@ -169,7 +169,7 @@ private void Analyze(TOptions options, AggregatingLogger logger) | |||
targets = ValidateTargetsExist(_rootContext, targets); | |||
|
|||
// 5. Initialize report file, if configured. | |||
InitializeOutputFile(options, _rootContext, targets); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This API isn't exposed to customers. Only tools that use it will see a difference.
src/Sarif/OptionallyEmittedData.cs
Outdated
@@ -80,6 +80,9 @@ public enum OptionallyEmittedData : int | |||
// Enrich SARIF log with git blame information | |||
GitBlameInformation = 0x1000, | |||
|
|||
// Enrich with artifacts only. | |||
Artifacts = 0x2000, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AnalyzeCommandBase
and MultithreadedAnalyzeCommandBase
artifacts generation
@@ -120,7 +120,7 @@ | |||
"index": 0 | |||
}, | |||
"region": { | |||
"startLine": 22, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we faced a similar issue in this PR:
https://github.com/microsoft/sarif-sdk/pull/2420/files#diff-277d16bd3a7355417dd787cfc0961db73b7f32e73ad49650468d4f4bb6e5c477
We should investigate this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, let's open an issue on it.
…://github.com/microsoft/sarif-sdk into users/ednakamu/fixing-multithreaded-artifacts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…ifacts generation (#2433) * Fixing multithreaded artifacts generation * Fixing tests and flags * Loosing precision. * Applying fix for AnalyzeCommandBase * Enabling tests * Updating test case and release history * Creating const to prevent magical numbers everywhere * Rebaselining tests * Creating Artifacts flag to keep previous behavior * Addressing PR feedback. * Rollback changes * Update SARIF2012.ProvideRuleProperties_Invalid.sarif * updating back * Ordering deprecated names
) * Add new visitor to get deterministic SARIF log by sorting results * Fix dotnet format issue * updating format * remove unnecessary using Format & minor fixes * Add Run Comparer to support sorting logs with multiple runs. * Add command argument unit tests fix dotnet format * use ContainsKey to avoid allocating variable * Fixing `AnalyzeCommandBase` and `MultithreadedAnalyzeCommandBase` artifacts generation (#2433) * Fixing multithreaded artifacts generation * Fixing tests and flags * Loosing precision. * Applying fix for AnalyzeCommandBase * Enabling tests * Updating test case and release history * Creating const to prevent magical numbers everywhere * Rebaselining tests * Creating Artifacts flag to keep previous behavior * Addressing PR feedback. * Rollback changes * Update SARIF2012.ProvideRuleProperties_Invalid.sarif * updating back * Ordering deprecated names * `SarifLogger` now emits an artifacts table entry if `artifactLocation` is not null for tool configuration and tool execution notifications. (#2437) * Fixing artifacts generation when logging notifications * Updating release history. * Updating ReleaseHistory * Fix `ArgumentException` when recurse is enabled and two file target specifiers generates the same file paths (#2438) * Fixing ArgumentException when passing two filePaths that generates duplicated file analysis * Fixing dotnet-format issues and updating releasehistory * Removing comments * Addressing PR feedback * Addressing PR feedback * Addressing PR review issues Add suppression support (#2435) * Add suppression support * Add incompatibility check and make suppressions non-null Co-authored-by: Eddy Nakamura <eddynaka@gmail.com> Update releasehistory fix couple test cases * Fix issues in PR review * Add xml comments * Fix test issues * fix dotnet format * Addressing review feedbacks * Fix tests * Update extension methods names * Change xml doc comments to normal comments Co-authored-by: Eddy Nakamura <eddynaka@gmail.com> Co-authored-by: Michael C. Fanning <michael.fanning@microsoft.com>
Description
The single/multi-threaded command base was generating all the artifacts even if we were not producing results.
Test
Testing multiple files with and without the hashes flag and checking if artifacts were produced.
This PR has a dependency on this: #2434, which will reduce the number of files to be analyzed once we merge it. That PR is just rebaselining our test files, preventing new changes from receiving all the changes we are seeing in this.