Skip to content

Commit 7178517

Browse files
committed
Formatted
1 parent 17d7fb6 commit 7178517

8 files changed

Lines changed: 49 additions & 49 deletions

File tree

src/KeeperData.Api/Middleware/ExceptionHandlingMiddleware.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ public async Task InvokeAsync(HttpContext context)
2828
try
2929
{
3030
await _next(context);
31-
31+
3232
// Record successful request metrics
3333
stopwatch.Stop();
3434
_metrics.RecordRequest("http_request", "success");
3535
_metrics.RecordDuration("http_request", stopwatch.ElapsedMilliseconds);
36-
_metrics.RecordCount("http_requests", 1,
36+
_metrics.RecordCount("http_requests", 1,
3737
("method", context.Request.Method),
3838
("endpoint", context.Request.Path.Value ?? "unknown"),
3939
("status_code", context.Response.StatusCode.ToString()),
@@ -129,20 +129,20 @@ private void RecordExceptionMetrics(Exception exception, int statusCode, string
129129
{
130130
_metrics.RecordRequest("http_request", "error");
131131
_metrics.RecordDuration("http_request", durationMs);
132-
_metrics.RecordCount("http_requests", 1,
132+
_metrics.RecordCount("http_requests", 1,
133133
("method", endpoint.Split(' ').FirstOrDefault() ?? "unknown"),
134134
("endpoint", endpoint.Split(' ').Skip(1).FirstOrDefault() ?? "unknown"),
135135
("status_code", statusCode.ToString()),
136136
("status", "error"));
137137

138138
// Record error-specific metrics
139-
_metrics.RecordCount("http_errors", 1,
139+
_metrics.RecordCount("http_errors", 1,
140140
("error_type", errorType),
141141
("exception_type", exception.GetType().Name),
142142
("status_code", statusCode.ToString()));
143143

144144
// Record duration for error analysis
145-
_metrics.RecordValue("error_request_duration", durationMs,
145+
_metrics.RecordValue("error_request_duration", durationMs,
146146
("error_type", errorType),
147147
("status_code", statusCode.ToString()));
148148
}

src/KeeperData.Infrastructure/Config/AwsConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace KeeperData.Infrastructure.Config;
66
public class AwsConfig
77
{
88
public const string SectionName = "AWS";
9-
9+
1010
public string Region { get; set; } = string.Empty;
1111
public EmfConfig EMF { get; set; } = new();
1212
public MetricsConfig Metrics { get; set; } = new();

src/KeeperData.Infrastructure/Extensions/TelemetryExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public static IServiceCollection AddKeeperDataMetrics(this IServiceCollection se
1111
services.TryAddSingleton<IApplicationMetrics, ApplicationMetrics>();
1212
services.TryAddSingleton<HealthCheckMetrics>();
1313
services.TryAddSingleton<HealthCheckMetricsPublisher>();
14-
14+
1515
return services;
1616
}
1717
}

src/KeeperData.Infrastructure/Telemetry/ApplicationMetrics.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@ public ApplicationMetrics(IOptions<AwsConfig> awsConfig)
1818
{
1919
var meterName = awsConfig.Value.Metrics.MeterName;
2020
_meter = new Meter(meterName);
21-
21+
2222
// Create instruments for common metrics
2323
_requestCounter = _meter.CreateCounter<int>(
2424
name: "requests_total",
2525
unit: "ea",
2626
description: "Total number of requests by operation and status");
27-
27+
2828
_durationHistogram = _meter.CreateHistogram<double>(
2929
name: "duration_milliseconds",
30-
unit: "ms",
30+
unit: "ms",
3131
description: "Duration of operations in milliseconds");
32-
32+
3333
_generalCounter = _meter.CreateCounter<int>(
3434
name: "count_total",
3535
unit: "ea",
3636
description: "General purpose counter with custom tags");
37-
37+
3838
_generalHistogram = _meter.CreateHistogram<double>(
3939
name: "value_measurement",
4040
unit: "value",
@@ -43,7 +43,7 @@ public ApplicationMetrics(IOptions<AwsConfig> awsConfig)
4343

4444
public void RecordRequest(string operation, string status)
4545
{
46-
_requestCounter.Add(1,
46+
_requestCounter.Add(1,
4747
new KeyValuePair<string, object?>("operation", operation),
4848
new KeyValuePair<string, object?>("status", status));
4949
}
@@ -60,12 +60,12 @@ public void RecordCount(string name, int value, params (string Key, string Value
6060
{
6161
new("metric_name", name)
6262
};
63-
63+
6464
foreach (var (key, val) in tags)
6565
{
6666
kvps.Add(new KeyValuePair<string, object?>(key, val));
6767
}
68-
68+
6969
_generalCounter.Add(value, kvps.ToArray());
7070
}
7171

@@ -75,12 +75,12 @@ public void RecordValue(string name, double value, params (string Key, string Va
7575
{
7676
new("metric_name", name)
7777
};
78-
78+
7979
foreach (var (key, val) in tags)
8080
{
8181
kvps.Add(new KeyValuePair<string, object?>(key, val));
8282
}
83-
83+
8484
_generalHistogram.Record(value, kvps.ToArray());
8585
}
8686

src/KeeperData.Infrastructure/Telemetry/EmfExporter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static class EmfExportExtensions
1616
public static IApplicationBuilder UseEmfExporter(this IApplicationBuilder builder)
1717
{
1818
var awsConfig = builder.ApplicationServices.GetRequiredService<IOptions<AwsConfig>>();
19-
EmfExporter.Init(builder.ApplicationServices.GetRequiredService<ILoggerFactory>().CreateLogger(nameof(EmfExporter)),
19+
EmfExporter.Init(builder.ApplicationServices.GetRequiredService<ILoggerFactory>().CreateLogger(nameof(EmfExporter)),
2020
awsConfig.Value.EMF.Namespace);
2121
return builder;
2222
}
@@ -27,12 +27,12 @@ public static class EmfExporter
2727
private static readonly MeterListener meterListener = new();
2828
private static ILogger log = null!;
2929
private static string awsNamespace = string.Empty;
30-
30+
3131
public static void Init(ILogger logger, string? awsNamespace)
3232
{
3333
log = logger;
3434
EmfExporter.awsNamespace = awsNamespace ?? string.Empty;
35-
35+
3636
meterListener.InstrumentPublished = (instrument, listener) =>
3737
{
3838
if (instrument.Meter.Name is "KeeperData")
@@ -58,7 +58,7 @@ static void OnMeasurementRecorded<T>(
5858
using var metricsLogger = new MetricsLogger();
5959
metricsLogger.SetNamespace(awsNamespace);
6060
var dimensionSet = new DimensionSet();
61-
61+
6262
foreach (var tag in tags)
6363
{
6464
dimensionSet.AddDimension(tag.Key, tag.Value?.ToString());
@@ -74,10 +74,10 @@ static void OnMeasurementRecorded<T>(
7474
{
7575
metricsLogger.PutProperty("TraceState", Activity.Current.TraceStateString);
7676
}
77-
77+
7878
metricsLogger.SetDimensions(dimensionSet);
7979
var name = instrument.Name.Dehumanize().Camelize();
80-
metricsLogger.PutMetric(name, Convert.ToDouble(measurement),
80+
metricsLogger.PutMetric(name, Convert.ToDouble(measurement),
8181
instrument.Unit == "ea" ? Unit.COUNT : Unit.MILLISECONDS);
8282
metricsLogger.Flush();
8383
}

src/KeeperData.Infrastructure/Telemetry/HealthCheckMetrics.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,25 @@ public class HealthCheckMetrics
1414
public HealthCheckMetrics(IMeterFactory meterFactory)
1515
{
1616
var meter = meterFactory.Create(MetricNames.MeterName);
17-
17+
1818
_healthCheckTotal = meter.CreateCounter<long>(
19-
"keeperdata.health.checks.total",
20-
"ea",
19+
"keeperdata.health.checks.total",
20+
"ea",
2121
"Total number of health checks performed");
22-
22+
2323
_healthCheckFailures = meter.CreateCounter<long>(
24-
"keeperdata.health.checks.failures",
25-
"ea",
24+
"keeperdata.health.checks.failures",
25+
"ea",
2626
"Number of health check failures");
27-
27+
2828
_healthCheckDuration = meter.CreateHistogram<double>(
29-
"keeperdata.health.checks.duration",
30-
"ms",
29+
"keeperdata.health.checks.duration",
30+
"ms",
3131
"Health check execution duration in milliseconds");
32-
32+
3333
_healthCheckStatus = meter.CreateUpDownCounter<int>(
34-
"keeperdata.health.status",
35-
"status",
34+
"keeperdata.health.status",
35+
"status",
3636
"Current health check status (2=Healthy, 1=Degraded, 0=Unhealthy)");
3737
}
3838

@@ -54,7 +54,7 @@ public void RecordHealthCheck(string healthCheckName, HealthStatus status, doubl
5454
}
5555

5656
// Record current health status as numeric value
57-
var statusValue = status switch
57+
var statusValue = status switch
5858
{
5959
HealthStatus.Healthy => 2,
6060
HealthStatus.Degraded => 1,

src/KeeperData.Infrastructure/Telemetry/HealthCheckMetricsPublisher.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class HealthCheckMetricsPublisher : IHealthCheckPublisher
1111
private readonly ILogger<HealthCheckMetricsPublisher> _logger;
1212

1313
public HealthCheckMetricsPublisher(
14-
HealthCheckMetrics healthMetrics,
14+
HealthCheckMetrics healthMetrics,
1515
IApplicationMetrics applicationMetrics,
1616
ILogger<HealthCheckMetricsPublisher> logger)
1717
{
@@ -37,13 +37,13 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke
3737
_applicationMetrics.RecordRequest("health_check", result.Status.ToString().ToLowerInvariant());
3838
_applicationMetrics.RecordDuration("health_check", durationMs);
3939

40-
_logger.LogDebug("Published health check metric for {HealthCheck} with status {Status} in {Duration}ms",
40+
_logger.LogDebug("Published health check metric for {HealthCheck} with status {Status} in {Duration}ms",
4141
healthCheckName, result.Status, durationMs);
4242
}
4343

4444
// Record overall health status
4545
_healthMetrics.RecordHealthCheck("overall", report.Status, report.TotalDuration.TotalMilliseconds);
46-
46+
4747
// Record summary metrics using IApplicationMetrics
4848
_applicationMetrics.RecordRequest("health_check_overall", report.Status.ToString().ToLowerInvariant());
4949
_applicationMetrics.RecordDuration("health_check_overall", report.TotalDuration.TotalMilliseconds);
@@ -53,7 +53,7 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke
5353
{
5454
// Don't let metrics publishing fail health checks
5555
_logger.LogError(ex, "Failed to publish health check metrics");
56-
56+
5757
// Record error metric
5858
_applicationMetrics.RecordRequest("health_check_publisher", "error");
5959
}

tests/KeeperData.Api.Tests.Component/Middleware/ExceptionHandlingMiddlewareTests.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -425,8 +425,8 @@ public async Task Successful_request_records_success_metrics()
425425

426426
_mockMetrics.Verify(m => m.RecordRequest("http_request", "success"), Times.Once);
427427
_mockMetrics.Verify(m => m.RecordDuration("http_request", It.IsAny<double>()), Times.Once);
428-
_mockMetrics.Verify(m => m.RecordCount("http_requests", 1,
429-
It.Is<(string Key, string Value)[]>(tags =>
428+
_mockMetrics.Verify(m => m.RecordCount("http_requests", 1,
429+
It.Is<(string Key, string Value)[]>(tags =>
430430
tags.Any(t => t.Key == "method" && t.Value == "GET") &&
431431
tags.Any(t => t.Key == "endpoint" && t.Value == "/api/test") &&
432432
tags.Any(t => t.Key == "status" && t.Value == "success"))), Times.Once);
@@ -447,19 +447,19 @@ public async Task Exception_records_error_metrics()
447447

448448
_mockMetrics.Verify(m => m.RecordRequest("http_request", "error"), Times.Once);
449449
_mockMetrics.Verify(m => m.RecordDuration("http_request", It.IsAny<double>()), Times.Once);
450-
_mockMetrics.Verify(m => m.RecordCount("http_requests", 1,
451-
It.Is<(string Key, string Value)[]>(tags =>
450+
_mockMetrics.Verify(m => m.RecordCount("http_requests", 1,
451+
It.Is<(string Key, string Value)[]>(tags =>
452452
tags.Any(t => t.Key == "status" && t.Value == "error") &&
453453
tags.Any(t => t.Key == "status_code" && t.Value == "404"))), Times.Once);
454-
_mockMetrics.Verify(m => m.RecordCount("http_errors", 1,
455-
It.Is<(string Key, string Value)[]>(tags =>
454+
_mockMetrics.Verify(m => m.RecordCount("http_errors", 1,
455+
It.Is<(string Key, string Value)[]>(tags =>
456456
tags.Any(t => t.Key == "error_type" && t.Value == "not_found") &&
457457
tags.Any(t => t.Key == "exception_type" && t.Value == "NotFoundException"))), Times.Once);
458458
}
459459

460460
[Theory]
461461
[InlineData(typeof(FluentValidation.ValidationException), "validation_error", 422)]
462-
[InlineData(typeof(DomainException), "domain_error", 400)]
462+
[InlineData(typeof(DomainException), "domain_error", 400)]
463463
[InlineData(typeof(InvalidOperationException), "internal_error", 500)]
464464
public async Task Different_exception_types_record_appropriate_error_metrics(Type exceptionType, string expectedErrorType, int expectedStatusCode)
465465
{
@@ -481,8 +481,8 @@ public async Task Different_exception_types_record_appropriate_error_metrics(Typ
481481
// Assert
482482
context.Response.StatusCode.Should().Be(expectedStatusCode);
483483

484-
_mockMetrics.Verify(m => m.RecordCount("http_errors", 1,
485-
It.Is<(string Key, string Value)[]>(tags =>
484+
_mockMetrics.Verify(m => m.RecordCount("http_errors", 1,
485+
It.Is<(string Key, string Value)[]>(tags =>
486486
tags.Any(t => t.Key == "error_type" && t.Value == expectedErrorType) &&
487487
tags.Any(t => t.Key == "exception_type" && t.Value == exceptionType.Name) &&
488488
tags.Any(t => t.Key == "status_code" && t.Value == expectedStatusCode.ToString()))), Times.Once);

0 commit comments

Comments
 (0)