-
Notifications
You must be signed in to change notification settings - Fork 88
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
Trace notifications #2604
Trace notifications #2604
Conversation
…rif-sdk into trace-notifications
/// <param name="associatedRule"> | ||
/// The scan rule, if any, associated with the notification. | ||
/// </param> | ||
void LogToolNotification(Notification notification, ReportingDescriptor associatedRule = 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.
An optional argument in an interface contract is an interesting thing. Any caller to the interface does not need to provide this argument. Anyone implementing this interface can override the optional value.
That can get confusing. I made this change to minimize code churn, so that callers who don't have an associated rule aren't strictly required to provide one.
@@ -305,6 +305,11 @@ private ISet<string> ValidateTargetsExist(TContext context, ISet<string> targets | |||
Policy = policy ?? new PropertiesDictionary() | |||
}; | |||
|
|||
context.Traces = |
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.
@@ -479,6 +479,16 @@ public void LogToolNotification(Notification notification) | |||
_run.Invocations[0].ExecutionSuccessful &= notification.Level != FailureLevel.Error; | |||
|
|||
CaptureFilesInNotification(notification); | |||
|
|||
if (associatedRule != 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.
@@ -1041,7 +1056,31 @@ public static void AnalyzeTargetHelper(TContext context, IEnumerable<Skimmer<TCo | |||
|
|||
try | |||
{ | |||
Stopwatch stopwatch = context.Traces.HasFlag(DefaultTraces.RuleScanTime) |
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.
@@ -663,11 +663,100 @@ public void AnalyzeCommandBase_ReportsWarningOnUnsupportedPlatformForRuleAndNoRu | |||
return run; | |||
} | |||
|
|||
[Fact] | |||
public void AnalyzeCommand_Traces() |
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.
Good things about this test: there are minimal literal constant 'magic values', it runs a comprehensive set of tests and will report on all break (instead of failing on the first one), it nicely buckets all trace testing in one place and can easily be extended. This change also makes some nice incremental improvements to the general test methodology, for example, returning the Run object from the test helper to assist in validation.
int executionNotificationsCount = 0; | ||
int configurationNotificationCount = 0; | ||
|
||
SarifHelpers.ValidateRun( |
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.
|
||
if (executionNotifications?.Where(t => t.Message.Text.Contains("elapsed")).Count() != expectedNotificationsCount) | ||
{ | ||
sb.AppendLine($"\t{trace} : did not observe term 'elapsed' in rule timing notifications."); |
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.
} | ||
} | ||
} | ||
sb.Length.Should().Be(0, $"test cases failed : {Environment.NewLine}{sb}"); |
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.
|
||
foreach (Result result in results) | ||
{ | ||
sb.AppendLine(result.ToString()); |
Check warning
Code scanning / CodeQL
Use of default ToString()
@@ -2035,6 +2145,8 @@ | |||
|
|||
public int ExpectedReturnCode; | |||
|
|||
public int RulesCount; |
Check notice
Code scanning / CodeQL
Missed 'readonly' opportunity
|
||
foreach (Result result in results) | ||
{ | ||
sb.AppendLine(result.ToString()); |
Check notice
Code scanning / CodeQL
Redundant ToString() call
@shaopeng, can you look at this for me? :) |
@michaelcfanning In reply to: 1381184325 |
Very sorry! Please review this change and let me know if you have feedback. :) we've got other worked blocked by this, so I merged already. I will remember to use the proper account reference : @shaopeng-gh . :) |
No description provided.