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:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Metrics;
|
||||
@@ -5,7 +6,7 @@ using System.Linq;
|
||||
|
||||
namespace StellaOps.Scheduler.Queue;
|
||||
|
||||
internal static class SchedulerQueueMetrics
|
||||
public static class SchedulerQueueMetrics
|
||||
{
|
||||
private const string TransportTagName = "transport";
|
||||
private const string QueueTagName = "queue";
|
||||
@@ -21,6 +22,25 @@ internal static class SchedulerQueueMetrics
|
||||
"scheduler_queue_depth",
|
||||
ObserveDepth);
|
||||
|
||||
public static IReadOnlyList<SchedulerQueueDepthSample> CaptureDepthSamples()
|
||||
{
|
||||
var snapshot = DepthSamples.ToArray();
|
||||
if (snapshot.Length == 0)
|
||||
{
|
||||
return Array.Empty<SchedulerQueueDepthSample>();
|
||||
}
|
||||
|
||||
var samples = new SchedulerQueueDepthSample[snapshot.Length];
|
||||
for (var i = 0; i < snapshot.Length; i++)
|
||||
{
|
||||
var entry = snapshot[i];
|
||||
samples[i] = new SchedulerQueueDepthSample(entry.Key.transport, entry.Key.queue, entry.Value);
|
||||
}
|
||||
|
||||
Array.Sort(samples, SchedulerQueueDepthSampleComparer.Instance);
|
||||
return Array.AsReadOnly(samples);
|
||||
}
|
||||
|
||||
public static void RecordEnqueued(string transport, string queue)
|
||||
=> EnqueuedCounter.Add(1, BuildTags(transport, queue));
|
||||
|
||||
@@ -45,6 +65,22 @@ internal static class SchedulerQueueMetrics
|
||||
internal static IReadOnlyDictionary<(string transport, string queue), long> SnapshotDepths()
|
||||
=> DepthSamples.ToDictionary(pair => pair.Key, pair => pair.Value);
|
||||
|
||||
private sealed class SchedulerQueueDepthSampleComparer : IComparer<SchedulerQueueDepthSample>
|
||||
{
|
||||
public static SchedulerQueueDepthSampleComparer Instance { get; } = new();
|
||||
|
||||
public int Compare(SchedulerQueueDepthSample x, SchedulerQueueDepthSample y)
|
||||
{
|
||||
var transport = string.Compare(x.Transport, y.Transport, StringComparison.Ordinal);
|
||||
if (transport != 0)
|
||||
{
|
||||
return transport;
|
||||
}
|
||||
|
||||
return string.Compare(x.Queue, y.Queue, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
|
||||
private static KeyValuePair<string, object?>[] BuildTags(string transport, string queue)
|
||||
=> new[]
|
||||
{
|
||||
@@ -63,3 +99,5 @@ internal static class SchedulerQueueMetrics
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public readonly record struct SchedulerQueueDepthSample(string Transport, string Queue, long Depth);
|
||||
|
||||
Reference in New Issue
Block a user