< Summary - Syki

Information
Class: Syki.Back.Middlewares.MetricsMiddleware
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Middlewares/MetricsMiddleware.cs
Tag: 21_17346963026
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 39
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%
Invoke()100%11100%

File(s)

/home/runner/work/syki/syki/Back/Middlewares/MetricsMiddleware.cs

#LineLine coverage
 1using Syki.Back.Metrics;
 2using System.Collections.Concurrent;
 3
 4namespace Syki.Back.Middlewares;
 5
 26public class MetricsMiddleware(RequestDelegate next)
 7{
 8    public async Task Invoke(HttpContext context)
 9    {
 870010        context.Response.OnStarting(() =>
 870011        {
 870012            var method = context.Request.Method;
 870013            var endpoint = context.Request.Path.ToString();
 870014            var status = context.Response.StatusCode.ToString();
 870015
 870016            SykiMetricsStore.Requests.AddOrUpdate(
 870017                $"{method} {endpoint}",
 870018                _ =>
 870019                {
 100020                    var dict = new ConcurrentDictionary<string, int>();
 100021                    dict.TryAdd("Total", 1);
 100022                    dict.TryAdd(method, 1);
 100023                    dict.TryAdd(status, 1);
 100024                    return dict;
 870025                },
 870026                (key, currentValue) =>
 870027                {
 1545028                    currentValue.AddOrUpdate("Total", 1, (_, oldValue) => oldValue + 1);
 1544029                    currentValue.AddOrUpdate(method, 1, (_, oldValue) => oldValue + 1);
 1536630                    currentValue.AddOrUpdate(status, 1, (_, oldValue) => oldValue + 1);
 772031                    return currentValue;
 870032                });
 870033
 870034            return Task.CompletedTask;
 870035        });
 36
 870037        await next(context);
 870038    }
 39}