< 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
100%
Covered lines: 21
Uncovered lines: 0
Coverable lines: 21
Total lines: 50
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
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%11100%
ListSourcesAsync(...)100%11100%

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
 2015    public InMemoryStructuredLogStore(IOptions<StructuredLogsOptions> options, IStructuredLogSourceRegistry sourceRegist
 16    {
 2017        _options = options.Value;
 2018        _sourceRegistry = sourceRegistry;
 2019        _recentLogs = new(_options.RecentLogCapacity);
 2020    }
 21
 22    public ValueTask WriteAsync(StructuredLogEvent logEvent, CancellationToken cancellationToken = default)
 23    {
 4224        _recentLogs.Add(logEvent);
 4225        _sourceRegistry.MarkSeen(logEvent.SourceId, logEvent.ReceivedAt);
 4226        return ValueTask.CompletedTask;
 27    }
 28
 29    public ValueTask<RecentStructuredLogsResult> QueryAsync(StructuredLogFilter filter, CancellationToken cancellationTo
 30    {
 2631        var take = _options.ClampRecentLogQueryTake(filter.Take);
 2632        var items = _recentLogs
 2633            .Snapshot()
 6334            .Where(x => StructuredLogFilterEvaluator.Matches(x, filter))
 3735            .OrderBy(x => x.Timestamp)
 3736            .ThenBy(x => x.ReceivedAt)
 3737            .ThenBy(x => x.SourceId, StringComparer.OrdinalIgnoreCase)
 3738            .ThenBy(x => x.Sequence)
 3739            .ThenBy(x => x.Id, StringComparer.Ordinal)
 2640            .TakeLast(take)
 2641            .ToList();
 42
 2643        return ValueTask.FromResult(new RecentStructuredLogsResult(items, _recentLogs.DroppedCount));
 44    }
 45
 46    public ValueTask<IReadOnlyCollection<StructuredLogSource>> ListSourcesAsync(CancellationToken cancellationToken = de
 47    {
 148        return ValueTask.FromResult(_sourceRegistry.List());
 49    }
 50}