up
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
Manifest Integrity / Validate Schema Integrity (push) Has been cancelled
Manifest Integrity / Validate Contract Documents (push) Has been cancelled
Manifest Integrity / Validate Pack Fixtures (push) Has been cancelled
Manifest Integrity / Audit SHA256SUMS Files (push) Has been cancelled
Manifest Integrity / Verify Merkle Roots (push) Has been cancelled
devportal-offline / build-offline (push) Has been cancelled
Mirror Thin Bundle Sign & Verify / mirror-sign (push) Has been cancelled

This commit is contained in:
StellaOps Bot
2025-12-13 18:08:55 +02:00
parent 6e45066e37
commit f1a39c4ce3
234 changed files with 24038 additions and 6910 deletions

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using StellaOps.Signals.Models;
@@ -9,4 +11,24 @@ public interface IReachabilityFactRepository
Task<ReachabilityFactDocument> UpsertAsync(ReachabilityFactDocument document, CancellationToken cancellationToken);
Task<ReachabilityFactDocument?> GetBySubjectAsync(string subjectKey, CancellationToken cancellationToken);
/// <summary>
/// Gets documents with ComputedAt older than the specified cutoff.
/// </summary>
Task<IReadOnlyList<ReachabilityFactDocument>> GetExpiredAsync(DateTimeOffset cutoff, int limit, CancellationToken cancellationToken);
/// <summary>
/// Deletes the document with the specified subject key.
/// </summary>
Task<bool> DeleteAsync(string subjectKey, CancellationToken cancellationToken);
/// <summary>
/// Gets the count of runtime facts for a subject.
/// </summary>
Task<int> GetRuntimeFactsCountAsync(string subjectKey, CancellationToken cancellationToken);
/// <summary>
/// Trims runtime facts for a subject to the specified limit, keeping most recent.
/// </summary>
Task TrimRuntimeFactsAsync(string subjectKey, int maxCount, CancellationToken cancellationToken);
}

View File

@@ -1,4 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using StellaOps.Signals.Models;
@@ -31,6 +34,66 @@ internal sealed class InMemoryReachabilityFactRepository : IReachabilityFactRepo
return Task.FromResult(_store.TryGetValue(subjectKey, out var doc) ? Clone(doc) : null);
}
public Task<IReadOnlyList<ReachabilityFactDocument>> GetExpiredAsync(DateTimeOffset cutoff, int limit, CancellationToken cancellationToken)
{
var expired = _store.Values
.Where(d => d.ComputedAt < cutoff)
.OrderBy(d => d.ComputedAt)
.Take(limit)
.Select(Clone)
.ToList();
return Task.FromResult<IReadOnlyList<ReachabilityFactDocument>>(expired);
}
public Task<bool> DeleteAsync(string subjectKey, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(subjectKey))
{
throw new ArgumentException("Subject key is required.", nameof(subjectKey));
}
return Task.FromResult(_store.TryRemove(subjectKey, out _));
}
public Task<int> GetRuntimeFactsCountAsync(string subjectKey, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(subjectKey))
{
throw new ArgumentException("Subject key is required.", nameof(subjectKey));
}
if (_store.TryGetValue(subjectKey, out var doc))
{
return Task.FromResult(doc.RuntimeFacts?.Count ?? 0);
}
return Task.FromResult(0);
}
public Task TrimRuntimeFactsAsync(string subjectKey, int maxCount, CancellationToken cancellationToken)
{
if (string.IsNullOrWhiteSpace(subjectKey))
{
throw new ArgumentException("Subject key is required.", nameof(subjectKey));
}
if (_store.TryGetValue(subjectKey, out var doc) && doc.RuntimeFacts is { Count: > 0 })
{
if (doc.RuntimeFacts.Count > maxCount)
{
var trimmed = doc.RuntimeFacts
.OrderByDescending(f => f.ObservedAt ?? DateTimeOffset.MinValue)
.ThenByDescending(f => f.HitCount)
.Take(maxCount)
.ToList();
doc.RuntimeFacts = trimmed;
}
}
return Task.CompletedTask;
}
private static ReachabilityFactDocument Clone(ReachabilityFactDocument source) => new()
{
Id = source.Id,