-
Notifications
You must be signed in to change notification settings - Fork 156
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
Using consoleLogger in Telemetry client within MultithreadedAnlyzeCom… #1002
Using consoleLogger in Telemetry client within MultithreadedAnlyzeCom… #1002
Conversation
b0dd6cc
to
c1af956
Compare
TestingIssue was tested with multiple setups SetupRunning analyze --config default --ignorePdbLoadError --hashes --statistics --output C:\Users\marekaldorf\source\repos\software-development-tools-samples\src\MyRun.sarif C:\Users\marekaldorf\source\repos\AllDwarf\BlobStorageTrigger\bin\*.so --log ForceOverwrite You can change the path to point to any empty folder and the sarif you want and reproduce it the same way I did. analyze --config default --ignorePdbLoadError --hashes --statistics --output {PATH_TO_SARIF}\{NAME}.sarif {PATH_TO_EMPTY_FOLDER}\*.so --log ForceOverwrite |
c1af956
to
5648804
Compare
5648804
to
3f42e99
Compare
@@ -48,13 +48,16 @@ private bool IsValidScanTarget(string file) | |||
|
|||
public override BinaryAnalyzerContext InitializeGlobalContextFromOptions(AnalyzeOptions options, ref BinaryAnalyzerContext context) | |||
{ | |||
base.InitializeGlobalContextFromOptions(options, ref context); |
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.
btw! now seems a good time to talk a bit about testing. one thing I observed in the previous change is that you might have broken support for the --quiet
flag. So you might run a test: revert to your previous change and run all tests: hopefully we see that some test protecting the functionality of the quiet switch fired.
I was only peripherally involved with the telemetry client work, unfortunately, so I don't know the state of testing.
This method is very testable, however, you can create this object and call this public method on it. So I would suggest creating some tests that hit this code path.
Verification looks straightforward, populate the object with a non-null Telemetry object, then call this init method and ensure the context.Loggers
property contains what you think that it should.
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.
Yep good point. I tried it with --quiet true
and I think seems to be working as expected no ConsoleLogger set, just telemetry is sent.
C:\Users\marekaldorf\source\repos\binskim\bld\bin\x64_Debug\netcoreapp3.1\BinSkim.exe (process 40088) exited with code 1.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
context.Logger
in this case it is without ConsoleLogger. It has empty IAnalysisLogger. So in quiet mode this specific code will add one empty logger and one RuleTelemetryLogger together.
I tried to redo it a bit with something like this:
if (this.Telemetry?.TelemetryClient != null)
{
// Create an aggregating logger that will combine all loggers into a single logger.
var aggregatingLogger = new AggregatingLogger();
if (context.Logger is AggregatingLogger)
{
aggregatingLogger = context.Logger as AggregatingLogger;
}
else
{
aggregatingLogger.Loggers.Add(context.Logger);
}
var ruleTelemetryLogger = new RuleTelemetryLogger(this.Telemetry.TelemetryClient);
ruleTelemetryLogger.AnalysisStarted();
// Combine rule telemetry with any other loggers that may be present.
aggregatingLogger.Loggers.Add(ruleTelemetryLogger);
context.Logger = aggregatingLogger;
}
In this case we'll achieve non empty IAnalyseLogger in the first place but it's a bit hacky I would say with the type checks and such WDYT?
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.
just FYI, I'm working now on the test hopefully tomorrow I'll make them working :)
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.
@michaelcfanning just added the tests
…f context.Logger.Loggers
1. Verify ConsoleLogger when telemetry is disabled. 2. Verify ConsoleLogger and RuleTelemetryLogger when telemetry is enabled. 3. Verify RuleTelemetryLogger when quiet option and telemetry are enabled. 4. Verify no loggers when both quiet option and telemetry are disabled.
@@ -8,6 +8,8 @@ | |||
using System.Linq; | |||
using System.Reflection; | |||
|
|||
using CommandLine; |
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.
@@ -150,5 +155,89 @@ private static string[] Shuffle(string[] data) | |||
|
|||
return data; | |||
} | |||
|
|||
[Fact] | |||
public void MultithreadedAnalyzeCommand_InitializeGlobalContextFromOptions_TelemetryNotSpecifiedHasOneConsoleLogger() |
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.
nice tests!
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 pull request includes changes to the
MultithreadedAnalyzeCommand
class insrc/BinSkim.Driver
to enhance logging capabilities by adding a new console logger and ensuring proper namespaces are included.Enhancements to logging:
src/BinSkim.Driver/MultithreadedAnalyzeCommand.cs
: Added aConsoleLogger
to theAggregatingLogger
to enable console logging during analysis.Namespace inclusion:
src/BinSkim.Driver/MultithreadedAnalyzeCommand.cs
: Included theMicrosoft.CodeAnalysis.Sarif.Writers
namespace to support the new logging functionality.