Skip to content

Commit

Permalink
fix: prometheus endpoint mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Apr 14, 2024
1 parent 8a6893d commit 8eabce1
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/GZCTF/Extensions/TelemetryExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ public static void UseTelemetry(this IApplicationBuilder app, TelemetryConfig? c
if (config.Prometheus.Port is { } port)
app.UseOpenTelemetryPrometheusScrapingEndpoint(context =>
{
if (context.Connection.LocalPort == port)
if (context.Connection.LocalPort == port
&& string.Equals(
context.Request.Path.ToString().TrimEnd('/'),
"/metrics",
StringComparison.OrdinalIgnoreCase))
{
// FIXME: workaround for prometheus
context.Request.Headers.Accept = "application/openmetrics-text";
Expand All @@ -86,9 +90,17 @@ public static void UseTelemetry(this IApplicationBuilder app, TelemetryConfig? c
else
app.UseOpenTelemetryPrometheusScrapingEndpoint(context =>
{
// FIXME: workaround for prometheus
context.Request.Headers.Accept = "application/openmetrics-text";
return true;
if (string.Equals(
context.Request.Path.ToString().TrimEnd('/'),
"/metrics",
StringComparison.OrdinalIgnoreCase))
{
// FIXME: workaround for prometheus
context.Request.Headers.Accept = "application/openmetrics-text";
return true;
}

return false;
});
}
}

0 comments on commit 8eabce1

Please sign in to comment.