microsoft / component-detection

Scans your project to determine what components you use
MIT License
396 stars 81 forks source link

Add CancellationToken support to CD processes #1167

Closed pauld-msft closed 2 weeks ago

pauld-msft commented 2 weeks ago

Adds cancellation support for pip report, and sets up the ability for other processes to be cancelled if we choose to do so.

Tested by running locally, here is an example with timeout set to 3: image

And here with it set to 10: image

Snippet from the logs for these runs:

[13:52:58 DBG] PipReport: Cancelled for file 'C:/src/component-detection/test/Microsoft.ComponentDetection.VerificationTests/resources/pip/simple-extras/requirements.txt' with command 'install -r requirements.txt --dry-run --ignore-installed --quiet --report uqz3ardl.l4r'.
[13:52:58 INF] Telemetry record: {
  "RecordName": "PipReportFailure",
  "ExitCode": -1,
  "StdErr": "PipReport: Cancelled for file \u0027C:/src/component-detection/test/Microsoft.ComponentDetection.VerificationTests/resources/pip/simple-extras/requirements.txt\u0027 with command \u0027install -r requirements.txt --dry-run --ignore-installed --quiet --report uqz3ardl.l4r\u0027. ",
  "ExecutionTime": "00:00:00.0192389",
  "Timestamp": "2024-06-12T20:52:58.1639892Z",
  "CorrelationId": "e942f400-f78d-4f33-baba-ae41cbb283ef"
}
[13:52:58 WRN] PipReport: Failure while parsing pip installation report for C:\src\component-detection\test\Microsoft.ComponentDetection.VerificationTests\resources\pip\simple-extras\requirements.txt
System.InvalidOperationException: PipReport: Cancelled for file 'C:/src/component-detection/test/Microsoft.ComponentDetection.VerificationTests/resources/pip/simple-extras/requirements.txt' with command 'install -r requirements.txt --dry-run --ignore-installed --quiet --report uqz3ardl.l4r'.
   at Microsoft.ComponentDetection.Detectors.Pip.PipCommandService.GenerateInstallationReportAsync(String path, String pipExePath, CancellationToken cancellationToken) in C:\src\component-detection\src\Microsoft.ComponentDetection.Detectors\pip\PipCommandService.cs:line 148
   at Microsoft.ComponentDetection.Detectors.Pip.PipReportComponentDetector.OnFileFoundAsync(ProcessRequest processRequest, IDictionary`2 detectorArgs, CancellationToken cancellationToken) in C:\src\component-detection\src\Microsoft.ComponentDetection.Detectors\pip\PipReportComponentDetector.cs:line 107
[13:52:58 INF] Telemetry record: {
  "RecordName": "FailedParsingFile",
  "DetectorId": "PipReport",
  "FilePath": "C:\\src\\component-detection\\test\\Microsoft.ComponentDetection.VerificationTests\\resources\\pip\\simple-extras\\requirements.txt",
  "ExceptionMessage": "PipReport: Cancelled for file \u0027C:/src/component-detection/test/Microsoft.ComponentDetection.VerificationTests/resources/pip/simple-extras/requirements.txt\u0027 with command \u0027install -r requirements.txt --dry-run --ignore-installed --quiet --report uqz3ardl.l4r\u0027.",
  "StackTrace": "   at Microsoft.ComponentDetection.Detectors.Pip.PipCommandService.GenerateInstallationReportAsync(String path, String pipExePath, CancellationToken cancellationToken) in C:\\src\\component-detection\\src\\Microsoft.ComponentDetection.Detectors\\pip\\PipCommandService.cs:line 148\r\n   at Microsoft.ComponentDetection.Detectors.Pip.PipReportComponentDetector.OnFileFoundAsync(ProcessRequest processRequest, IDictionary\u00602 detectorArgs, CancellationToken cancellationToken) in C:\\src\\component-detection\\src\\Microsoft.ComponentDetection.Detectors\\pip\\PipReportComponentDetector.cs:line 107",
  "ExecutionTime": "00:00:00.0001008",
  "Timestamp": "2024-06-12T20:52:58.190925Z",
  "CorrelationId": "e942f400-f78d-4f33-baba-ae41cbb283ef"
}
[13:52:58 INF] Telemetry record: {
  "RecordName": "DetectorExecution",
  "DetectorId": "PipReport",
  "DetectedComponentCount": 0,
  "ExplicitlyReferencedComponentCount": 0,
  "ReturnCode": 0,
  "IsExperimental": true,
  "ExperimentalInformation": null,
  "AdditionalTelemetryDetails": "{}",
  "ExecutionTime": "00:00:10.2052562",
  "Timestamp": "2024-06-12T20:52:58.1927965Z",
  "CorrelationId": "e942f400-f78d-4f33-baba-ae41cbb283ef"
}
codecov[bot] commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 60.31746% with 25 lines in your changes missing coverage. Please review.

Project coverage is 76.2%. Comparing base (e8c72a1) to head (9e6f8a0). Report is 2 commits behind head on main.

Files Patch % Lines
...Orchestrator/Services/DetectorProcessingService.cs 26.3% 13 Missing and 1 partial :warning:
...ntDetection.Common/CommandLineInvocationService.cs 61.5% 10 Missing :warning:
...ft.ComponentDetection.Common/FileWritingService.cs 0.0% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1167 +/- ## ======================================= - Coverage 76.3% 76.2% -0.2% ======================================= Files 257 257 Lines 11350 11401 +51 Branches 1139 1142 +3 ======================================= + Hits 8670 8697 +27 - Misses 2348 2371 +23 - Partials 332 333 +1 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

github-actions[bot] commented 2 weeks ago

👋 Hi! It looks like you modified some files in the Detectors folder. You may need to bump the detector versions if any of the following scenarios apply:

If none of the above scenarios apply, feel free to ignore this comment 🙂