Add unit tests for SBOM ingestion and transformation
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
- Implement `SbomIngestServiceCollectionExtensionsTests` to verify the SBOM ingestion pipeline exports snapshots correctly. - Create `SbomIngestTransformerTests` to ensure the transformation produces expected nodes and edges, including deduplication of license nodes and normalization of timestamps. - Add `SbomSnapshotExporterTests` to test the export functionality for manifest, adjacency, nodes, and edges. - Introduce `VexOverlayTransformerTests` to validate the transformation of VEX nodes and edges. - Set up project file for the test project with necessary dependencies and configurations. - Include JSON fixture files for testing purposes.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using System.Diagnostics.Metrics;
|
||||
using StellaOps.AdvisoryAI.Orchestration;
|
||||
|
||||
namespace StellaOps.AdvisoryAI.Metrics;
|
||||
|
||||
public sealed class AdvisoryPipelineMetrics : IDisposable
|
||||
{
|
||||
public const string MeterName = "StellaOps.AdvisoryAI";
|
||||
|
||||
private readonly Meter _meter;
|
||||
private readonly Counter<long> _plansCreated;
|
||||
private readonly Counter<long> _plansQueued;
|
||||
private readonly Counter<long> _plansProcessed;
|
||||
private readonly Counter<long> _outputsStored;
|
||||
private readonly Counter<long> _guardrailBlocks;
|
||||
private readonly Histogram<double> _planBuildDuration;
|
||||
private bool _disposed;
|
||||
|
||||
public AdvisoryPipelineMetrics(IMeterFactory meterFactory)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(meterFactory);
|
||||
|
||||
_meter = meterFactory.Create(MeterName, version: "1.0.0");
|
||||
_plansCreated = _meter.CreateCounter<long>("advisory_plans_created");
|
||||
_plansQueued = _meter.CreateCounter<long>("advisory_plans_queued");
|
||||
_plansProcessed = _meter.CreateCounter<long>("advisory_plans_processed");
|
||||
_outputsStored = _meter.CreateCounter<long>("advisory_outputs_stored");
|
||||
_guardrailBlocks = _meter.CreateCounter<long>("advisory_guardrail_blocks");
|
||||
_planBuildDuration = _meter.CreateHistogram<double>("advisory_plan_build_duration_seconds");
|
||||
}
|
||||
|
||||
public void RecordPlanCreated(double buildSeconds, AdvisoryTaskType taskType)
|
||||
{
|
||||
_plansCreated.Add(1, KeyValuePair.Create<string, object?>("task_type", taskType.ToString()));
|
||||
_planBuildDuration.Record(buildSeconds, KeyValuePair.Create<string, object?>("task_type", taskType.ToString()));
|
||||
}
|
||||
|
||||
public void RecordPlanQueued(AdvisoryTaskType taskType)
|
||||
=> _plansQueued.Add(1, KeyValuePair.Create<string, object?>("task_type", taskType.ToString()));
|
||||
|
||||
public void RecordPlanProcessed(AdvisoryTaskType taskType, bool fromCache)
|
||||
{
|
||||
_plansProcessed.Add(
|
||||
1,
|
||||
KeyValuePair.Create<string, object?>("task_type", taskType.ToString()),
|
||||
KeyValuePair.Create<string, object?>("cache_hit", fromCache));
|
||||
}
|
||||
|
||||
public void RecordOutputStored(AdvisoryTaskType taskType, bool planFromCache, bool guardrailBlocked)
|
||||
{
|
||||
_outputsStored.Add(
|
||||
1,
|
||||
KeyValuePair.Create<string, object?>("task_type", taskType.ToString()),
|
||||
KeyValuePair.Create<string, object?>("plan_cache_hit", planFromCache),
|
||||
KeyValuePair.Create<string, object?>("guardrail_blocked", guardrailBlocked));
|
||||
}
|
||||
|
||||
public void RecordGuardrailResult(AdvisoryTaskType taskType, bool blocked)
|
||||
{
|
||||
if (blocked)
|
||||
{
|
||||
_guardrailBlocks.Add(1, KeyValuePair.Create<string, object?>("task_type", taskType.ToString()));
|
||||
}
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_meter.Dispose();
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user