Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
<Compile Include="$(RepoRoot)\src\Shared\CharExtensions.cs" Link="Includes\CharExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" />
<Compile Include="$(RepoRoot)\src\Shared\Guard.cs" Link="Includes\Guard.cs" />
<Compile Include="$(RepoRoot)\src\Shared\Shims\Lock.cs" Link="Includes\Shims\Lock.cs" />
<Compile Include="$(RepoRoot)\src\Shared\Shims\NullableAttributes.cs" Link="Includes\Shims\NullableAttributes.cs" />
<Compile Include="$(RepoRoot)\src\Shared\StopwatchExtensions.cs" Link="Includes\StopwatchExtensions.cs" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ public async Task InvokeAsync(HttpContext httpContext)

var protocol = Negotiate(requestHeaders);

var collectionResponse = await this.exporter.CollectionManager.EnterCollect(protocol.IsOpenMetrics);
var collectionResponse = await this.exporter.CollectionManager.EnterCollect(protocol);

try
{
linkedCts.Token.ThrowIfCancellationRequested();

var dataView = protocol.IsOpenMetrics ? collectionResponse.OpenMetricsView : collectionResponse.PlainTextView;
var dataView = collectionResponse.View;

response.StatusCode = StatusCodes.Status200OK;

Expand Down Expand Up @@ -116,7 +116,7 @@ public async Task InvokeAsync(HttpContext httpContext)
}
finally
{
this.exporter.CollectionManager.ExitCollect();
this.exporter.CollectionManager.ExitCollect(protocol);
}
}
catch (Exception ex)
Expand Down Expand Up @@ -272,7 +272,7 @@ private static bool TryParse(
if (version is null)
{
// Use the oldest version if no version preference was specified
version = isOpenMetrics ? PrometheusProtocol.OpenMetricsV0 : PrometheusProtocol.PrometheusVersion0;
version = isOpenMetrics ? PrometheusProtocol.OpenMetricsV0 : PrometheusProtocol.PrometheusV0;
}
else if (version.Major is not > 0)
{
Expand All @@ -286,6 +286,9 @@ private static bool TryParse(
}

protocol = new(mediaType, escaping, version, isOpenMetrics);

protocol.Value.Validate();

return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ internal static PrometheusProtocol Negotiate(string? contentType)
if (version is null)
{
// Use the oldest version if no version preference was specified
version = isOpenMetrics ? PrometheusProtocol.OpenMetricsV0 : PrometheusProtocol.PrometheusVersion0;
version = isOpenMetrics ? PrometheusProtocol.OpenMetricsV0 : PrometheusProtocol.PrometheusV0;
}
else if (version.Major is not > 0)
{
Expand All @@ -138,6 +138,8 @@ internal static PrometheusProtocol Negotiate(string? contentType)
version,
isOpenMetrics);

protocol.Validate();

preferences.Add((protocol, quality));
}

Expand Down
Loading
Loading