< Summary

Information
Class: Elsa.Diagnostics.StructuredLogs.Providers.InMemory.InMemoryStructuredLogStore
Assembly: Elsa.Diagnostics.StructuredLogs
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.StructuredLogs/Providers/InMemory/InMemoryStructuredLogStore.cs
Line coverage
95%
Covered lines: 20
Uncovered lines: 1
Coverable lines: 21
Total lines: 50
Line coverage: 95.2%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
WriteAsync(...)100%11100%
QueryAsync(...)100%22100%
ListSourcesAsync(...)100%210%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Diagnostics.StructuredLogs/Providers/InMemory/InMemoryStructuredLogStore.cs

#LineLine coverage
 1using Elsa.Diagnostics.StructuredLogs.Contracts;
 2using Elsa.Diagnostics.StructuredLogs.Models;
 3using Elsa.Diagnostics.StructuredLogs.Options;
 4using Elsa.Diagnostics.StructuredLogs.Services;
 5using Microsoft.Extensions.Options;
 6
 7namespace Elsa.Diagnostics.StructuredLogs.Providers.InMemory;
 8
 9public class InMemoryStructuredLogStore : IStructuredLogStore
 10{
 11    private readonly RingBuffer<StructuredLogEvent> _recentLogs;
 12    private readonly IStructuredLogSourceRegistry _sourceRegistry;
 13    private readonly StructuredLogsOptions _options;
 14
 815    public InMemoryStructuredLogStore(IOptions<StructuredLogsOptions> options, IStructuredLogSourceRegistry sourceRegist
 16    {
 817        _options = options.Value;
 818        _sourceRegistry = sourceRegistry;
 819        _recentLogs = new(_options.RecentLogCapacity);
 820    }
 21
 22    public ValueTask WriteAsync(StructuredLogEvent logEvent, CancellationToken cancellationToken = default)
 23    {
 1524        _recentLogs.Add(logEvent);
 1525        _sourceRegistry.MarkSeen(logEvent.SourceId, logEvent.ReceivedAt);
 1526        return ValueTask.CompletedTask;
 27    }
 28
 29    public ValueTask<RecentStructuredLogsResult> QueryAsync(StructuredLogFilter filter, CancellationToken cancellationTo
 30    {
 431        var take = Math.Clamp(filter.Take ?? _options.MaxRecentLogQuerySize, 0, _options.MaxRecentLogQuerySize);
 432        var items = _recentLogs
 433            .Snapshot()
 1034            .Where(x => StructuredLogFilterEvaluator.Matches(x, filter))
 835            .OrderBy(x => x.Timestamp)
 836            .ThenBy(x => x.ReceivedAt)
 837            .ThenBy(x => x.SourceId, StringComparer.OrdinalIgnoreCase)
 838            .ThenBy(x => x.Sequence)
 839            .ThenBy(x => x.Id, StringComparer.Ordinal)
 440            .TakeLast(take)
 441            .ToList();
 42
 443        return ValueTask.FromResult(new RecentStructuredLogsResult(items, _recentLogs.DroppedCount));
 44    }
 45
 46    public ValueTask<IReadOnlyCollection<StructuredLogSource>> ListSourcesAsync(CancellationToken cancellationToken = de
 47    {
 048        return ValueTask.FromResult(_sourceRegistry.List());
 49    }
 50}