Refactor and enhance scanner worker functionality
- Cleaned up code formatting and organization across multiple files for improved readability. - Introduced `OsScanAnalyzerDispatcher` to handle OS analyzer execution and plugin loading. - Updated `ScanJobContext` to include an `Analysis` property for storing scan results. - Enhanced `ScanJobProcessor` to utilize the new `OsScanAnalyzerDispatcher`. - Improved logging and error handling in `ScanProgressReporter` for better traceability. - Updated project dependencies and added references to new analyzer plugins. - Revised task documentation to reflect current status and dependencies.
This commit is contained in:
		| @@ -1,102 +1,102 @@ | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Reflection; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using Microsoft.Extensions.Hosting; | ||||
| using OpenTelemetry.Metrics; | ||||
| using OpenTelemetry.Resources; | ||||
| using OpenTelemetry.Trace; | ||||
| using StellaOps.Scanner.Worker.Options; | ||||
|  | ||||
| namespace StellaOps.Scanner.Worker.Diagnostics; | ||||
|  | ||||
| public static class TelemetryExtensions | ||||
| { | ||||
|     public static void ConfigureScannerWorkerTelemetry(this IHostApplicationBuilder builder, ScannerWorkerOptions options) | ||||
|     { | ||||
|         ArgumentNullException.ThrowIfNull(builder); | ||||
|         ArgumentNullException.ThrowIfNull(options); | ||||
|  | ||||
|         var telemetry = options.Telemetry; | ||||
|         if (!telemetry.EnableTelemetry) | ||||
|         { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         var openTelemetry = builder.Services.AddOpenTelemetry(); | ||||
|  | ||||
|         openTelemetry.ConfigureResource(resource => | ||||
|         { | ||||
|             var version = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown"; | ||||
|             resource.AddService(telemetry.ServiceName, serviceVersion: version, serviceInstanceId: Environment.MachineName); | ||||
|             resource.AddAttributes(new[] | ||||
|             { | ||||
|                 new KeyValuePair<string, object>("deployment.environment", builder.Environment.EnvironmentName), | ||||
|             }); | ||||
|  | ||||
|             foreach (var kvp in telemetry.ResourceAttributes) | ||||
|             { | ||||
|                 if (string.IsNullOrWhiteSpace(kvp.Key) || kvp.Value is null) | ||||
|                 { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 resource.AddAttributes(new[] { new KeyValuePair<string, object>(kvp.Key, kvp.Value) }); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         if (telemetry.EnableTracing) | ||||
|         { | ||||
|             openTelemetry.WithTracing(tracing => | ||||
|             { | ||||
|                 tracing.AddSource(ScannerWorkerInstrumentation.ActivitySourceName); | ||||
|                 ConfigureExporter(tracing, telemetry); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         if (telemetry.EnableMetrics) | ||||
|         { | ||||
|             openTelemetry.WithMetrics(metrics => | ||||
|             { | ||||
|                 metrics | ||||
|                     .AddMeter(ScannerWorkerInstrumentation.MeterName) | ||||
|                     .AddRuntimeInstrumentation() | ||||
|                     .AddProcessInstrumentation(); | ||||
|  | ||||
|                 ConfigureExporter(metrics, telemetry); | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static void ConfigureExporter(TracerProviderBuilder tracing, ScannerWorkerOptions.TelemetryOptions telemetry) | ||||
|     { | ||||
|         if (!string.IsNullOrWhiteSpace(telemetry.OtlpEndpoint)) | ||||
|         { | ||||
|             tracing.AddOtlpExporter(options => | ||||
|             { | ||||
|                 options.Endpoint = new Uri(telemetry.OtlpEndpoint); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         if (telemetry.ExportConsole || string.IsNullOrWhiteSpace(telemetry.OtlpEndpoint)) | ||||
|         { | ||||
|             tracing.AddConsoleExporter(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static void ConfigureExporter(MeterProviderBuilder metrics, ScannerWorkerOptions.TelemetryOptions telemetry) | ||||
|     { | ||||
|         if (!string.IsNullOrWhiteSpace(telemetry.OtlpEndpoint)) | ||||
|         { | ||||
|             metrics.AddOtlpExporter(options => | ||||
|             { | ||||
|                 options.Endpoint = new Uri(telemetry.OtlpEndpoint); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         if (telemetry.ExportConsole || string.IsNullOrWhiteSpace(telemetry.OtlpEndpoint)) | ||||
|         { | ||||
|             metrics.AddConsoleExporter(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| using System; | ||||
| using System.Collections.Generic; | ||||
| using System.Reflection; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using Microsoft.Extensions.Hosting; | ||||
| using OpenTelemetry.Metrics; | ||||
| using OpenTelemetry.Resources; | ||||
| using OpenTelemetry.Trace; | ||||
| using StellaOps.Scanner.Worker.Options; | ||||
|  | ||||
| namespace StellaOps.Scanner.Worker.Diagnostics; | ||||
|  | ||||
| public static class TelemetryExtensions | ||||
| { | ||||
|     public static void ConfigureScannerWorkerTelemetry(this IHostApplicationBuilder builder, ScannerWorkerOptions options) | ||||
|     { | ||||
|         ArgumentNullException.ThrowIfNull(builder); | ||||
|         ArgumentNullException.ThrowIfNull(options); | ||||
|  | ||||
|         var telemetry = options.Telemetry; | ||||
|         if (!telemetry.EnableTelemetry) | ||||
|         { | ||||
|             return; | ||||
|         } | ||||
|  | ||||
|         var openTelemetry = builder.Services.AddOpenTelemetry(); | ||||
|  | ||||
|         openTelemetry.ConfigureResource(resource => | ||||
|         { | ||||
|             var version = Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "unknown"; | ||||
|             resource.AddService(telemetry.ServiceName, serviceVersion: version, serviceInstanceId: Environment.MachineName); | ||||
|             resource.AddAttributes(new[] | ||||
|             { | ||||
|                 new KeyValuePair<string, object>("deployment.environment", builder.Environment.EnvironmentName), | ||||
|             }); | ||||
|  | ||||
|             foreach (var kvp in telemetry.ResourceAttributes) | ||||
|             { | ||||
|                 if (string.IsNullOrWhiteSpace(kvp.Key) || kvp.Value is null) | ||||
|                 { | ||||
|                     continue; | ||||
|                 } | ||||
|  | ||||
|                 resource.AddAttributes(new[] { new KeyValuePair<string, object>(kvp.Key, kvp.Value) }); | ||||
|             } | ||||
|         }); | ||||
|  | ||||
|         if (telemetry.EnableTracing) | ||||
|         { | ||||
|             openTelemetry.WithTracing(tracing => | ||||
|             { | ||||
|                 tracing.AddSource(ScannerWorkerInstrumentation.ActivitySourceName); | ||||
|                 ConfigureExporter(tracing, telemetry); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         if (telemetry.EnableMetrics) | ||||
|         { | ||||
|             openTelemetry.WithMetrics(metrics => | ||||
|             { | ||||
|                 metrics | ||||
|                     .AddMeter(ScannerWorkerInstrumentation.MeterName) | ||||
|                     .AddRuntimeInstrumentation() | ||||
|                     .AddProcessInstrumentation(); | ||||
|  | ||||
|                 ConfigureExporter(metrics, telemetry); | ||||
|             }); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static void ConfigureExporter(TracerProviderBuilder tracing, ScannerWorkerOptions.TelemetryOptions telemetry) | ||||
|     { | ||||
|         if (!string.IsNullOrWhiteSpace(telemetry.OtlpEndpoint)) | ||||
|         { | ||||
|             tracing.AddOtlpExporter(options => | ||||
|             { | ||||
|                 options.Endpoint = new Uri(telemetry.OtlpEndpoint); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         if (telemetry.ExportConsole || string.IsNullOrWhiteSpace(telemetry.OtlpEndpoint)) | ||||
|         { | ||||
|             tracing.AddConsoleExporter(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private static void ConfigureExporter(MeterProviderBuilder metrics, ScannerWorkerOptions.TelemetryOptions telemetry) | ||||
|     { | ||||
|         if (!string.IsNullOrWhiteSpace(telemetry.OtlpEndpoint)) | ||||
|         { | ||||
|             metrics.AddOtlpExporter(options => | ||||
|             { | ||||
|                 options.Endpoint = new Uri(telemetry.OtlpEndpoint); | ||||
|             }); | ||||
|         } | ||||
|  | ||||
|         if (telemetry.ExportConsole || string.IsNullOrWhiteSpace(telemetry.OtlpEndpoint)) | ||||
|         { | ||||
|             metrics.AddConsoleExporter(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user