diff --git a/src/Mocha.Core/Storage/Jaeger/IJaegerSpanReader.cs b/src/Mocha.Core/Storage/Jaeger/IJaegerSpanReader.cs index 24c8c43..7ae6cad 100644 --- a/src/Mocha.Core/Storage/Jaeger/IJaegerSpanReader.cs +++ b/src/Mocha.Core/Storage/Jaeger/IJaegerSpanReader.cs @@ -7,11 +7,11 @@ namespace Mocha.Core.Storage.Jaeger; public interface IJaegerSpanReader { - Task GetServicesAsync(); + Task> GetServicesAsync(); - Task GetOperationsAsync(string serviceName); + Task> GetOperationsAsync(string serviceName); - Task FindTracesAsync(JaegerTraceQueryParameters query); + Task> FindTracesAsync(JaegerTraceQueryParameters query); - Task FindTracesAsync(string[] traceIDs, ulong? startTimeMinUnixNano = null, ulong? startTimeMaxUnixNano = null); + Task> FindTracesAsync(string[] traceIDs, ulong? startTimeMinUnixNano = null, ulong? startTimeMaxUnixNano = null); } diff --git a/src/Mocha.Query.Jaeger/Controllers/TraceController.cs b/src/Mocha.Query.Jaeger/Controllers/TraceController.cs index 6ad6ada..6c4c943 100644 --- a/src/Mocha.Query.Jaeger/Controllers/TraceController.cs +++ b/src/Mocha.Query.Jaeger/Controllers/TraceController.cs @@ -12,19 +12,19 @@ namespace Mocha.Query.Jaeger.Controllers public class TraceController(IJaegerSpanReader spanReader) : Controller { [HttpGet("services")] - public async Task> GetSeries() + public async Task>> GetSeries() { return new(await spanReader.GetServicesAsync()); } [HttpGet("services/{serviceName}/operations")] - public async Task> GetOperations(string serviceName) + public async Task>> GetOperations(string serviceName) { return new(await spanReader.GetOperationsAsync(serviceName)); } [HttpGet("traces")] - public async Task> FindTraces([FromQuery] FindTracesRequest request) + public async Task>> FindTraces([FromQuery] FindTracesRequest request) { static ulong? ParseAsNanoseconds(string? input) { @@ -71,7 +71,7 @@ public async Task> FindTraces([FromQuery] FindTrac startTimeMax = now; } - JaegerTrace[] traces; + IEnumerable traces; if (request.TraceID?.Any() ?? false) { @@ -99,26 +99,26 @@ public async Task> FindTraces([FromQuery] FindTrac } JaegerResponseError? error = null; - if (traces.Length == 0) + if (traces.Any() is false) { error = new JaegerResponseError { Code = (int)HttpStatusCode.NotFound, Message = "trace not found" }; } - return new JaegerResponse(traces) { Error = error }; + return new JaegerResponse>(traces) { Error = error }; } [HttpGet("traces/{traceID}")] - public async Task> GetTrace(string traceID) + public async Task>> GetTrace(string traceID) { var traces = await spanReader.FindTracesAsync([traceID]); JaegerResponseError? error = null; - if (traces.Length == 0) + if (traces.Any() is false) { error = new JaegerResponseError { Code = (int)HttpStatusCode.NotFound, Message = "trace not found" }; } - return new JaegerResponse(traces) { Error = error }; + return new JaegerResponse>(traces) { Error = error }; } } } diff --git a/src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFJaegerSpanReader.cs b/src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFJaegerSpanReader.cs index 1b87190..3e03436 100644 --- a/src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFJaegerSpanReader.cs +++ b/src/Mocha.Storage/EntityFrameworkCore/Jaeger/EFJaegerSpanReader.cs @@ -10,25 +10,25 @@ namespace Mocha.Storage.EntityFrameworkCore.Jaeger; internal class EFJaegerSpanReader(IDbContextFactory contextFactory) : IJaegerSpanReader { - public async Task GetServicesAsync() + public async Task> GetServicesAsync() { await using var context = await contextFactory.CreateDbContextAsync(); - var services = await context.Spans.Select(s => s.ServiceName).Distinct().ToArrayAsync(); + var services = await context.Spans.Select(s => s.ServiceName).Distinct().ToListAsync(); return services; } - public async Task GetOperationsAsync(string serviceName) + public async Task> GetOperationsAsync(string serviceName) { await using var context = await contextFactory.CreateDbContextAsync(); var operations = await context.Spans .Where(s => s.ServiceName == serviceName) .Select(s => s.SpanName) .Distinct() - .ToArrayAsync(); + .ToListAsync(); return operations; } - public async Task FindTracesAsync(JaegerTraceQueryParameters query) + public async Task> FindTracesAsync(JaegerTraceQueryParameters query) { await using var context = await contextFactory.CreateDbContextAsync(); var queryableSpans = context.Spans.AsQueryable(); @@ -92,7 +92,7 @@ join spanId in spanIds on span.SpanId equals spanId return await QueryJaegerTracesAsync(queryableSpans, context); } - public async Task FindTracesAsync( + public async Task> FindTracesAsync( string[]? traceIDs, ulong? startTimeUnixNano, ulong? endTimeUnixNano) @@ -119,29 +119,29 @@ public async Task FindTracesAsync( return await QueryJaegerTracesAsync(queryableSpans, context); } - private static async Task QueryJaegerTracesAsync( + private static async Task> QueryJaegerTracesAsync( IQueryable queryableSpans, MochaContext context) { - var spans = await queryableSpans.ToArrayAsync(); + var spans = await queryableSpans.ToListAsync(); var spanIds = spans.Select(s => s.SpanId).ToArray(); var spanAttributes = await context.SpanAttributes .Where(a => spanIds.Contains(a.SpanId)) - .ToArrayAsync(); + .ToListAsync(); var resourceAttributes = await context.ResourceAttributes .Where(a => spanIds.Contains(a.SpanId)) - .ToArrayAsync(); + .ToListAsync(); var spanEvents = await context.SpanEvents .Where(e => spanIds.Contains(e.SpanId)) - .ToArrayAsync(); + .ToListAsync(); var spanEventAttributes = await context.SpanEventAttributes .Where(a => spanIds.Contains(a.SpanId)) - .ToArrayAsync(); + .ToListAsync(); var jaegerTraces = spans.ToJaegerTraces( spanAttributes, resourceAttributes, spanEvents, spanEventAttributes).ToArray(); diff --git a/tests/Mocha.Storage.Tests/EntityFrameworkCore/EFJaegerSpanReaderTests.cs b/tests/Mocha.Storage.Tests/EntityFrameworkCore/EFJaegerSpanReaderTests.cs index 5b79e17..1b804ae 100644 --- a/tests/Mocha.Storage.Tests/EntityFrameworkCore/EFJaegerSpanReaderTests.cs +++ b/tests/Mocha.Storage.Tests/EntityFrameworkCore/EFJaegerSpanReaderTests.cs @@ -364,7 +364,7 @@ public async Task FindTracesAsync_TraceID() now.AddMinutes(-2).ToUnixTimeNanoseconds(), now.AddMinutes(2).ToUnixTimeNanoseconds()); Assert.Single(traces); - Assert.Equal("TraceId1", traces[0].TraceID); + Assert.Equal("TraceId1", traces.First().TraceID); } public void Dispose()