Some checks failed
Docs CI / lint-and-preview (push) Has been cancelled
- Added RuntimeFactsNdjsonReader for reading NDJSON formatted runtime facts. - Introduced IRuntimeFactsIngestionService interface and its implementation. - Enhanced Program.cs to register new services and endpoints for runtime facts. - Updated CallgraphIngestionService to include CAS URI in stored artifacts. - Created RuntimeFactsValidationException for validation errors during ingestion. - Added tests for RuntimeFactsIngestionService and RuntimeFactsNdjsonReader. - Implemented SignalsSealedModeMonitor for compliance checks in sealed mode. - Updated project dependencies for testing utilities.
53 lines
1.5 KiB
C#
53 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Text;
|
|
using System.Text.Json;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using StellaOps.Signals.Models;
|
|
|
|
namespace StellaOps.Signals.Parsing;
|
|
|
|
internal static class RuntimeFactsNdjsonReader
|
|
{
|
|
private static readonly JsonSerializerOptions SerializerOptions = new(JsonSerializerDefaults.Web);
|
|
|
|
public static async Task<List<RuntimeFactEvent>> ReadAsync(
|
|
Stream input,
|
|
bool gzipEncoded,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
ArgumentNullException.ThrowIfNull(input);
|
|
|
|
Stream effectiveStream = input;
|
|
if (gzipEncoded)
|
|
{
|
|
effectiveStream = new GZipStream(input, CompressionMode.Decompress, leaveOpen: true);
|
|
}
|
|
|
|
using var reader = new StreamReader(effectiveStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, leaveOpen: !gzipEncoded);
|
|
|
|
var events = new List<RuntimeFactEvent>();
|
|
string? line;
|
|
while ((line = await reader.ReadLineAsync(cancellationToken).ConfigureAwait(false)) != null)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(line))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var evt = JsonSerializer.Deserialize<RuntimeFactEvent>(line, SerializerOptions);
|
|
if (evt is null || string.IsNullOrWhiteSpace(evt.SymbolId))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
events.Add(evt);
|
|
}
|
|
|
|
return events;
|
|
}
|
|
}
|