From 151488a21d28654f052981632323980b8ca58fb8 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Wed, 27 Sep 2023 18:32:02 +0200 Subject: [PATCH 01/24] Aligning metrics with OTel semantic convention --- .../Metric.cs | 4 +- .../Metric.cs | 5 +- .../TelemetryHealthCheckPublisher.cs | 4 +- .../Linux/LinuxUtilizationProvider.cs | 21 ++++---- .../ResourceUtilizationCounters.cs | 10 ++-- .../Windows/WindowsCounters.cs | 50 ++++++++++--------- 6 files changed, 49 insertions(+), 45 deletions(-) diff --git a/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs b/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs index 944fa08970f..c274b4b6a07 100644 --- a/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs +++ b/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs @@ -8,9 +8,9 @@ namespace Microsoft.AspNetCore.HeaderParsing; internal static partial class Metric { - [Counter("HeaderName", "Kind", Name = @"HeaderParsing.ParsingErrors")] + [Counter("header.name", "error.kind", Name = "aspnetcore.header_parsing.parse_errors")] public static partial ParsingErrorCounter CreateParsingErrorCounter(Meter meter); - [Counter("HeaderName", "Type", Name = @"HeaderParsing.CacheAccess")] + [Counter("header.name", "access.type", Name = "aspnetcore.header_parsing.cache_accesses")] public static partial CacheAccessCounter CreateCacheAccessCounter(Meter meter); } diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs index e366c714bbe..143fadf169d 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs @@ -12,10 +12,11 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks; internal static partial class Metric { - [Counter("healthy", "status", Name = @"R9\\HealthCheck\\Report")] + // TODO: should we rename "healthy" to "is_healthy"? Or maybe remove the attribute at all? + [Counter("healthy", "health.status", Name = "health_check.reports")] public static partial HealthCheckReportCounter CreateHealthCheckReportCounter(Meter meter); - [Counter("name", "status", Name = @"R9\\HealthCheck\\UnhealthyHealthCheck")] + [Counter("health_check.name", "health.status", Name = "health_check.unhealthy_checks")] public static partial UnhealthyHealthCheckCounter CreateUnhealthyHealthCheckCounter(Meter meter); public static void RecordMetric(this HealthCheckReportCounter counterMetric, bool isHealthy, HealthStatus status) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs index 217bef39e8f..2d5f051fd86 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs @@ -50,7 +50,7 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke Log.Healthy(_logger, report.Status); } - _metrics.HealthCheckReportCounter.RecordMetric(true, report.Status); + _metrics.HealthCheckReportCounter.RecordMetric(isHealthy: true, report.Status); } else { @@ -80,7 +80,7 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke Log.Unhealthy(_logger, report.Status, stringBuilder); PoolFactory.SharedStringBuilderPool.Return(stringBuilder); - _metrics.HealthCheckReportCounter.RecordMetric(false, report.Status); + _metrics.HealthCheckReportCounter.RecordMetric(isHealthy: false, report.Status); } return Task.CompletedTask; diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs index 679d5a1c3bf..37e67167e75 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs @@ -9,7 +9,8 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux; internal sealed class LinuxUtilizationProvider : ISnapshotProvider { - private const float Hundred = 100.0f; + private const long Hundred = 100L; + private readonly object _cpuLocker = new(); private readonly object _memoryLocker = new(); private readonly LinuxUtilizationParser _parser; @@ -48,7 +49,7 @@ public LinuxUtilizationProvider(IOptions options, Lin var hostCpus = _parser.GetHostCpuCount(); var availableCpus = _parser.GetCgroupLimitedCpus(); - _scale = hostCpus * Hundred / availableCpus; + _scale = hostCpus / availableCpus; _scaleForTrackerApi = hostCpus / availableCpus; #pragma warning disable CA2000 // Dispose objects before losing scope @@ -58,13 +59,13 @@ public LinuxUtilizationProvider(IOptions options, Lin var meter = meterFactory.Create("Microsoft.Extensions.Diagnostics.ResourceMonitoring"); #pragma warning restore CA2000 // Dispose objects before losing scope - _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.CpuConsumptionPercentage, observeValue: CpuPercentage); - _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.MemoryConsumptionPercentage, observeValue: MemoryPercentage); + _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.CpuConsumptionPercentage, observeValue: CpuUtilization, unit: "1"); + _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.MemoryConsumptionPercentage, observeValue: MemoryUtilization, unit: "1"); Resources = new SystemResources(1, hostCpus, _totalMemoryInBytes, hostMemory); } - public double CpuPercentage() + public double CpuUtilization() { var now = _timeProvider.GetUtcNow(); bool needUpdate = false; @@ -91,7 +92,7 @@ public double CpuPercentage() if (deltaHost > 0 && deltaCgroup > 0) { - var percentage = Math.Min(Hundred, deltaCgroup / deltaHost * _scale); + var percentage = Math.Min(1.0, deltaCgroup / deltaHost * _scale); _cpuPercentage = percentage; _refreshAfterCpu = now.Add(_cpuRefreshInterval); @@ -105,7 +106,7 @@ public double CpuPercentage() return _cpuPercentage; } - public double MemoryPercentage() + public double MemoryUtilization() { var now = _timeProvider.GetUtcNow(); bool needUpdate = false; @@ -126,7 +127,7 @@ public double MemoryPercentage() { if (now >= _refreshAfterMemory) { - var memoryPercentage = Math.Min(Hundred, (double)memoryUsed / _totalMemoryInBytes * Hundred); + var memoryPercentage = Math.Min(1.0, (double)memoryUsed / _totalMemoryInBytes); _memoryPercentage = memoryPercentage; _refreshAfterMemory = now.Add(_memoryRefreshInterval); @@ -149,9 +150,9 @@ public Snapshot GetSnapshot() var memoryUsed = _parser.GetMemoryUsageInBytes(); return new Snapshot( - totalTimeSinceStart: TimeSpan.FromTicks(hostTime / (long)Hundred), + totalTimeSinceStart: TimeSpan.FromTicks(hostTime / Hundred), kernelTimeSinceStart: TimeSpan.Zero, - userTimeSinceStart: TimeSpan.FromTicks((long)(cgroupTime / (long)Hundred * _scaleForTrackerApi)), + userTimeSinceStart: TimeSpan.FromTicks((long)(cgroupTime / Hundred * _scaleForTrackerApi)), memoryUsageInBytes: memoryUsed); } } diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationCounters.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationCounters.cs index f873bef44d6..933b00bf5da 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationCounters.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationCounters.cs @@ -7,24 +7,24 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring; /// Represents the names of instruments published by this package. /// /// -/// These counters are currently only published on Linux. +/// These metrics are currently only published on Linux. /// /// public static class ResourceUtilizationCounters { /// - /// Gets the CPU consumption of the running application in percentages. + /// Gets the CPU consumption of the running application in range [0, 1]. /// /// /// The type of an instrument is . /// - public static string CpuConsumptionPercentage => "cpu_consumption_percentage"; + public static string CpuUtilization => "process.cpu.utilization"; /// - /// Gets the memory consumption of the running application in percentages. + /// Gets the memory consumption of the running application in range [0, 1]. /// /// /// The type of an instrument is . /// - public static string MemoryConsumptionPercentage => "memory_consumption_percentage"; + public static string MemoryUtilization => "process.memory.utilization"; } diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs index 5f87b9dfc19..6a5711856a4 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs @@ -17,8 +17,10 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) var meter = meterFactory.Create("Microsoft.Extensions.Diagnostics.ResourceMonitoring"); #pragma warning restore CA2000 // Dispose objects before losing scope + // TODO: these should be heavily rewritten to align with + // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/system-metrics.md#metric-systemnetworkconnections _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_closed_count", + "process.network.tcp.ipv4_connection_closed_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -26,7 +28,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_listen_count", + "process.network.tcp.ipv4_connection_listen_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -34,7 +36,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_syn_sent_count", + "process.network.tcp.ipv4_connection_syn_sent_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -42,7 +44,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_syn_received_count", + "process.network.tcp.ipv4_connection_syn_received_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -50,7 +52,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_established_count", + "process.network.tcp.ipv4_connection_established_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -58,7 +60,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_fin_wait_1_count", + "process.network.tcp.ipv4_connection_fin_wait_1_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -66,7 +68,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_fin_wait_2_count", + "process.network.tcp.ipv4_connection_fin_wait_2_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -74,7 +76,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_close_wait_count", + "process.network.tcp.ipv4_connection_close_wait_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -82,7 +84,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_closing_count", + "process.network.tcp.ipv4_connection_closing_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -90,7 +92,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_last_ack_count", + "process.network.tcp.ipv4_connection_last_ack_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -98,7 +100,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_time_wait_count", + "process.network.tcp.ipv4_connection_time_wait_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -106,7 +108,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv4_tcp_connection_delete_tcb_count", + "process.network.tcp.ipv4_connection_delete_tcb_count", () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -114,7 +116,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_closed_count", + "process.network.tcp.ipv6_connection_closed_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -122,7 +124,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_listen_count", + "process.network.tcp.ipv6_connection_listen_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -130,7 +132,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_syn_sent_count", + "process.network.tcp.ipv6_connection_syn_sent_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -138,7 +140,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_syn_received_count", + "process.network.tcp.ipv6_connection_syn_received_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -146,7 +148,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_established_count", + "process.network.tcp.ipv6_connection_established_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -154,7 +156,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_fin_wait_1_count", + "process.network.tcp.ipv6_connection_fin_wait_1_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -162,7 +164,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_fin_wait_2_count", + "process.network.tcp.ipv6_connection_fin_wait_2_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -170,7 +172,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_close_wait_count", + "process.network.tcp.ipv6_connection_close_wait_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -178,7 +180,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_closing_count", + "process.network.tcp.ipv6_connection_closing_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -186,7 +188,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_last_ack_count", + "process.network.tcp.ipv6_connection_last_ack_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -194,7 +196,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_time_wait_count", + "process.network.tcp.ipv6_connection_time_wait_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -202,7 +204,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) }); _ = meter.CreateObservableGauge( - "ipv6_tcp_connection_delete_tcb_count", + "process.network.tcp.ipv6_connection_delete_tcb_count", () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); From eb3189c640d6bf86ff86f4f8802b292ed80609b0 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Wed, 4 Oct 2023 14:45:01 +0200 Subject: [PATCH 02/24] fix the build --- .../Linux/LinuxUtilizationProvider.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs index 37e67167e75..656e5a2ca9f 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs @@ -59,8 +59,8 @@ public LinuxUtilizationProvider(IOptions options, Lin var meter = meterFactory.Create("Microsoft.Extensions.Diagnostics.ResourceMonitoring"); #pragma warning restore CA2000 // Dispose objects before losing scope - _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.CpuConsumptionPercentage, observeValue: CpuUtilization, unit: "1"); - _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.MemoryConsumptionPercentage, observeValue: MemoryUtilization, unit: "1"); + _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.CpuUtilization, observeValue: CpuUtilization, unit: "1"); + _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.MemoryUtilization, observeValue: MemoryUtilization, unit: "1"); Resources = new SystemResources(1, hostCpus, _totalMemoryInBytes, hostMemory); } From 3ca7aa26f6f34f6dc8d767f2e595e1b25b9d08b6 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Wed, 4 Oct 2023 18:06:51 +0200 Subject: [PATCH 03/24] convert WindowsCounters --- .../Metric.cs | 1 + .../Windows/WindowsCounters.cs | 202 +++++++++++++----- .../Metrics/MetricCollector.cs | 2 +- 3 files changed, 155 insertions(+), 50 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs index 143fadf169d..02a28cf720d 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs @@ -13,6 +13,7 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks; internal static partial class Metric { // TODO: should we rename "healthy" to "is_healthy"? Or maybe remove the attribute at all? + // To klauco: do we really need this true/false dimension? We already have "health.status" dimension. [Counter("healthy", "health.status", Name = "health_check.reports")] public static partial HealthCheckReportCounter CreateHealthCheckReportCounter(Meter meter); diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs index 6a5711856a4..16e2018e67d 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections.Generic; using System.Diagnostics.Metrics; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Network; @@ -10,6 +11,8 @@ internal sealed class WindowsCounters { public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) { + const string NetworkStateKey = "system.network.state"; + const string GaugeName = "process.network.connections"; #pragma warning disable CA2000 // Dispose objects before losing scope // We don't dispose the meter because IMeterFactory handles that // An issue on analyzer side: https://github.com/dotnet/roslyn-analyzers/issues/6912 @@ -17,198 +20,299 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) var meter = meterFactory.Create("Microsoft.Extensions.Diagnostics.ResourceMonitoring"); #pragma warning restore CA2000 // Dispose objects before losing scope - // TODO: these should be heavily rewritten to align with + var tcpTag = KeyValuePair.Create("network.transport", "tcp"); + var tcpVersionFourTag = KeyValuePair.Create("network.transport.version", "ipv4"); + var tcpVersionSixTag = KeyValuePair.Create("network.transport.version", "ipv6"); + + // TODO: these are heavily rewritten to align with // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/system-metrics.md#metric-systemnetworkconnections + // All these should be of UpDownCounter type _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_closed_count", + //"process.network.tcp.ipv4_connection_closed_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.ClosedCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "closed") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_listen_count", + //"process.network.tcp.ipv4_connection_listen_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.ListenCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "listen") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_syn_sent_count", + //"process.network.tcp.ipv4_connection_syn_sent_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.SynSentCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "syn_sent") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_syn_received_count", + //"process.network.tcp.ipv4_connection_syn_received_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.SynRcvdCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "syn_recv") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_established_count", + //"process.network.tcp.ipv4_connection_established_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.EstabCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "established") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_fin_wait_1_count", + //"process.network.tcp.ipv4_connection_fin_wait_1_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.FinWait1Count; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "fin_wait_1") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_fin_wait_2_count", + //"process.network.tcp.ipv4_connection_fin_wait_2_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.FinWait2Count; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "fin_wait_2") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_close_wait_count", + //"process.network.tcp.ipv4_connection_close_wait_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.CloseWaitCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "close_wait") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_closing_count", + //"process.network.tcp.ipv4_connection_closing_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.ClosingCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "closing") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_last_ack_count", + //"process.network.tcp.ipv4_connection_last_ack_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.LastAckCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "last_ack") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_time_wait_count", + //"process.network.tcp.ipv4_connection_time_wait_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.TimeWaitCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "time_wait") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv4_connection_delete_tcb_count", + //"process.network.tcp.ipv4_connection_delete_tcb_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); return snapshot.DeleteTcbCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "delete") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_closed_count", + //"process.network.tcp.ipv6_connection_closed_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.ClosedCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "close") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_listen_count", + //"process.network.tcp.ipv6_connection_listen_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.ListenCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "listen") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_syn_sent_count", + //"process.network.tcp.ipv6_connection_syn_sent_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.SynSentCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "syn_sent") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_syn_received_count", + //"process.network.tcp.ipv6_connection_syn_received_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.SynRcvdCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "syn_recv") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_established_count", + //"process.network.tcp.ipv6_connection_established_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.EstabCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "established") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_fin_wait_1_count", + //"process.network.tcp.ipv6_connection_fin_wait_1_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.FinWait1Count; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "fin_wait_1") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_fin_wait_2_count", + //"process.network.tcp.ipv6_connection_fin_wait_2_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.FinWait2Count; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "fin_wait_2") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_close_wait_count", + //"process.network.tcp.ipv6_connection_close_wait_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.CloseWaitCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "close_wait") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_closing_count", + //"process.network.tcp.ipv6_connection_closing_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.ClosingCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "closing") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_last_ack_count", + //"process.network.tcp.ipv6_connection_last_ack_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.LastAckCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "last_ack") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_time_wait_count", + //"process.network.tcp.ipv6_connection_time_wait_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.TimeWaitCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "time_wait") }); _ = meter.CreateObservableGauge( - "process.network.tcp.ipv6_connection_delete_tcb_count", + //"process.network.tcp.ipv6_connection_delete_tcb_count", + GaugeName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); return snapshot.DeleteTcbCount; - }); + }, + unit: "{connection}", + description: null, + tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "delete") }); } } diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Metrics/MetricCollector.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Metrics/MetricCollector.cs index 5dea2d6efac..f834465989b 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Metrics/MetricCollector.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Metrics/MetricCollector.cs @@ -250,7 +250,7 @@ public Task WaitForMeasurementsAsync(int minCount, CancellationToken cancellatio [SuppressMessage("Resilience", "EA0014:The async method doesn't support cancellation", Justification = "Not relevant in this case")] public async Task WaitForMeasurementsAsync(int minCount, TimeSpan timeout) { -#if NET8_0_OR_GREATER +#if NET8_0 using var cancellationTokenSource = new CancellationTokenSource(timeout, _timeProvider); #else using var cancellationTokenSource = _timeProvider.CreateCancellationTokenSource(timeout); From bd7a57c7859a8ca537f0e9750633b3ea700ed56c Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Wed, 4 Oct 2023 18:46:03 +0200 Subject: [PATCH 04/24] resilience enrichment tags --- .../Resilience/Internal/ResilienceTagNames.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs index 158f77e362e..460138a5606 100644 --- a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs +++ b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs @@ -5,13 +5,13 @@ namespace Microsoft.Extensions.Resilience.Internal; internal static class ResilienceTagNames { - public const string FailureSource = "failure-source"; + public const string FailureSource = "failure.source"; - public const string FailureReason = "failure-reason"; + public const string FailureReason = "failure.reason"; - public const string FailureSummary = "failure-summary"; + public const string FailureSummary = "failure.summary"; - public const string DependencyName = "dep-name"; + public const string DependencyName = "dependency.name"; - public const string RequestName = "req-name"; + public const string RequestName = "request.name"; } From 7cab4c8daf2c003be512c5e18bba85d519b85ec9 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Wed, 4 Oct 2023 18:50:54 +0200 Subject: [PATCH 05/24] again Windows counters --- .../Windows/WindowsCounters.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs index 16e2018e67d..d36c29ff766 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs @@ -21,8 +21,10 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) #pragma warning restore CA2000 // Dispose objects before losing scope var tcpTag = KeyValuePair.Create("network.transport", "tcp"); - var tcpVersionFourTag = KeyValuePair.Create("network.transport.version", "ipv4"); - var tcpVersionSixTag = KeyValuePair.Create("network.transport.version", "ipv6"); + + // These are covered in https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-metrics.md#attributes: + var tcpVersionFourTag = KeyValuePair.Create("network.type", "ipv4"); + var tcpVersionSixTag = KeyValuePair.Create("network.type", "ipv6"); // TODO: these are heavily rewritten to align with // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/system-metrics.md#metric-systemnetworkconnections From 98e3f0e42a39925e88fce1e7363cf501271e4e02 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Thu, 5 Oct 2023 16:46:56 +0200 Subject: [PATCH 06/24] Update src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs Co-authored-by: Noah Falk --- src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs b/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs index c274b4b6a07..b23072fca78 100644 --- a/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs +++ b/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs @@ -8,7 +8,7 @@ namespace Microsoft.AspNetCore.HeaderParsing; internal static partial class Metric { - [Counter("header.name", "error.kind", Name = "aspnetcore.header_parsing.parse_errors")] + [Counter("header.name", "error.type", Name = "aspnetcore.header_parsing.parse_errors")] public static partial ParsingErrorCounter CreateParsingErrorCounter(Meter meter); [Counter("header.name", "access.type", Name = "aspnetcore.header_parsing.cache_accesses")] From 2967ec96d4d3a46cf43e54f8ff5ef22e4e5d69e1 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Thu, 5 Oct 2023 17:14:55 +0200 Subject: [PATCH 07/24] fixes + improve mutation score --- .../Linux/LinuxUtilizationProvider.cs | 5 +++-- .../ResourceMonitoringOptions.Linux.cs | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs index 656e5a2ca9f..4b48058e326 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs @@ -9,6 +9,7 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Linux; internal sealed class LinuxUtilizationProvider : ISnapshotProvider { + private const double One = 1.0; private const long Hundred = 100L; private readonly object _cpuLocker = new(); @@ -92,7 +93,7 @@ public double CpuUtilization() if (deltaHost > 0 && deltaCgroup > 0) { - var percentage = Math.Min(1.0, deltaCgroup / deltaHost * _scale); + var percentage = Math.Min(One, deltaCgroup / deltaHost * _scale); _cpuPercentage = percentage; _refreshAfterCpu = now.Add(_cpuRefreshInterval); @@ -127,7 +128,7 @@ public double MemoryUtilization() { if (now >= _refreshAfterMemory) { - var memoryPercentage = Math.Min(1.0, (double)memoryUsed / _totalMemoryInBytes); + var memoryPercentage = Math.Min(One, (double)memoryUsed / _totalMemoryInBytes); _memoryPercentage = memoryPercentage; _refreshAfterMemory = now.Add(_memoryRefreshInterval); diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs index 5ec54ef4d57..f21bdbe23d3 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs @@ -13,7 +13,7 @@ public partial class ResourceMonitoringOptions internal static readonly TimeSpan DefaultRefreshInterval = TimeSpan.FromSeconds(5); /// - /// Gets or sets the default interval used for refreshing values reported by . + /// Gets or sets the default interval used for refreshing values reported by . /// /// /// The default value is 5 seconds. @@ -26,7 +26,7 @@ public partial class ResourceMonitoringOptions public TimeSpan CpuConsumptionRefreshInterval { get; set; } = DefaultRefreshInterval; /// - /// Gets or sets the default interval used for refreshing values reported by . + /// Gets or sets the default interval used for refreshing values reported by . /// /// /// The default value is 5 seconds. From 2fc604f58194af4ab87903d973632a50b091995c Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Fri, 6 Oct 2023 13:30:59 +0200 Subject: [PATCH 08/24] CR + fixes --- .../Linux/LinuxUtilizationProvider.cs | 4 ++-- ...ensions.Diagnostics.ResourceMonitoring.csproj | 2 -- ...xtensions.Diagnostics.ResourceMonitoring.json | 14 -------------- .../ResourceMonitoringOptions.Linux.cs | 4 ++-- ...ters.cs => ResourceUtilizationInstruments.cs} | 6 +++--- .../Windows/WindowsCounters.cs | 6 +++--- .../Linux/AcceptanceTest.cs | 8 ++++---- .../Linux/LinuxCountersTests.cs | 4 ++-- .../ResourceUtilizationCountersTests.cs | 16 ---------------- 9 files changed, 16 insertions(+), 48 deletions(-) rename src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/{ResourceUtilizationCounters.cs => ResourceUtilizationInstruments.cs} (82%) delete mode 100644 test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceUtilizationCountersTests.cs diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs index 4b48058e326..b2c2f259216 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Linux/LinuxUtilizationProvider.cs @@ -60,8 +60,8 @@ public LinuxUtilizationProvider(IOptions options, Lin var meter = meterFactory.Create("Microsoft.Extensions.Diagnostics.ResourceMonitoring"); #pragma warning restore CA2000 // Dispose objects before losing scope - _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.CpuUtilization, observeValue: CpuUtilization, unit: "1"); - _ = meter.CreateObservableGauge(name: ResourceUtilizationCounters.MemoryUtilization, observeValue: MemoryUtilization, unit: "1"); + _ = meter.CreateObservableGauge(name: ResourceUtilizationInstruments.CpuUtilization, observeValue: CpuUtilization, unit: "1"); + _ = meter.CreateObservableGauge(name: ResourceUtilizationInstruments.MemoryUtilization, observeValue: MemoryUtilization, unit: "1"); Resources = new SystemResources(1, hostCpus, _totalMemoryInBytes, hostMemory); } diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Microsoft.Extensions.Diagnostics.ResourceMonitoring.csproj b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Microsoft.Extensions.Diagnostics.ResourceMonitoring.csproj index 333067cd272..5801f144a17 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Microsoft.Extensions.Diagnostics.ResourceMonitoring.csproj +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Microsoft.Extensions.Diagnostics.ResourceMonitoring.csproj @@ -42,8 +42,6 @@ - - diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Microsoft.Extensions.Diagnostics.ResourceMonitoring.json b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Microsoft.Extensions.Diagnostics.ResourceMonitoring.json index 3bb53fbb05d..f20b3d49685 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Microsoft.Extensions.Diagnostics.ResourceMonitoring.json +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Microsoft.Extensions.Diagnostics.ResourceMonitoring.json @@ -133,20 +133,6 @@ } ] }, - { - "Type": "static class Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceUtilizationCounters", - "Stage": "Stable", - "Properties": [ - { - "Member": "static string Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceUtilizationCounters.CpuConsumptionPercentage { get; }", - "Stage": "Stable" - }, - { - "Member": "static string Microsoft.Extensions.Diagnostics.ResourceMonitoring.ResourceUtilizationCounters.MemoryConsumptionPercentage { get; }", - "Stage": "Stable" - } - ] - }, { "Type": "readonly struct Microsoft.Extensions.Diagnostics.ResourceMonitoring.SystemResources", "Stage": "Stable", diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs index f21bdbe23d3..27dc1aa1a15 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs @@ -13,7 +13,7 @@ public partial class ResourceMonitoringOptions internal static readonly TimeSpan DefaultRefreshInterval = TimeSpan.FromSeconds(5); /// - /// Gets or sets the default interval used for refreshing values reported by . + /// Gets or sets the default interval used for refreshing values reported by "process.cpu.utilization" metrics. /// /// /// The default value is 5 seconds. @@ -26,7 +26,7 @@ public partial class ResourceMonitoringOptions public TimeSpan CpuConsumptionRefreshInterval { get; set; } = DefaultRefreshInterval; /// - /// Gets or sets the default interval used for refreshing values reported by . + /// Gets or sets the default interval used for refreshing values reported by "process.memory.virtual.utilization" metrics. /// /// /// The default value is 5 seconds. diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationCounters.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationInstruments.cs similarity index 82% rename from src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationCounters.cs rename to src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationInstruments.cs index 933b00bf5da..e06984eb13f 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationCounters.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationInstruments.cs @@ -10,7 +10,7 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring; /// These metrics are currently only published on Linux. /// /// -public static class ResourceUtilizationCounters +internal static class ResourceUtilizationInstruments { /// /// Gets the CPU consumption of the running application in range [0, 1]. @@ -18,7 +18,7 @@ public static class ResourceUtilizationCounters /// /// The type of an instrument is . /// - public static string CpuUtilization => "process.cpu.utilization"; + public const string CpuUtilization = "process.cpu.utilization"; /// /// Gets the memory consumption of the running application in range [0, 1]. @@ -26,5 +26,5 @@ public static class ResourceUtilizationCounters /// /// The type of an instrument is . /// - public static string MemoryUtilization => "process.memory.utilization"; + public const string MemoryUtilization = "process.memory.virtual.utilization"; } diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs index d36c29ff766..024aed2a372 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs @@ -20,11 +20,11 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) var meter = meterFactory.Create("Microsoft.Extensions.Diagnostics.ResourceMonitoring"); #pragma warning restore CA2000 // Dispose objects before losing scope - var tcpTag = KeyValuePair.Create("network.transport", "tcp"); + var tcpTag = new KeyValuePair("network.transport", "tcp"); // These are covered in https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-metrics.md#attributes: - var tcpVersionFourTag = KeyValuePair.Create("network.type", "ipv4"); - var tcpVersionSixTag = KeyValuePair.Create("network.type", "ipv6"); + var tcpVersionFourTag = new KeyValuePair("network.type", "ipv4"); + var tcpVersionSixTag = new KeyValuePair("network.type", "ipv6"); // TODO: these are heavily rewritten to align with // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/system-metrics.md#metric-systemnetworkconnections diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs index d0acbad4074..4f637ef72a1 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/AcceptanceTest.cs @@ -157,8 +157,8 @@ public Task ResourceUtilizationTracker_Reports_The_Same_Values_As_One_Can_Observ listener.InstrumentPublished = (i, m) => { - if (i.Name == ResourceUtilizationCounters.CpuConsumptionPercentage - || i.Name == ResourceUtilizationCounters.MemoryConsumptionPercentage) + if (i.Name == ResourceUtilizationInstruments.CpuUtilization + || i.Name == ResourceUtilizationInstruments.MemoryUtilization) { m.EnableMeasurementEvents(i); } @@ -166,11 +166,11 @@ public Task ResourceUtilizationTracker_Reports_The_Same_Values_As_One_Can_Observ listener.SetMeasurementEventCallback((m, f, _, _) => { - if (m.Name == ResourceUtilizationCounters.CpuConsumptionPercentage) + if (m.Name == ResourceUtilizationInstruments.CpuUtilization) { cpuFromGauge = f; } - else if (m.Name == ResourceUtilizationCounters.MemoryConsumptionPercentage) + else if (m.Name == ResourceUtilizationInstruments.MemoryUtilization) { memoryFromGauge = f; } diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxCountersTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxCountersTests.cs index 3e75a1da2c2..d4386605c5c 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxCountersTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxCountersTests.cs @@ -61,9 +61,9 @@ public void LinuxCounters_Registers_Instruments() listener.RecordObservableInstruments(); Assert.Equal(2, samples.Count); - Assert.Equal(ResourceUtilizationCounters.CpuConsumptionPercentage, samples[0].instrument.Name); + Assert.Equal(ResourceUtilizationInstruments.CpuUtilization, samples[0].instrument.Name); Assert.Equal(double.NaN, samples[0].value); - Assert.Equal(ResourceUtilizationCounters.MemoryConsumptionPercentage, samples[1].instrument.Name); + Assert.Equal(ResourceUtilizationInstruments.MemoryUtilization, samples[1].instrument.Name); Assert.Equal(50, samples[1].value); } } diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceUtilizationCountersTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceUtilizationCountersTests.cs deleted file mode 100644 index 5cfa3003cb7..00000000000 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/ResourceUtilizationCountersTests.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using Xunit; - -namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Test; - -public class ResourceUtilizationCountersTests -{ - [Fact] - public void ExpectedStrings() - { - Assert.Equal("cpu_consumption_percentage", ResourceUtilizationCounters.CpuConsumptionPercentage); - Assert.Equal("memory_consumption_percentage", ResourceUtilizationCounters.MemoryConsumptionPercentage); - } -} From fa0122333867f636f5f8ee4bbacc57c79b1a7acd Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Fri, 6 Oct 2023 13:35:42 +0200 Subject: [PATCH 09/24] remove redundant dimension --- .../Metric.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs index 02a28cf720d..0d3daee41fc 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs @@ -2,7 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Diagnostics.Metrics; -using System.Globalization; using Microsoft.Extensions.Diagnostics.Metrics; using Microsoft.Extensions.EnumStrings; @@ -12,16 +11,14 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks; internal static partial class Metric { - // TODO: should we rename "healthy" to "is_healthy"? Or maybe remove the attribute at all? - // To klauco: do we really need this true/false dimension? We already have "health.status" dimension. - [Counter("healthy", "health.status", Name = "health_check.reports")] + [Counter("health.status", Name = "health_check.reports")] public static partial HealthCheckReportCounter CreateHealthCheckReportCounter(Meter meter); [Counter("health_check.name", "health.status", Name = "health_check.unhealthy_checks")] public static partial UnhealthyHealthCheckCounter CreateUnhealthyHealthCheckCounter(Meter meter); public static void RecordMetric(this HealthCheckReportCounter counterMetric, bool isHealthy, HealthStatus status) - => counterMetric.Add(1, isHealthy.ToString(CultureInfo.InvariantCulture), status.ToInvariantString()); + => counterMetric.Add(1, status.ToInvariantString()); public static void RecordMetric(this UnhealthyHealthCheckCounter counterMetric, string name, HealthStatus status) => counterMetric.Add(1, name, status.ToInvariantString()); From 3a66a5d43b031c1ecf1e7600fd35f526cb5e4f8e Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Fri, 6 Oct 2023 13:43:30 +0200 Subject: [PATCH 10/24] CR --- .../Windows/WindowsSnapshotProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsSnapshotProvider.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsSnapshotProvider.cs index 97cd645a946..691127d351a 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsSnapshotProvider.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsSnapshotProvider.cs @@ -33,6 +33,6 @@ public Snapshot GetSnapshot() TimeSpan.FromTicks(TimeProvider.GetUtcNow().Ticks), TimeSpan.FromTicks(process.PrivilegedProcessorTime.Ticks), TimeSpan.FromTicks(process.UserProcessorTime.Ticks), - (ulong)process.WorkingSet64); + (ulong)process.VirtualMemorySize64); } } From fa880430ad06106ca8bce8f9ea191c4cd0e4f389 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Fri, 6 Oct 2023 13:47:52 +0200 Subject: [PATCH 11/24] Update src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Metrics/MetricCollector.cs --- .../Metrics/MetricCollector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Metrics/MetricCollector.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Metrics/MetricCollector.cs index f834465989b..5dea2d6efac 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Metrics/MetricCollector.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.Testing/Metrics/MetricCollector.cs @@ -250,7 +250,7 @@ public Task WaitForMeasurementsAsync(int minCount, CancellationToken cancellatio [SuppressMessage("Resilience", "EA0014:The async method doesn't support cancellation", Justification = "Not relevant in this case")] public async Task WaitForMeasurementsAsync(int minCount, TimeSpan timeout) { -#if NET8_0 +#if NET8_0_OR_GREATER using var cancellationTokenSource = new CancellationTokenSource(timeout, _timeProvider); #else using var cancellationTokenSource = _timeProvider.CreateCancellationTokenSource(timeout); From 3613c4d8b60cad7e213b15cbc76677de0b11a688 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Fri, 6 Oct 2023 15:45:19 +0200 Subject: [PATCH 12/24] fixes --- .../Microsoft.Gen.Metrics/Emitter.cs | 2 +- .../Metric.cs | 2 +- .../TelemetryHealthCheckPublisher.cs | 4 ++-- .../HeaderParsingFeatureTests.cs | 18 +++++++++-------- .../TelemetryHealthChecksPublisherTests.cs | 20 ++++++------------- 5 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/Generators/Microsoft.Gen.Metrics/Emitter.cs b/src/Generators/Microsoft.Gen.Metrics/Emitter.cs index d6b0decec0d..0e6e7da0091 100644 --- a/src/Generators/Microsoft.Gen.Metrics/Emitter.cs +++ b/src/Generators/Microsoft.Gen.Metrics/Emitter.cs @@ -297,7 +297,7 @@ private void GenTagList(MetricMethod metricMethod) foreach (var tagName in metricMethod.TagKeys) { var paramName = GetSanitizedParamName(tagName); - OutLn($"new global::System.Collections.Generic.KeyValuePair(\"{paramName}\", {paramName}),"); + OutLn($"new global::System.Collections.Generic.KeyValuePair(\"{tagName}\", {paramName}),"); } } else diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs index 0d3daee41fc..12f5e2ada67 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs @@ -17,7 +17,7 @@ internal static partial class Metric [Counter("health_check.name", "health.status", Name = "health_check.unhealthy_checks")] public static partial UnhealthyHealthCheckCounter CreateUnhealthyHealthCheckCounter(Meter meter); - public static void RecordMetric(this HealthCheckReportCounter counterMetric, bool isHealthy, HealthStatus status) + public static void RecordMetric(this HealthCheckReportCounter counterMetric, HealthStatus status) => counterMetric.Add(1, status.ToInvariantString()); public static void RecordMetric(this UnhealthyHealthCheckCounter counterMetric, string name, HealthStatus status) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs index 2d5f051fd86..133258997bc 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs @@ -50,7 +50,7 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke Log.Healthy(_logger, report.Status); } - _metrics.HealthCheckReportCounter.RecordMetric(isHealthy: true, report.Status); + _metrics.HealthCheckReportCounter.RecordMetric(report.Status); } else { @@ -80,7 +80,7 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke Log.Unhealthy(_logger, report.Status, stringBuilder); PoolFactory.SharedStringBuilderPool.Return(stringBuilder); - _metrics.HealthCheckReportCounter.RecordMetric(isHealthy: false, report.Status); + _metrics.HealthCheckReportCounter.RecordMetric(report.Status); } return Task.CompletedTask; diff --git a/test/Libraries/Microsoft.AspNetCore.HeaderParsing.Tests/HeaderParsingFeatureTests.cs b/test/Libraries/Microsoft.AspNetCore.HeaderParsing.Tests/HeaderParsingFeatureTests.cs index b8d53275e70..7f8c7796da2 100644 --- a/test/Libraries/Microsoft.AspNetCore.HeaderParsing.Tests/HeaderParsingFeatureTests.cs +++ b/test/Libraries/Microsoft.AspNetCore.HeaderParsing.Tests/HeaderParsingFeatureTests.cs @@ -135,7 +135,7 @@ public void TryParse_returns_false_on_error() { using var meter = new Meter(nameof(TryParse_returns_false_on_error)); var metrics = GetMockedMetrics(meter); - using var metricCollector = new MetricCollector(meter, @"HeaderParsing.ParsingErrors"); + using var metricCollector = new MetricCollector(meter, "aspnetcore.header_parsing.parse_errors"); Context.Request.Headers["Date"] = "Not a date."; var feature = new HeaderParsingFeature(Registry, _logger, metrics) { Context = Context }; @@ -147,10 +147,11 @@ public void TryParse_returns_false_on_error() Assert.Equal("Can't parse header 'Date' due to 'Unable to parse date time offset value.'.", _logger.Collector.LatestRecord.Message); - var latest = metricCollector.LastMeasurement!; + var latest = metricCollector.LastMeasurement; + Assert.NotNull(latest); latest.Value.Should().Be(1); - latest.Tags["HeaderName"].Should().Be("Date"); - latest.Tags["Kind"].Should().Be("Unable to parse date time offset value."); + latest.Tags["header.name"].Should().Be("Date"); + latest.Tags["error.type"].Should().Be("Unable to parse date time offset value."); } [Fact] @@ -190,7 +191,7 @@ public void CachingWorks() { using var meter = new Meter(nameof(CachingWorks)); var metrics = GetMockedMetrics(meter); - using var metricCollector = new MetricCollector(meter, @"HeaderParsing.CacheAccess"); + using var metricCollector = new MetricCollector(meter, "aspnetcore.header_parsing.cache_accesses"); Context.Request.Headers[HeaderNames.CacheControl] = "max-age=604800"; @@ -204,10 +205,11 @@ public void CachingWorks() Assert.Same(value1, value2); Assert.Same(value1, value3); - var latest = metricCollector.LastMeasurement!; + var latest = metricCollector.LastMeasurement; + Assert.NotNull(latest); latest.Value.Should().Be(1); - latest.Tags["HeaderName"].Should().Be(HeaderNames.CacheControl); - latest.Tags["Type"].Should().Be("Hit"); + latest.Tags["header.name"].Should().Be(HeaderNames.CacheControl); + latest.Tags["access.type"].Should().Be("Hit"); } private static HeaderParsingMetrics GetMockedMetrics(Meter meter) diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common.Tests/TelemetryHealthChecksPublisherTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common.Tests/TelemetryHealthChecksPublisherTests.cs index ad1c5226e35..70df808eb8d 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common.Tests/TelemetryHealthChecksPublisherTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common.Tests/TelemetryHealthChecksPublisherTests.cs @@ -17,10 +17,10 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks.Test; public class TelemetryHealthChecksPublisherTests { - private const string HealthReportMetricName = @"R9\HealthCheck\Report"; - private const string UnhealthyHealthCheckMetricName = @"R9\HealthCheck\UnhealthyHealthCheck"; + private const string HealthReportMetricName = "health_check.reports"; + private const string UnhealthyHealthCheckMetricName = "health_check.unhealthy_checks"; - public static TheoryData, bool, int, string, LogLevel, string, string> PublishAsyncArgs => new() + public static TheoryData, bool, int, string, LogLevel, string> PublishAsyncArgs => new() { { new List { HealthStatus.Healthy }, @@ -28,7 +28,6 @@ public class TelemetryHealthChecksPublisherTests 1, "Process reporting healthy: Healthy.", LogLevel.Debug, - bool.TrueString, HealthStatus.Healthy.ToString() }, { @@ -37,7 +36,6 @@ public class TelemetryHealthChecksPublisherTests 1, "Process reporting unhealthy: Degraded. Health check entries are id0: {status: Degraded, description: desc0}", LogLevel.Warning, - bool.FalseString, HealthStatus.Degraded.ToString() }, { @@ -46,7 +44,6 @@ public class TelemetryHealthChecksPublisherTests 1, "Process reporting unhealthy: Unhealthy. Health check entries are id0: {status: Unhealthy, description: desc0}", LogLevel.Warning, - bool.FalseString, HealthStatus.Unhealthy.ToString() }, { @@ -55,7 +52,6 @@ public class TelemetryHealthChecksPublisherTests 0, "Process reporting healthy: Healthy.", LogLevel.Debug, - bool.TrueString, HealthStatus.Healthy.ToString() }, { @@ -64,7 +60,6 @@ public class TelemetryHealthChecksPublisherTests 1, "Process reporting unhealthy: Unhealthy. Health check entries are id0: {status: Healthy, description: desc0}, id1: {status: Unhealthy, description: desc1}", LogLevel.Warning, - bool.FalseString, HealthStatus.Unhealthy.ToString() }, { @@ -74,7 +69,6 @@ public class TelemetryHealthChecksPublisherTests "Process reporting unhealthy: Unhealthy. Health check entries are " + "id0: {status: Healthy, description: desc0}, id1: {status: Degraded, description: desc1}, id2: {status: Unhealthy, description: desc2}", LogLevel.Warning, - bool.FalseString, HealthStatus.Unhealthy.ToString() }, }; @@ -87,7 +81,6 @@ public async Task PublishAsync( int expectedLogCount, string expectedLogMessage, LogLevel expectedLogLevel, - string expectedMetricHealthy, string expectedMetricStatus) { using var meter = new Meter(nameof(PublishAsync)); @@ -116,8 +109,7 @@ public async Task PublishAsync( var latest = healthyMetricCollector.LastMeasurement!; latest.Value.Should().Be(1); - latest.Tags["healthy"].Should().Be(expectedMetricHealthy); - latest.Tags["status"].Should().Be(expectedMetricStatus); + latest.Tags["health.status"].Should().Be(expectedMetricStatus); var unhealthyCounters = unhealthyMetricCollector.GetMeasurementSnapshot(); @@ -145,8 +137,8 @@ private static long GetValue(IReadOnlyCollection> cou { foreach (var counter in counters) { - if (counter!.Tags["name"]?.ToString() == healthy && - counter!.Tags["status"]?.ToString() == status) + if (counter!.Tags["health_check.name"]?.ToString() == healthy && + counter!.Tags["health.status"]?.ToString() == status) { return counter.Value; } From 717678ccddd9a7c2d9ebc26dec339a3478dda4b8 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Fri, 6 Oct 2023 15:50:32 +0200 Subject: [PATCH 13/24] minor fix --- .../TelemetryHealthCheckPublisher.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs index 133258997bc..16bbfc97c6e 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/TelemetryHealthCheckPublisher.cs @@ -49,8 +49,6 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke { Log.Healthy(_logger, report.Status); } - - _metrics.HealthCheckReportCounter.RecordMetric(report.Status); } else { @@ -79,10 +77,10 @@ public Task PublishAsync(HealthReport report, CancellationToken cancellationToke Log.Unhealthy(_logger, report.Status, stringBuilder); PoolFactory.SharedStringBuilderPool.Return(stringBuilder); - - _metrics.HealthCheckReportCounter.RecordMetric(report.Status); } + _metrics.HealthCheckReportCounter.RecordMetric(report.Status); + return Task.CompletedTask; } } From bca9575f5c83e16d21c59591ca7aede3e0864d23 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Mon, 9 Oct 2023 13:48:38 +0200 Subject: [PATCH 14/24] Update src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsSnapshotProvider.cs --- .../Windows/WindowsSnapshotProvider.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsSnapshotProvider.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsSnapshotProvider.cs index 691127d351a..97cd645a946 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsSnapshotProvider.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsSnapshotProvider.cs @@ -33,6 +33,6 @@ public Snapshot GetSnapshot() TimeSpan.FromTicks(TimeProvider.GetUtcNow().Ticks), TimeSpan.FromTicks(process.PrivilegedProcessorTime.Ticks), TimeSpan.FromTicks(process.UserProcessorTime.Ticks), - (ulong)process.VirtualMemorySize64); + (ulong)process.WorkingSet64); } } From 18870752be96ada23e3a25cdcbb11bab539838b9 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Mon, 9 Oct 2023 14:20:16 +0200 Subject: [PATCH 15/24] CR (Reiley) --- .../Windows/WindowsCounters.cs | 129 ++++++++---------- 1 file changed, 54 insertions(+), 75 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs index 024aed2a372..49ea53f66c6 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs @@ -12,7 +12,8 @@ internal sealed class WindowsCounters public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) { const string NetworkStateKey = "system.network.state"; - const string GaugeName = "process.network.connections"; + const string InstrumentName = "process.network.connections"; + #pragma warning disable CA2000 // Dispose objects before losing scope // We don't dispose the meter because IMeterFactory handles that // An issue on analyzer side: https://github.com/dotnet/roslyn-analyzers/issues/6912 @@ -26,12 +27,12 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) var tcpVersionFourTag = new KeyValuePair("network.type", "ipv4"); var tcpVersionSixTag = new KeyValuePair("network.type", "ipv6"); - // TODO: these are heavily rewritten to align with + // These metrics are aligned with // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/system-metrics.md#metric-systemnetworkconnections - // All these should be of UpDownCounter type - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_closed_count", - GaugeName, + + // IPv4: + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -41,9 +42,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "closed") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_listen_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -53,9 +53,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "listen") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_syn_sent_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -65,9 +64,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "syn_sent") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_syn_received_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -77,9 +75,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "syn_recv") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_established_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -89,9 +86,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "established") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_fin_wait_1_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -101,9 +97,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "fin_wait_1") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_fin_wait_2_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -113,9 +108,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "fin_wait_2") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_close_wait_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -125,9 +119,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "close_wait") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_closing_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -137,9 +130,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "closing") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_last_ack_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -149,9 +141,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "last_ack") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_time_wait_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -161,9 +152,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "time_wait") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv4_connection_delete_tcb_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); @@ -173,9 +163,9 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "delete") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_closed_count", - GaugeName, + // IPv6: + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -185,9 +175,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "close") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_listen_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -197,9 +186,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "listen") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_syn_sent_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -209,9 +197,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "syn_sent") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_syn_received_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -221,9 +208,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "syn_recv") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_established_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -233,9 +219,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "established") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_fin_wait_1_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -245,9 +230,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "fin_wait_1") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_fin_wait_2_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -257,9 +241,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "fin_wait_2") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_close_wait_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -269,9 +252,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "close_wait") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_closing_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -281,9 +263,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "closing") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_last_ack_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -293,9 +274,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "last_ack") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_time_wait_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); @@ -305,9 +285,8 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) description: null, tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "time_wait") }); - _ = meter.CreateObservableGauge( - //"process.network.tcp.ipv6_connection_delete_tcb_count", - GaugeName, + _ = meter.CreateObservableUpDownCounter( + InstrumentName, () => { var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); From 43a73feedb58f689e36d4c4f4ca0bd2e57ccbc89 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Tue, 10 Oct 2023 12:36:11 +0200 Subject: [PATCH 16/24] CR (James) --- .../Windows/WindowsCounters.cs | 312 +++--------------- .../Resilience/Internal/ResilienceTagNames.cs | 10 +- 2 files changed, 54 insertions(+), 268 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs index 49ea53f66c6..0b37abb126f 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Collections.Generic; +using System.Diagnostics; using System.Diagnostics.Metrics; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Network; @@ -9,10 +10,11 @@ namespace Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows; internal sealed class WindowsCounters { + private readonly TcpTableInfo _tcpTableInfo; + public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) { - const string NetworkStateKey = "system.network.state"; - const string InstrumentName = "process.network.connections"; + _tcpTableInfo = tcpTableInfo; #pragma warning disable CA2000 // Dispose objects before losing scope // We don't dispose the meter because IMeterFactory handles that @@ -22,278 +24,62 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) #pragma warning restore CA2000 // Dispose objects before losing scope var tcpTag = new KeyValuePair("network.transport", "tcp"); + var commonTags = new TagList + { + tcpTag + }; - // These are covered in https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-metrics.md#attributes: - var tcpVersionFourTag = new KeyValuePair("network.type", "ipv4"); - var tcpVersionSixTag = new KeyValuePair("network.type", "ipv6"); - - // These metrics are aligned with + // The metric is aligned with // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/system-metrics.md#metric-systemnetworkconnections - // IPv4: - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.ClosedCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "closed") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.ListenCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "listen") }); - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.SynSentCount; - }, + "process.network.connections", + GetMeasurements, unit: "{connection}", description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "syn_sent") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.SynRcvdCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "syn_recv") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.EstabCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "established") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.FinWait1Count; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "fin_wait_1") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.FinWait2Count; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "fin_wait_2") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.CloseWaitCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "close_wait") }); + tags: commonTags); + } - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.ClosingCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "closing") }); + private IEnumerable> GetMeasurements() + { + const string NetworkStateKey = "system.network.state"; - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.LastAckCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "last_ack") }); + // These are covered in https://github.com/open-telemetry/semantic-conventions/blob/main/docs/rpc/rpc-metrics.md#attributes: + var tcpVersionFourTag = new KeyValuePair("network.type", "ipv4"); + var tcpVersionSixTag = new KeyValuePair("network.type", "ipv6"); - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.TimeWaitCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "time_wait") }); + var measurements = new List>(24); - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv4CachingSnapshot(); - return snapshot.DeleteTcbCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionFourTag, new(NetworkStateKey, "delete") }); + // IPv4: + var snapshotV4 = _tcpTableInfo.GetIPv4CachingSnapshot(); + measurements.Add(new Measurement(snapshotV4.ClosedCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "closed") })); + measurements.Add(new Measurement(snapshotV4.ListenCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "listen") })); + measurements.Add(new Measurement(snapshotV4.SynSentCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "syn_sent") })); + measurements.Add(new Measurement(snapshotV4.SynRcvdCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "syn_recv") })); + measurements.Add(new Measurement(snapshotV4.EstabCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "established") })); + measurements.Add(new Measurement(snapshotV4.FinWait1Count, new TagList { tcpVersionFourTag, new(NetworkStateKey, "fin_wait_1") })); + measurements.Add(new Measurement(snapshotV4.FinWait2Count, new TagList { tcpVersionFourTag, new(NetworkStateKey, "fin_wait_2") })); + measurements.Add(new Measurement(snapshotV4.CloseWaitCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "close_wait") })); + measurements.Add(new Measurement(snapshotV4.ClosingCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "closing") })); + measurements.Add(new Measurement(snapshotV4.LastAckCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "last_ack") })); + measurements.Add(new Measurement(snapshotV4.TimeWaitCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "time_wait") })); + measurements.Add(new Measurement(snapshotV4.DeleteTcbCount, new TagList { tcpVersionFourTag, new(NetworkStateKey, "delete") })); // IPv6: - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.ClosedCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "close") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.ListenCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "listen") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.SynSentCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "syn_sent") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.SynRcvdCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "syn_recv") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.EstabCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "established") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.FinWait1Count; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "fin_wait_1") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.FinWait2Count; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "fin_wait_2") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.CloseWaitCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "close_wait") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.ClosingCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "closing") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.LastAckCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "last_ack") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.TimeWaitCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "time_wait") }); - - _ = meter.CreateObservableUpDownCounter( - InstrumentName, - () => - { - var snapshot = tcpTableInfo.GetIPv6CachingSnapshot(); - return snapshot.DeleteTcbCount; - }, - unit: "{connection}", - description: null, - tags: new[] { tcpTag, tcpVersionSixTag, new(NetworkStateKey, "delete") }); + var snapshotV6 = _tcpTableInfo.GetIPv6CachingSnapshot(); + measurements.Add(new Measurement(snapshotV6.ClosedCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "closed") })); + measurements.Add(new Measurement(snapshotV6.ListenCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "listen") })); + measurements.Add(new Measurement(snapshotV6.SynSentCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "syn_sent") })); + measurements.Add(new Measurement(snapshotV6.SynRcvdCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "syn_recv") })); + measurements.Add(new Measurement(snapshotV6.EstabCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "established") })); + measurements.Add(new Measurement(snapshotV6.FinWait1Count, new TagList { tcpVersionSixTag, new(NetworkStateKey, "fin_wait_1") })); + measurements.Add(new Measurement(snapshotV6.FinWait2Count, new TagList { tcpVersionSixTag, new(NetworkStateKey, "fin_wait_2") })); + measurements.Add(new Measurement(snapshotV6.CloseWaitCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "close_wait") })); + measurements.Add(new Measurement(snapshotV6.ClosingCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "closing") })); + measurements.Add(new Measurement(snapshotV6.LastAckCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "last_ack") })); + measurements.Add(new Measurement(snapshotV6.TimeWaitCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "time_wait") })); + measurements.Add(new Measurement(snapshotV6.DeleteTcbCount, new TagList { tcpVersionSixTag, new(NetworkStateKey, "delete") })); + + return measurements; } } diff --git a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs index 460138a5606..c7adcce3cd5 100644 --- a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs +++ b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs @@ -5,13 +5,13 @@ namespace Microsoft.Extensions.Resilience.Internal; internal static class ResilienceTagNames { - public const string FailureSource = "failure.source"; + public const string FailureSource = "resilience.failure.source"; - public const string FailureReason = "failure.reason"; + public const string FailureReason = "resilience.failure.reason"; - public const string FailureSummary = "failure.summary"; + public const string FailureSummary = "resilience.failure.summary"; - public const string DependencyName = "dependency.name"; + public const string DependencyName = "resilience.dependency.name"; - public const string RequestName = "request.name"; + public const string RequestName = "resilience.request.name"; } From e10ccda2cd2b07d28f8b113105e9419349c9c244 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Tue, 10 Oct 2023 13:00:45 +0200 Subject: [PATCH 17/24] fixes in tests --- .../Windows/WindowsCountersTests.cs | 56 ++----------------- .../ResilienceMetricsEnricherTests.cs | 26 ++++----- 2 files changed, 19 insertions(+), 63 deletions(-) diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsCountersTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsCountersTests.cs index 09948f43f38..b6867d74df1 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsCountersTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsCountersTests.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Diagnostics.Metrics; -using System.Linq; using FluentAssertions; using Microsoft.Extensions.Diagnostics.ResourceMonitoring.Windows.Network; using Moq; @@ -54,54 +53,8 @@ public void WindowsCounters_Registers_Instruments() listener.Start(); listener.RecordObservableInstruments(); samples.Count.Should().Be(24); - samples.First().instrument.Name.Should().Be("ipv4_tcp_connection_closed_count"); - samples.First().value.Should().Be(1); - samples.Skip(1).First().instrument.Name.Should().Be("ipv4_tcp_connection_listen_count"); - samples.Skip(1).First().value.Should().Be(1); - samples.Skip(2).First().instrument.Name.Should().Be("ipv4_tcp_connection_syn_sent_count"); - samples.Skip(2).First().value.Should().Be(1); - samples.Skip(3).First().instrument.Name.Should().Be("ipv4_tcp_connection_syn_received_count"); - samples.Skip(3).First().value.Should().Be(1); - samples.Skip(4).First().instrument.Name.Should().Be("ipv4_tcp_connection_established_count"); - samples.Skip(4).First().value.Should().Be(1); - samples.Skip(5).First().instrument.Name.Should().Be("ipv4_tcp_connection_fin_wait_1_count"); - samples.Skip(5).First().value.Should().Be(1); - samples.Skip(6).First().instrument.Name.Should().Be("ipv4_tcp_connection_fin_wait_2_count"); - samples.Skip(6).First().value.Should().Be(1); - samples.Skip(7).First().instrument.Name.Should().Be("ipv4_tcp_connection_close_wait_count"); - samples.Skip(7).First().value.Should().Be(1); - samples.Skip(8).First().instrument.Name.Should().Be("ipv4_tcp_connection_closing_count"); - samples.Skip(8).First().value.Should().Be(1); - samples.Skip(9).First().instrument.Name.Should().Be("ipv4_tcp_connection_last_ack_count"); - samples.Skip(9).First().value.Should().Be(1); - samples.Skip(10).First().instrument.Name.Should().Be("ipv4_tcp_connection_time_wait_count"); - samples.Skip(10).First().value.Should().Be(1); - samples.Skip(11).First().instrument.Name.Should().Be("ipv4_tcp_connection_delete_tcb_count"); - samples.Skip(11).First().value.Should().Be(1); - samples.Skip(12).First().instrument.Name.Should().Be("ipv6_tcp_connection_closed_count"); - samples.Skip(12).First().value.Should().Be(1); - samples.Skip(13).First().instrument.Name.Should().Be("ipv6_tcp_connection_listen_count"); - samples.Skip(13).First().value.Should().Be(1); - samples.Skip(14).First().instrument.Name.Should().Be("ipv6_tcp_connection_syn_sent_count"); - samples.Skip(14).First().value.Should().Be(1); - samples.Skip(15).First().instrument.Name.Should().Be("ipv6_tcp_connection_syn_received_count"); - samples.Skip(15).First().value.Should().Be(1); - samples.Skip(16).First().instrument.Name.Should().Be("ipv6_tcp_connection_established_count"); - samples.Skip(16).First().value.Should().Be(1); - samples.Skip(17).First().instrument.Name.Should().Be("ipv6_tcp_connection_fin_wait_1_count"); - samples.Skip(17).First().value.Should().Be(1); - samples.Skip(18).First().instrument.Name.Should().Be("ipv6_tcp_connection_fin_wait_2_count"); - samples.Skip(18).First().value.Should().Be(1); - samples.Skip(19).First().instrument.Name.Should().Be("ipv6_tcp_connection_close_wait_count"); - samples.Skip(19).First().value.Should().Be(1); - samples.Skip(20).First().instrument.Name.Should().Be("ipv6_tcp_connection_closing_count"); - samples.Skip(20).First().value.Should().Be(1); - samples.Skip(21).First().instrument.Name.Should().Be("ipv6_tcp_connection_last_ack_count"); - samples.Skip(21).First().value.Should().Be(1); - samples.Skip(22).First().instrument.Name.Should().Be("ipv6_tcp_connection_time_wait_count"); - samples.Skip(22).First().value.Should().Be(1); - samples.Skip(23).First().instrument.Name.Should().Be("ipv6_tcp_connection_delete_tcb_count"); - samples.Skip(23).First().value.Should().Be(1); + samples.Should().AllSatisfy(x => x.instrument.Name.Should().Be("process.network.connections")); + samples.Should().AllSatisfy(x => x.value.Should().Be(1)); } [Fact] @@ -126,7 +79,10 @@ public void WindowsCounters_Got_Unsuccessful() { InstrumentPublished = (instrument, listener) => { - listener.EnableMeasurementEvents(instrument); + if (instrument.Meter == meter) + { + listener.EnableMeasurementEvents(instrument); + } } }; diff --git a/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs index df5c60f0c27..5ff428456ab 100644 --- a/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs +++ b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs @@ -42,9 +42,9 @@ public void AddResilienceEnricher_Exception_EnsureDimensions() CreateSut().Enrich(CreateEnrichmentContext(Outcome.FromException(new InvalidOperationException { Source = "my-source" }))); - Tags["failure-reason"].Should().Be("InvalidOperationException"); - Tags["failure-summary"].Should().Be("type:desc:details"); - Tags["failure-source"].Should().Be("my-source"); + Tags["resilience.failure.reason"].Should().Be("InvalidOperationException"); + Tags["resilience.failure.summary"].Should().Be("type:desc:details"); + Tags["resilience.failure.source"].Should().Be("my-source"); } [Fact] @@ -54,9 +54,9 @@ public void AddResilienceEnricher_ExceptionWithNoSummarizer_EnsureNoDimensions() CreateSut().Enrich(CreateEnrichmentContext(Outcome.FromException(new InvalidOperationException { Source = "my-source" }))); - Tags.Should().NotContainKey("failure-reason"); - Tags.Should().NotContainKey("failure-summary"); - Tags.Should().NotContainKey("failure-source"); + Tags.Should().NotContainKey("resilience.failure.reason"); + Tags.Should().NotContainKey("resilience.failure.summary"); + Tags.Should().NotContainKey("resilience.failure.source"); } [Fact] @@ -66,9 +66,9 @@ public void AddResilienceEnricher_Outcome_EnsureDimensions() CreateSut().Enrich(CreateEnrichmentContext(Outcome.FromResult("string-result"))); - Tags["failure-source"].Should().Be("my-source"); - Tags["failure-reason"].Should().Be("my-reason"); - Tags["failure-summary"].Should().Be("string-result"); + Tags["resilience.failure.source"].Should().Be("my-source"); + Tags["resilience.failure.reason"].Should().Be("my-reason"); + Tags["resilience.failure.summary"].Should().Be("string-result"); } [Fact] @@ -78,8 +78,8 @@ public void AddResilienceEnricher_RequestMetadata_EnsureDimensions() Outcome.FromResult("string-result"), context => context.SetRequestMetadata(new RequestMetadata { RequestName = "my-req", DependencyName = "my-dep" }))); - Tags["dep-name"].Should().Be("my-dep"); - Tags["req-name"].Should().Be("my-req"); + Tags["resilience.dependency.name"].Should().Be("my-dep"); + Tags["resilience.request.name"].Should().Be("my-req"); } [Fact] @@ -90,8 +90,8 @@ public void AddResilienceEnricher_RequestMetadataFromOutgoingRequestContext_Ensu CreateSut().Enrich(CreateEnrichmentContext()); - Tags["dep-name"].Should().Be("my-dep"); - Tags["req-name"].Should().Be("my-req"); + Tags["resilience.dependency.name"].Should().Be("my-dep"); + Tags["resilience.request.name"].Should().Be("my-req"); } private EnrichmentContext CreateEnrichmentContext(Outcome? outcome = null, Action? configure = null) From a8af5444d884c53dde49fd7adb0faa4dc8bc6183 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Tue, 10 Oct 2023 14:27:12 +0200 Subject: [PATCH 18/24] fix tests --- .../Linux/LinuxCountersTests.cs | 7 +++++-- ...pClientBuilderExtensionsTests.Resilience.cs | 18 +++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxCountersTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxCountersTests.cs index d4386605c5c..2a0c286d0ea 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxCountersTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Linux/LinuxCountersTests.cs @@ -44,7 +44,10 @@ public void LinuxCounters_Registers_Instruments() { InstrumentPublished = (instrument, listener) => { - listener.EnableMeasurementEvents(instrument); + if (ReferenceEquals(meter, instrument.Meter)) + { + listener.EnableMeasurementEvents(instrument); + } } }; @@ -64,6 +67,6 @@ public void LinuxCounters_Registers_Instruments() Assert.Equal(ResourceUtilizationInstruments.CpuUtilization, samples[0].instrument.Name); Assert.Equal(double.NaN, samples[0].value); Assert.Equal(ResourceUtilizationInstruments.MemoryUtilization, samples[1].instrument.Name); - Assert.Equal(50, samples[1].value); + Assert.Equal(0.5, samples[1].value); } } diff --git a/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs b/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs index bcdd3784c33..5bb514dcbd7 100644 --- a/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs +++ b/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs @@ -71,13 +71,13 @@ public async Task AddResilienceHandler_OnPipelineDisposed_EnsureCalled() context.OnPipelineDisposed(() => onPipelineDisposedCalled = true); }); - var serviceProvider = services.BuildServiceProvider(); - - var client = serviceProvider.GetRequiredService().CreateClient("client"); - using var request = new HttpRequestMessage(HttpMethod.Get, "https://dummy"); + using (var serviceProvider = services.BuildServiceProvider()) + { + var client = serviceProvider.GetRequiredService().CreateClient("client"); + using var request = new HttpRequestMessage(HttpMethod.Get, "https://dummy"); - await client.GetStringAsync("https://dummy"); - serviceProvider.Dispose(); + await client.GetStringAsync("https://dummy"); + } onPipelineDisposedCalled.Should().BeTrue(); } @@ -123,9 +123,9 @@ public async Task AddResilienceHandler_EnsureFailureResultContext() using var response = await client.SendAsync(request); var lookup = enricher.Tags.ToLookup(t => t.Key, t => t.Value); - lookup["failure-reason"].Should().Contain("500"); - lookup["failure-summary"].Should().Contain("InternalServerError"); - lookup["failure-source"].Should().Contain(TelemetryConstants.Unknown); + lookup["resilience.failure.reason"].Should().Contain("500"); + lookup["resilience.failure.summary"].Should().Contain("InternalServerError"); + lookup["resilience.failure.source"].Should().Contain(TelemetryConstants.Unknown); } [Fact] From fc8c3e020bbf4cf729d3a64ba0926489c709a149 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Tue, 17 Oct 2023 20:25:06 +0200 Subject: [PATCH 19/24] CR --- src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs b/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs index b23072fca78..5237c8a528f 100644 --- a/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs +++ b/src/Libraries/Microsoft.AspNetCore.HeaderParsing/Metric.cs @@ -8,9 +8,9 @@ namespace Microsoft.AspNetCore.HeaderParsing; internal static partial class Metric { - [Counter("header.name", "error.type", Name = "aspnetcore.header_parsing.parse_errors")] + [Counter("aspnetcore.header_parsing.header.name", "error.type", Name = "aspnetcore.header_parsing.parse_errors")] public static partial ParsingErrorCounter CreateParsingErrorCounter(Meter meter); - [Counter("header.name", "access.type", Name = "aspnetcore.header_parsing.cache_accesses")] + [Counter("aspnetcore.header_parsing.header.name", "aspnetcore.header_parsing.cache_access.type", Name = "aspnetcore.header_parsing.cache_accesses")] public static partial CacheAccessCounter CreateCacheAccessCounter(Meter meter); } From fac0bb46f55afad0b2b83d888a5a6696d1356433 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Tue, 17 Oct 2023 20:32:36 +0200 Subject: [PATCH 20/24] Update src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs Co-authored-by: Liudmila Molkova --- .../Windows/WindowsCounters.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs index 0b37abb126f..fed46d64795 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/Windows/WindowsCounters.cs @@ -33,7 +33,7 @@ public WindowsCounters(IMeterFactory meterFactory, TcpTableInfo tcpTableInfo) // https://github.com/open-telemetry/semantic-conventions/blob/main/docs/system/system-metrics.md#metric-systemnetworkconnections _ = meter.CreateObservableUpDownCounter( - "process.network.connections", + "system.network.connections", GetMeasurements, unit: "{connection}", description: null, From ddd86c07f58d5529e54b3e15d84ae37120348d5d Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Wed, 18 Oct 2023 16:57:47 +0200 Subject: [PATCH 21/24] CR --- .../Metric.cs | 4 +-- .../ResourceUtilizationInstruments.cs | 2 +- .../Resilience/Internal/ResilienceTagNames.cs | 10 +++---- .../HeaderParsingFeatureTests.cs | 6 ++--- .../TelemetryHealthChecksPublisherTests.cs | 14 +++++----- .../Windows/WindowsCountersTests.cs | 2 +- ...ClientBuilderExtensionsTests.Resilience.cs | 6 ++--- .../ResilienceMetricsEnricherTests.cs | 26 +++++++++---------- 8 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs index 12f5e2ada67..b59531bf859 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common/Metric.cs @@ -11,10 +11,10 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks; internal static partial class Metric { - [Counter("health.status", Name = "health_check.reports")] + [Counter("dotnet.health_check.status", Name = "dotnet.health_check.reports")] public static partial HealthCheckReportCounter CreateHealthCheckReportCounter(Meter meter); - [Counter("health_check.name", "health.status", Name = "health_check.unhealthy_checks")] + [Counter("dotnet.health_check.name", "dotnet.health_check.status", Name = "dotnet.health_check.unhealthy_checks")] public static partial UnhealthyHealthCheckCounter CreateUnhealthyHealthCheckCounter(Meter meter); public static void RecordMetric(this HealthCheckReportCounter counterMetric, HealthStatus status) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationInstruments.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationInstruments.cs index e06984eb13f..da38092353b 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationInstruments.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceUtilizationInstruments.cs @@ -26,5 +26,5 @@ internal static class ResourceUtilizationInstruments /// /// The type of an instrument is . /// - public const string MemoryUtilization = "process.memory.virtual.utilization"; + public const string MemoryUtilization = "dotnet.process.memory.virtual.utilization"; } diff --git a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs index c7adcce3cd5..80c8d8e1dc0 100644 --- a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs +++ b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs @@ -5,13 +5,13 @@ namespace Microsoft.Extensions.Resilience.Internal; internal static class ResilienceTagNames { - public const string FailureSource = "resilience.failure.source"; + public const string FailureSource = "dotnet.resilience.failure.source"; - public const string FailureReason = "resilience.failure.reason"; + public const string FailureReason = "dotnet.resilience.failure.reason"; - public const string FailureSummary = "resilience.failure.summary"; + public const string FailureSummary = "dotnet.resilience.failure.summary"; - public const string DependencyName = "resilience.dependency.name"; + public const string DependencyName = "dotnet.resilience.dependency.name"; - public const string RequestName = "resilience.request.name"; + public const string RequestName = "dotnet.resilience.request.name"; } diff --git a/test/Libraries/Microsoft.AspNetCore.HeaderParsing.Tests/HeaderParsingFeatureTests.cs b/test/Libraries/Microsoft.AspNetCore.HeaderParsing.Tests/HeaderParsingFeatureTests.cs index 7f8c7796da2..ce23cb2dfb0 100644 --- a/test/Libraries/Microsoft.AspNetCore.HeaderParsing.Tests/HeaderParsingFeatureTests.cs +++ b/test/Libraries/Microsoft.AspNetCore.HeaderParsing.Tests/HeaderParsingFeatureTests.cs @@ -150,7 +150,7 @@ public void TryParse_returns_false_on_error() var latest = metricCollector.LastMeasurement; Assert.NotNull(latest); latest.Value.Should().Be(1); - latest.Tags["header.name"].Should().Be("Date"); + latest.Tags["aspnetcore.header_parsing.header.name"].Should().Be("Date"); latest.Tags["error.type"].Should().Be("Unable to parse date time offset value."); } @@ -208,8 +208,8 @@ public void CachingWorks() var latest = metricCollector.LastMeasurement; Assert.NotNull(latest); latest.Value.Should().Be(1); - latest.Tags["header.name"].Should().Be(HeaderNames.CacheControl); - latest.Tags["access.type"].Should().Be("Hit"); + latest.Tags["aspnetcore.header_parsing.header.name"].Should().Be(HeaderNames.CacheControl); + latest.Tags["aspnetcore.header_parsing.cache_access.type"].Should().Be("Hit"); } private static HeaderParsingMetrics GetMockedMetrics(Meter meter) diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common.Tests/TelemetryHealthChecksPublisherTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common.Tests/TelemetryHealthChecksPublisherTests.cs index 70df808eb8d..9bf8fa6f06c 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common.Tests/TelemetryHealthChecksPublisherTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.HealthChecks.Common.Tests/TelemetryHealthChecksPublisherTests.cs @@ -17,8 +17,8 @@ namespace Microsoft.Extensions.Diagnostics.HealthChecks.Test; public class TelemetryHealthChecksPublisherTests { - private const string HealthReportMetricName = "health_check.reports"; - private const string UnhealthyHealthCheckMetricName = "health_check.unhealthy_checks"; + private const string HealthReportMetricName = "dotnet.health_check.reports"; + private const string UnhealthyHealthCheckMetricName = "dotnet.health_check.unhealthy_checks"; public static TheoryData, bool, int, string, LogLevel, string> PublishAsyncArgs => new() { @@ -106,10 +106,12 @@ public async Task PublishAsync( Assert.Equal(expectedLogLevel, collector.LatestRecord.Level); } - var latest = healthyMetricCollector.LastMeasurement!; + var latest = healthyMetricCollector.LastMeasurement; + + Assert.NotNull(latest); latest.Value.Should().Be(1); - latest.Tags["health.status"].Should().Be(expectedMetricStatus); + latest.Tags.Should().ContainKey("dotnet.health_check.status").WhoseValue.Should().Be(expectedMetricStatus); var unhealthyCounters = unhealthyMetricCollector.GetMeasurementSnapshot(); @@ -137,8 +139,8 @@ private static long GetValue(IReadOnlyCollection> cou { foreach (var counter in counters) { - if (counter!.Tags["health_check.name"]?.ToString() == healthy && - counter!.Tags["health.status"]?.ToString() == status) + if (counter!.Tags["dotnet.health_check.name"]?.ToString() == healthy && + counter!.Tags["dotnet.health_check.status"]?.ToString() == status) { return counter.Value; } diff --git a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsCountersTests.cs b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsCountersTests.cs index b6867d74df1..cbd1ecee25c 100644 --- a/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsCountersTests.cs +++ b/test/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring.Tests/Windows/WindowsCountersTests.cs @@ -53,7 +53,7 @@ public void WindowsCounters_Registers_Instruments() listener.Start(); listener.RecordObservableInstruments(); samples.Count.Should().Be(24); - samples.Should().AllSatisfy(x => x.instrument.Name.Should().Be("process.network.connections")); + samples.Should().AllSatisfy(x => x.instrument.Name.Should().Be("system.network.connections")); samples.Should().AllSatisfy(x => x.value.Should().Be(1)); } diff --git a/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs b/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs index 5bb514dcbd7..ea330f9059e 100644 --- a/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs +++ b/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs @@ -123,9 +123,9 @@ public async Task AddResilienceHandler_EnsureFailureResultContext() using var response = await client.SendAsync(request); var lookup = enricher.Tags.ToLookup(t => t.Key, t => t.Value); - lookup["resilience.failure.reason"].Should().Contain("500"); - lookup["resilience.failure.summary"].Should().Contain("InternalServerError"); - lookup["resilience.failure.source"].Should().Contain(TelemetryConstants.Unknown); + lookup["dotnet.resilience.failure.reason"].Should().Contain("500"); + lookup["dotnet.resilience.failure.summary"].Should().Contain("InternalServerError"); + lookup["dotnet.resilience.failure.source"].Should().Contain(TelemetryConstants.Unknown); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs index 5ff428456ab..f206f4d9d2d 100644 --- a/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs +++ b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs @@ -42,9 +42,9 @@ public void AddResilienceEnricher_Exception_EnsureDimensions() CreateSut().Enrich(CreateEnrichmentContext(Outcome.FromException(new InvalidOperationException { Source = "my-source" }))); - Tags["resilience.failure.reason"].Should().Be("InvalidOperationException"); - Tags["resilience.failure.summary"].Should().Be("type:desc:details"); - Tags["resilience.failure.source"].Should().Be("my-source"); + Tags.Should().ContainKey("dotnet.resilience.failure.reason").WhoseValue.Should().Be("InvalidOperationException"); + Tags.Should().ContainKey("dotnet.resilience.failure.summary").WhoseValue.Should().Be("type:desc:details"); + Tags.Should().ContainKey("dotnet.resilience.failure.source").WhoseValue.Should().Be("my-source"); } [Fact] @@ -54,9 +54,9 @@ public void AddResilienceEnricher_ExceptionWithNoSummarizer_EnsureNoDimensions() CreateSut().Enrich(CreateEnrichmentContext(Outcome.FromException(new InvalidOperationException { Source = "my-source" }))); - Tags.Should().NotContainKey("resilience.failure.reason"); - Tags.Should().NotContainKey("resilience.failure.summary"); - Tags.Should().NotContainKey("resilience.failure.source"); + Tags.Should().NotContainKey("dotnet.resilience.failure.reason"); + Tags.Should().NotContainKey("dotnet.resilience.failure.summary"); + Tags.Should().NotContainKey("dotnet.resilience.failure.source"); } [Fact] @@ -66,9 +66,9 @@ public void AddResilienceEnricher_Outcome_EnsureDimensions() CreateSut().Enrich(CreateEnrichmentContext(Outcome.FromResult("string-result"))); - Tags["resilience.failure.source"].Should().Be("my-source"); - Tags["resilience.failure.reason"].Should().Be("my-reason"); - Tags["resilience.failure.summary"].Should().Be("string-result"); + Tags.Should().ContainKey("dotnet.resilience.failure.source").WhoseValue.Should().Be("my-source"); + Tags.Should().ContainKey("dotnet.resilience.failure.reason").WhoseValue.Should().Be("my-reason"); + Tags.Should().ContainKey("dotnet.resilience.failure.summary").WhoseValue.Should().Be("string-result"); } [Fact] @@ -78,8 +78,8 @@ public void AddResilienceEnricher_RequestMetadata_EnsureDimensions() Outcome.FromResult("string-result"), context => context.SetRequestMetadata(new RequestMetadata { RequestName = "my-req", DependencyName = "my-dep" }))); - Tags["resilience.dependency.name"].Should().Be("my-dep"); - Tags["resilience.request.name"].Should().Be("my-req"); + Tags.Should().ContainKey("dotnet.resilience.dependency.name").WhoseValue.Should().Be("my-dep"); + Tags.Should().ContainKey("dotnet.resilience.request.name").WhoseValue.Should().Be("my-req"); } [Fact] @@ -90,8 +90,8 @@ public void AddResilienceEnricher_RequestMetadataFromOutgoingRequestContext_Ensu CreateSut().Enrich(CreateEnrichmentContext()); - Tags["resilience.dependency.name"].Should().Be("my-dep"); - Tags["resilience.request.name"].Should().Be("my-req"); + Tags.Should().ContainKey("dotnet.resilience.dependency.name").WhoseValue.Should().Be("my-dep"); + Tags.Should().ContainKey("dotnet.resilience.request.name").WhoseValue.Should().Be("my-req"); } private EnrichmentContext CreateEnrichmentContext(Outcome? outcome = null, Action? configure = null) From c61c8d330faaf0ca04903e712865cdd282041709 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Mon, 23 Oct 2023 17:06:46 +0200 Subject: [PATCH 22/24] align Resilience attribute names --- .../Internal/ResilienceMetricsEnricher.cs | 8 ++------ .../Resilience/Internal/ResilienceTagNames.cs | 10 +++------- ...ClientBuilderExtensionsTests.Resilience.cs | 8 +++----- .../ResilienceMetricsEnricherTests.cs | 20 +++++++------------ 4 files changed, 15 insertions(+), 31 deletions(-) diff --git a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceMetricsEnricher.cs b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceMetricsEnricher.cs index c0621654715..ee5d9990322 100644 --- a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceMetricsEnricher.cs +++ b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceMetricsEnricher.cs @@ -34,16 +34,12 @@ public override void Enrich(in EnrichmentContext if (_exceptionSummarizer is not null && outcome?.Exception is Exception e) { - context.Tags.Add(new(ResilienceTagNames.FailureSource, e.Source)); - context.Tags.Add(new(ResilienceTagNames.FailureReason, e.GetType().Name)); - context.Tags.Add(new(ResilienceTagNames.FailureSummary, _exceptionSummarizer.Summarize(e).ToString())); + context.Tags.Add(new(ResilienceTagNames.ErrorType, _exceptionSummarizer.Summarize(e).ToString())); } else if (outcome is not null && outcome.Value.Result is object result && _faultFactories.TryGetValue(result.GetType(), out var factory)) { var failureContext = factory(result); - context.Tags.Add(new(ResilienceTagNames.FailureSource, failureContext.FailureSource)); - context.Tags.Add(new(ResilienceTagNames.FailureReason, failureContext.FailureReason)); - context.Tags.Add(new(ResilienceTagNames.FailureSummary, failureContext.AdditionalInformation)); + context.Tags.Add(new(ResilienceTagNames.ErrorType, failureContext.AdditionalInformation)); } if ((context.TelemetryEvent.Context.GetRequestMetadata() ?? _outgoingRequestContext?.RequestMetadata) is RequestMetadata requestMetadata) diff --git a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs index 80c8d8e1dc0..587a044dae9 100644 --- a/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs +++ b/src/Libraries/Microsoft.Extensions.Resilience/Resilience/Internal/ResilienceTagNames.cs @@ -5,13 +5,9 @@ namespace Microsoft.Extensions.Resilience.Internal; internal static class ResilienceTagNames { - public const string FailureSource = "dotnet.resilience.failure.source"; + public const string ErrorType = "error.type"; - public const string FailureReason = "dotnet.resilience.failure.reason"; + public const string DependencyName = "request.dependency.name"; - public const string FailureSummary = "dotnet.resilience.failure.summary"; - - public const string DependencyName = "dotnet.resilience.dependency.name"; - - public const string RequestName = "dotnet.resilience.request.name"; + public const string RequestName = "request.name"; } diff --git a/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs b/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs index ea330f9059e..ebf5f52c117 100644 --- a/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs +++ b/test/Libraries/Microsoft.Extensions.Http.Resilience.Tests/Resilience/HttpClientBuilderExtensionsTests.Resilience.cs @@ -10,7 +10,6 @@ using FluentAssertions; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Diagnostics.Metrics.Testing; -using Microsoft.Extensions.Http.Diagnostics; using Microsoft.Extensions.Http.Resilience.Internal; using Microsoft.Extensions.Http.Resilience.Test.Helpers; using Microsoft.Extensions.Options; @@ -117,15 +116,14 @@ public async Task AddResilienceHandler_EnsureFailureResultContext() options.Retry.Delay = TimeSpan.Zero; }); - var client = services.BuildServiceProvider().GetRequiredService().CreateClient("client"); + using var serviceProvider = services.BuildServiceProvider(); + var client = serviceProvider.GetRequiredService().CreateClient("client"); using var request = new HttpRequestMessage(HttpMethod.Get, "https://dummy"); using var response = await client.SendAsync(request); var lookup = enricher.Tags.ToLookup(t => t.Key, t => t.Value); - lookup["dotnet.resilience.failure.reason"].Should().Contain("500"); - lookup["dotnet.resilience.failure.summary"].Should().Contain("InternalServerError"); - lookup["dotnet.resilience.failure.source"].Should().Contain(TelemetryConstants.Unknown); + lookup["error.type"].Should().Contain("InternalServerError"); } [Fact] diff --git a/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs index f206f4d9d2d..e02ca8b5242 100644 --- a/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs +++ b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/ResilienceMetricsEnricherTests.cs @@ -42,9 +42,7 @@ public void AddResilienceEnricher_Exception_EnsureDimensions() CreateSut().Enrich(CreateEnrichmentContext(Outcome.FromException(new InvalidOperationException { Source = "my-source" }))); - Tags.Should().ContainKey("dotnet.resilience.failure.reason").WhoseValue.Should().Be("InvalidOperationException"); - Tags.Should().ContainKey("dotnet.resilience.failure.summary").WhoseValue.Should().Be("type:desc:details"); - Tags.Should().ContainKey("dotnet.resilience.failure.source").WhoseValue.Should().Be("my-source"); + Tags.Should().ContainKey("error.type").WhoseValue.Should().Be("type:desc:details"); } [Fact] @@ -54,9 +52,7 @@ public void AddResilienceEnricher_ExceptionWithNoSummarizer_EnsureNoDimensions() CreateSut().Enrich(CreateEnrichmentContext(Outcome.FromException(new InvalidOperationException { Source = "my-source" }))); - Tags.Should().NotContainKey("dotnet.resilience.failure.reason"); - Tags.Should().NotContainKey("dotnet.resilience.failure.summary"); - Tags.Should().NotContainKey("dotnet.resilience.failure.source"); + Tags.Should().NotContainKey("error.type"); } [Fact] @@ -66,9 +62,7 @@ public void AddResilienceEnricher_Outcome_EnsureDimensions() CreateSut().Enrich(CreateEnrichmentContext(Outcome.FromResult("string-result"))); - Tags.Should().ContainKey("dotnet.resilience.failure.source").WhoseValue.Should().Be("my-source"); - Tags.Should().ContainKey("dotnet.resilience.failure.reason").WhoseValue.Should().Be("my-reason"); - Tags.Should().ContainKey("dotnet.resilience.failure.summary").WhoseValue.Should().Be("string-result"); + Tags.Should().ContainKey("error.type").WhoseValue.Should().Be("string-result"); } [Fact] @@ -78,8 +72,8 @@ public void AddResilienceEnricher_RequestMetadata_EnsureDimensions() Outcome.FromResult("string-result"), context => context.SetRequestMetadata(new RequestMetadata { RequestName = "my-req", DependencyName = "my-dep" }))); - Tags.Should().ContainKey("dotnet.resilience.dependency.name").WhoseValue.Should().Be("my-dep"); - Tags.Should().ContainKey("dotnet.resilience.request.name").WhoseValue.Should().Be("my-req"); + Tags.Should().ContainKey("request.dependency.name").WhoseValue.Should().Be("my-dep"); + Tags.Should().ContainKey("request.name").WhoseValue.Should().Be("my-req"); } [Fact] @@ -90,8 +84,8 @@ public void AddResilienceEnricher_RequestMetadataFromOutgoingRequestContext_Ensu CreateSut().Enrich(CreateEnrichmentContext()); - Tags.Should().ContainKey("dotnet.resilience.dependency.name").WhoseValue.Should().Be("my-dep"); - Tags.Should().ContainKey("dotnet.resilience.request.name").WhoseValue.Should().Be("my-req"); + Tags.Should().ContainKey("request.dependency.name").WhoseValue.Should().Be("my-dep"); + Tags.Should().ContainKey("request.name").WhoseValue.Should().Be("my-req"); } private EnrichmentContext CreateEnrichmentContext(Outcome? outcome = null, Action? configure = null) From 0d244ba9b307b2b7fc098900cd74ba27609a61b2 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Mon, 23 Oct 2023 19:17:58 +0200 Subject: [PATCH 23/24] fix test coverage --- .../Resilience/FailureResultContextTests.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/FailureResultContextTests.cs diff --git a/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/FailureResultContextTests.cs b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/FailureResultContextTests.cs new file mode 100644 index 00000000000..a280c306c75 --- /dev/null +++ b/test/Libraries/Microsoft.Extensions.Resilience.Tests/Resilience/FailureResultContextTests.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using FluentAssertions; +using Microsoft.Extensions.Http.Diagnostics; +using Xunit; + +namespace Microsoft.Extensions.Resilience.Test.Resilience; + +public class FailureResultContextTests +{ + [Fact] + public void ContextFactory_CreateTheObject() + { + var context = FailureResultContext.Create(); + + context.FailureSource.Should().Be(TelemetryConstants.Unknown); + context.AdditionalInformation.Should().Be(TelemetryConstants.Unknown); + context.FailureReason.Should().Be(TelemetryConstants.Unknown); + } +} From 42ac60ebbaa79024c95aea93784306418e4f5404 Mon Sep 17 00:00:00 2001 From: Nikita Balabaev Date: Mon, 23 Oct 2023 19:35:25 +0200 Subject: [PATCH 24/24] Update src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs --- .../ResourceMonitoringOptions.Linux.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs index 27dc1aa1a15..cb6038826f9 100644 --- a/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs +++ b/src/Libraries/Microsoft.Extensions.Diagnostics.ResourceMonitoring/ResourceMonitoringOptions.Linux.cs @@ -26,7 +26,7 @@ public partial class ResourceMonitoringOptions public TimeSpan CpuConsumptionRefreshInterval { get; set; } = DefaultRefreshInterval; /// - /// Gets or sets the default interval used for refreshing values reported by "process.memory.virtual.utilization" metrics. + /// Gets or sets the default interval used for refreshing values reported by "dotnet.process.memory.virtual.utilization" metrics. /// /// /// The default value is 5 seconds.