Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ Notes](../../RELEASENOTES.md).
blocks, which could stall concurrent scrapes being waited on.
([#7571](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7571))

* Fixed metric values and histogram bucket bounds being written with 17
significant digits instead of their shortest round-trippable representation.
([#7589](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7589))

* Fixed the canonical representation used for histogram `le` and summary
`quantile` label values falling back to 17 significant digits incorrectly.
([#7589](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7589))

## 1.17.0-beta.1

Released 2026-Jul-16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ Notes](../../RELEASENOTES.md).
processing loop to stop, and no longer throws if the loop faulted.
([#7587](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7587))

* Fixed metric values and histogram bucket bounds being written with 17
significant digits instead of their shortest round-trippable representation.
([#7589](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7589))

* Fixed the canonical representation used for histogram `le` and summary
`quantile` label values falling back to 17 significant digits incorrectly.
([#7589](https://github.com/open-telemetry/opentelemetry-dotnet/pull/7589))

## 1.17.0-beta.1

Released 2026-Jul-16
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,40 @@ public async Task Prometheus_Can_Scrape_Metrics(string scrapeProtocol) => await
}

Assert.ProperSuperset(expectedSeries, actualSeries);

// Verify that the histogram bucket boundaries round-trip correctly through the Prometheus text formats.
// See https://github.com/open-telemetry/opentelemetry-dotnet/discussions/7585.
var durationBuckets = usesUtf8Names
? "http.server.request.duration_seconds_bucket"
: "http_server_request_duration_seconds_bucket";

string[] expectedBounds =
[
"+Inf",
"0.005",
"0.01",
"0.025",
"0.05",
"0.075",
"0.1",
"0.25",
"0.5",
"0.75",
"1.0",
"10.0",
"2.5",
"5.0",
"7.5",
];
Comment thread
martincostello marked this conversation as resolved.
Resolved

var actualBounds = await WaitForLabelValuesAsync(
prometheusBaseAddress,
durationBuckets,
"le",
outputHelper,
cts.Token);

Assert.Equal(expectedBounds, actualBounds);
}
finally
{
Expand Down Expand Up @@ -344,6 +378,64 @@ static async Task<HashSet<string>> WaitForMetricsSeriesAsync(
return [];
}

static async Task<string[]> WaitForLabelValuesAsync(
Uri baseAddress,
string metricName,
string labelName,
ITestOutputHelper outputHelper,
CancellationToken cancellationToken)
{
// See https://prometheus.io/docs/prometheus/latest/querying/api/#querying-label-values
var valuesUrl = QueryHelpers.AddQueryString(
$"/api/v1/label/{labelName}/values",
[
KeyValuePair.Create<string, string?>("limit", "0"),
KeyValuePair.Create<string, string?>("match[]", $"{{__name__=\"{metricName}\"}}"),
]);

var valuesUri = new Uri(valuesUrl, UriKind.Relative);

var frequency = TimeSpan.FromMilliseconds(250);

using var client = new HttpClient() { BaseAddress = baseAddress };

while (!cancellationToken.IsCancellationRequested)
{
try
{
using var values = await client.GetFromJsonAsync<JsonDocument>(valuesUri, cancellationToken);

if (values!.RootElement.ValueKind is JsonValueKind.Object &&
values.RootElement.TryGetProperty("status", out var status) &&
status.GetString() == "success")
{
var data = values.RootElement.GetProperty("data");

if (data.GetArrayLength() > 0)
{
return [.. data.EnumerateArray().Select((p) => p.GetString()!)];
}
}
}
catch (Exception ex)
{
outputHelper.WriteLine($"[prometheus] Exception while waiting for label values: {ex}");
}

try
{
await Task.Delay(frequency, cancellationToken);
}
catch (TaskCanceledException)
{
break;
}
}

Assert.Fail($"Timed out waiting for the '{labelName}' label values of the '{metricName}' metric.");
return [];
}

static async Task WaitForServiceDiscoveryAsync(
Uri baseAddress,
ITestOutputHelper outputHelper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,29 @@ public Property WriteLongMatchesReferenceImplementation() => Prop.ForAll(
static (value) => SerializeLong(value).SequenceEqual(ReferenceWriteLong(value)));

[Property(MaxTest = MaxTests)]
public Property WriteDoubleMatchesReferenceImplementation() => Prop.ForAll(
public Property WriteDoubleRoundTripsWithoutPadding() => Prop.ForAll(
Generators.DoubleArbitrary(),
static (value) => SerializeDouble(value).SequenceEqual(ReferenceWriteDouble(value)));
static (value) =>
{
var written = Encoding.UTF8.GetString(SerializeDouble(value));

if (double.IsNaN(value))
{
return written == "NaN";
}
else if (double.IsPositiveInfinity(value))
{
return written == "+Inf";
}
else if (double.IsNegativeInfinity(value))
{
return written == "-Inf";
}

return double.TryParse(written, NumberStyles.Float, CultureInfo.InvariantCulture, out var parsed)
&& parsed.Equals(value)
&& written.Length <= value.ToString("G17", CultureInfo.InvariantCulture).Length;
});

[Property(MaxTest = MaxTests)]
public Property EscapeNameWithDotsMatchesReferenceImplementation() => Prop.ForAll(
Expand Down Expand Up @@ -207,14 +227,6 @@ c is (>= 'A' and <= 'Z') or

private static byte[] ReferenceWriteLong(long value) => Encoding.UTF8.GetBytes(value.ToString(CultureInfo.InvariantCulture));

private static byte[] ReferenceWriteDouble(double value) => value switch
{
var doubleValue when double.IsPositiveInfinity(doubleValue) => Encoding.UTF8.GetBytes("+Inf"),
var doubleValue when double.IsNegativeInfinity(doubleValue) => Encoding.UTF8.GetBytes("-Inf"),
var doubleValue when double.IsNaN(doubleValue) => Encoding.UTF8.GetBytes("NaN"),
_ => Encoding.UTF8.GetBytes(value.ToString("G17", CultureInfo.InvariantCulture)),
};

// An independent re-implementation of the dots and values escaping schemes used to validate
// PrometheusEscaping.EscapeName. It deliberately uses different mechanisms (manual surrogate
// decoding, a StringBuilder, and int.ToString("x")) than the production code.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ public async Task Can_Scrape_Prometheus(string accept)
histogram.Name,
new ExplicitBucketHistogramConfiguration
{
Boundaries = [5, 10],
// Boundaries which exercise every shape a bucket bound can be rendered
// with: fixed-point, and both negative and positive scientific notation.
Boundaries = [1.5e-05, 0.005, 5, 10, 1e6],
ExemplarReservoirFactory = () => new SimpleFixedSizeExemplarReservoir(3),
TagKeys = [KeepTag],
})
Expand Down
Loading