From c6e97f43f1cbfaa0d6828a96c86aea0c75bce0ad Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 11 Nov 2026 17:29:22 +0000
Subject: [PATCH 1/2] Initial plan
From 2df6ed717bbfc10061a16de8bc834a76097573d3 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Wed, 11 Nov 2026 17:31:24 +0000
Subject: [PATCH 2/2] Normalize PrometheusHandler line endings
Co-authored-by: brendandburns <5751682+brendandburns@users.noreply.github.com>
---
src/KubernetesClient/PrometheusHandler.cs | 158 +++++++++++-----------
1 file changed, 79 insertions(+), 79 deletions(-)
diff --git a/src/KubernetesClient/PrometheusHandler.cs b/src/KubernetesClient/PrometheusHandler.cs
index 7b7bd5461..c850afb79 100644
--- a/src/KubernetesClient/PrometheusHandler.cs
+++ b/src/KubernetesClient/PrometheusHandler.cs
@@ -1,79 +1,79 @@
-using System.Diagnostics;
-using System.Diagnostics.Metrics;
-using System.Net.Http;
-
-namespace k8s
-{
- ///
- /// Implements legacy Prometheus metrics
- ///
- /// Provided for compatibility for existing usages of PrometheusHandler. It is recommended
- /// to transition to using OpenTelemetry and the default HttpClient metrics.
- ///
- /// Note that the tags/labels are not appropriately named for some metrics. This
- /// incorrect naming is retained to maintain compatibility and won't be fixed on this implementation.
- /// Use OpenTelemetry and the standard HttpClient metrics instead.
- public class PrometheusHandler : DelegatingHandler
- {
- private const string Prefix = "k8s_dotnet";
- private static readonly Meter Meter = new Meter("k8s.dotnet");
-
- private static readonly Counter RequestsSent = Meter.CreateCounter(
- $"{Prefix}_request_total",
- description: "Number of requests sent by this client");
-
- private static readonly Histogram RequestLatency = Meter.CreateHistogram(
- $"{Prefix}_request_latency_seconds", unit: "milliseconds",
- description: "Latency of requests sent by this client");
-
- private static readonly Counter ResponseCodes = Meter.CreateCounter(
- $"{Prefix}_response_code_total",
- description: "Number of response codes received by the client");
-
- private static readonly UpDownCounter ActiveRequests =
- Meter.CreateUpDownCounter(
- $"{Prefix}_active_requests",
- description: "Number of requests currently in progress");
-
- ///
- protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
- {
- if (request == null)
- {
- throw new ArgumentNullException(nameof(request));
- }
-
- var digest = KubernetesRequestDigest.Parse(request);
- var timer = Stopwatch.StartNew();
- // Note that this is a tag called "method" but the value is the Verb.
- // This is incorrect, but existing behavior.
- var methodWithVerbValue = new KeyValuePair("method", digest.Verb);
- try
- {
- ActiveRequests.Add(1, methodWithVerbValue);
- RequestsSent.Add(1, methodWithVerbValue);
-
- var resp = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
- ResponseCodes.Add(
- 1,
- new KeyValuePair("method", request.Method.ToString()),
- new KeyValuePair("code", (int)resp.StatusCode));
- return resp;
- }
- finally
- {
- timer.Stop();
- ActiveRequests.Add(-1, methodWithVerbValue);
- var tags = new TagList
- {
- { "verb", digest.Verb },
- { "group", digest.ApiGroup },
- { "version", digest.ApiVersion },
- { "kind", digest.Kind },
- }
- ;
- RequestLatency.Record(timer.Elapsed.TotalMilliseconds, tags);
- }
- }
- }
-}
+using System.Diagnostics;
+using System.Diagnostics.Metrics;
+using System.Net.Http;
+
+namespace k8s
+{
+ ///
+ /// Implements legacy Prometheus metrics
+ ///
+ /// Provided for compatibility for existing usages of PrometheusHandler. It is recommended
+ /// to transition to using OpenTelemetry and the default HttpClient metrics.
+ ///
+ /// Note that the tags/labels are not appropriately named for some metrics. This
+ /// incorrect naming is retained to maintain compatibility and won't be fixed on this implementation.
+ /// Use OpenTelemetry and the standard HttpClient metrics instead.
+ public class PrometheusHandler : DelegatingHandler
+ {
+ private const string Prefix = "k8s_dotnet";
+ private static readonly Meter Meter = new Meter("k8s.dotnet");
+
+ private static readonly Counter RequestsSent = Meter.CreateCounter(
+ $"{Prefix}_request_total",
+ description: "Number of requests sent by this client");
+
+ private static readonly Histogram RequestLatency = Meter.CreateHistogram(
+ $"{Prefix}_request_latency_seconds", unit: "milliseconds",
+ description: "Latency of requests sent by this client");
+
+ private static readonly Counter ResponseCodes = Meter.CreateCounter(
+ $"{Prefix}_response_code_total",
+ description: "Number of response codes received by the client");
+
+ private static readonly UpDownCounter ActiveRequests =
+ Meter.CreateUpDownCounter(
+ $"{Prefix}_active_requests",
+ description: "Number of requests currently in progress");
+
+ ///
+ protected override async Task SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
+ {
+ if (request == null)
+ {
+ throw new ArgumentNullException(nameof(request));
+ }
+
+ var digest = KubernetesRequestDigest.Parse(request);
+ var timer = Stopwatch.StartNew();
+ // Note that this is a tag called "method" but the value is the Verb.
+ // This is incorrect, but existing behavior.
+ var methodWithVerbValue = new KeyValuePair("method", digest.Verb);
+ try
+ {
+ ActiveRequests.Add(1, methodWithVerbValue);
+ RequestsSent.Add(1, methodWithVerbValue);
+
+ var resp = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
+ ResponseCodes.Add(
+ 1,
+ new KeyValuePair("method", request.Method.ToString()),
+ new KeyValuePair("code", (int)resp.StatusCode));
+ return resp;
+ }
+ finally
+ {
+ timer.Stop();
+ ActiveRequests.Add(-1, methodWithVerbValue);
+ var tags = new TagList
+ {
+ { "verb", digest.Verb },
+ { "group", digest.ApiGroup },
+ { "version", digest.ApiVersion },
+ { "kind", digest.Kind },
+ }
+ ;
+ RequestLatency.Record(timer.Elapsed.TotalMilliseconds, tags);
+ }
+ }
+ }
+}