Skip to content

Commit

Permalink
[release/8.0] Update Diagnostics shipped version (#5990)
Browse files Browse the repository at this point in the history
* Update Diagnostics shipped version

* Fixup api

* Fixup more tests

* PR feedback
  • Loading branch information
wiktork authored Feb 6, 2024
1 parent 9b1e979 commit 01acd6a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion eng/dependabot/nuget.org/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<!-- Import references updated by Dependabot. -->
<PropertyGroup>
<!-- dotnet/diagnostics references -->
<MicrosoftDiagnosticsMonitoringShippedVersion>8.0.452401</MicrosoftDiagnosticsMonitoringShippedVersion>
<MicrosoftDiagnosticsMonitoringShippedVersion>8.0.510501</MicrosoftDiagnosticsMonitoringShippedVersion>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected override async Task SerializeAsync(ICounterPayload counter)
}
else if (counter is CounterEndedPayload)
{
Logger.CounterEndedPayload(counter.Name);
Logger.CounterEndedPayload(counter.CounterMetadata.CounterName);
return;
}
else if (!counter.EventType.IsValuePublishedEvent())
Expand All @@ -70,12 +70,12 @@ protected override async Task SerializeAsync(ICounterPayload counter)
Quantile quantile = aggregatePercentilePayload.Quantiles[i];

SerializeCounterValues(counter.Timestamp,
counter.Provider,
counter.Name,
counter.CounterMetadata.ProviderName,
counter.CounterMetadata.CounterName,
counter.DisplayName,
counter.Unit,
counter.CounterType.ToString(),
CounterUtilities.AppendPercentile(counter.Metadata, quantile.Percentage),
CounterUtilities.AppendPercentile(counter.ValueTags, quantile.Percentage),
quantile.Value);

if (i < aggregatePercentilePayload.Quantiles.Length - 1)
Expand All @@ -90,12 +90,12 @@ protected override async Task SerializeAsync(ICounterPayload counter)
_bufferWriter.Clear();

SerializeCounterValues(counter.Timestamp,
counter.Provider,
counter.Name,
counter.CounterMetadata.ProviderName,
counter.CounterMetadata.CounterName,
counter.DisplayName,
counter.Unit,
counter.CounterType.ToString(),
counter.Metadata,
counter.ValueTags,
counter.Value);
}
await _stream.WriteAsync(_bufferWriter.WrittenMemory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public MetricKey(ICounterPayload metric)
public override int GetHashCode()
{
HashCode code = new HashCode();
code.Add(_metric.Provider);
code.Add(_metric.Name);
code.Add(_metric.CounterMetadata.ProviderName);
code.Add(_metric.CounterMetadata.CounterName);
return code.ToHashCode();
}

Expand Down Expand Up @@ -73,9 +73,9 @@ public void AddMetric(ICounterPayload metric)
//Do not accept CounterEnded payloads.
if (metric is CounterEndedPayload counterEnded)
{
if (_observedEndedCounters.Add((counterEnded.Provider, counterEnded.Name)))
if (_observedEndedCounters.Add((counterEnded.CounterMetadata.ProviderName, counterEnded.CounterMetadata.CounterName)))
{
_logger.CounterEndedPayload(counterEnded.Name);
_logger.CounterEndedPayload(counterEnded.CounterMetadata.CounterName);
}
return;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ public async Task SnapshotMetrics(Stream outputStream, CancellationToken token)
{
ICounterPayload metricInfo = metricGroup.Value.First();

string metricName = PrometheusDataModel.GetPrometheusNormalizedName(metricInfo.Provider, metricInfo.Name, metricInfo.Unit);
string metricName = PrometheusDataModel.GetPrometheusNormalizedName(metricInfo.CounterMetadata.ProviderName, metricInfo.CounterMetadata.CounterName, metricInfo.Unit);

await WriteMetricHeader(metricInfo, writer, metricName);

Expand Down Expand Up @@ -165,7 +165,7 @@ public async Task SnapshotMetrics(Stream outputStream, CancellationToken token)

private static string GetMetricLabels(ICounterPayload metric, double? quantile)
{
string metadata = metric.Metadata;
string metadata = metric.ValueTags;

char separator = IsMeter(metric) ? '=' : ':';
var metadataValues = CounterUtilities.GetMetadata(metadata, separator);
Expand Down Expand Up @@ -243,7 +243,7 @@ private static async Task WriteMetricDetails(

private static bool CompareMetrics(ICounterPayload first, ICounterPayload second)
{
return string.Equals(first.Name, second.Name);
return string.Equals(first.CounterMetadata.CounterName, second.CounterMetadata.CounterName);
}

public void Clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ public async Task HistogramFormat_Test()
{
List<ICounterPayload> payload = new();

payload.Add(new AggregatePercentilePayload(MeterName, InstrumentName, "DisplayName", string.Empty, string.Empty,
payload.Add(new AggregatePercentilePayload(new CounterMetadata(MeterName, InstrumentName, meterTags: null, instrumentTags: null, scopeHash: null),
"DisplayName", string.Empty, string.Empty,
new Quantile[] { new Quantile(0.5, Value1), new Quantile(0.95, Value2), new Quantile(0.99, Value3) },
Timestamp));

using MemoryStream stream = await GetMetrics(payload);
List<string> lines = ReadStream(stream);

string metricName = $"{MeterName.ToLowerInvariant()}_{payload[0].Name}";
string metricName = $"{MeterName.ToLowerInvariant()}_{payload[0].CounterMetadata.CounterName}";

const string quantile_50 = "{quantile=\"0.5\"}";
const string quantile_95 = "{quantile=\"0.95\"}";
Expand All @@ -68,13 +69,14 @@ public async Task HistogramFormat_Test()
[Fact]
public async Task GaugeFormat_Test()
{
ICounterPayload payload = new GaugePayload(MeterName, InstrumentName, "DisplayName", "", null, Value1, Timestamp);
ICounterPayload payload = new GaugePayload(new CounterMetadata(MeterName, InstrumentName, meterTags: null, instrumentTags: null, scopeHash: null),
"DisplayName", "", null, Value1, Timestamp);

MemoryStream stream = await GetMetrics(new() { payload });

List<string> lines = ReadStream(stream);

string metricName = $"{MeterName.ToLowerInvariant()}_{payload.Name}";
string metricName = $"{MeterName.ToLowerInvariant()}_{payload.CounterMetadata.CounterName}";

Assert.Equal(3, lines.Count);
Assert.Equal(FormattableString.Invariant($"# HELP {metricName}{payload.Unit} {payload.DisplayName}"), lines[0]);
Expand All @@ -85,13 +87,14 @@ public async Task GaugeFormat_Test()
[Fact]
public async Task CounterFormat_Test()
{
ICounterPayload payload = new RatePayload(MeterName, InstrumentName, "DisplayName", "", null, Value1, IntervalSeconds, Timestamp);
ICounterPayload payload = new RatePayload(new CounterMetadata(MeterName, InstrumentName, meterTags: null, instrumentTags: null, scopeHash: null),
"DisplayName", "", null, Value1, IntervalSeconds, Timestamp);

MemoryStream stream = await GetMetrics(new() { payload });

List<string> lines = ReadStream(stream);

string metricName = $"{MeterName.ToLowerInvariant()}_{payload.Name}";
string metricName = $"{MeterName.ToLowerInvariant()}_{payload.CounterMetadata.CounterName}";

Assert.Equal(3, lines.Count);
Assert.Equal($"# HELP {metricName}{payload.Unit} {payload.DisplayName}", lines[0]);
Expand All @@ -102,13 +105,14 @@ public async Task CounterFormat_Test()
[Fact]
public async Task UpDownCounterFormat_Test()
{
ICounterPayload payload = new UpDownCounterPayload(MeterName, InstrumentName, "DisplayName", "", null, Value1, Timestamp);
ICounterPayload payload = new UpDownCounterPayload(new CounterMetadata(MeterName, InstrumentName, meterTags: null, instrumentTags: null, scopeHash: null),
"DisplayName", "", null, Value1, Timestamp);

MemoryStream stream = await GetMetrics(new() { payload });

List<string> lines = ReadStream(stream);

string metricName = $"{MeterName.ToLowerInvariant()}_{payload.Name}";
string metricName = $"{MeterName.ToLowerInvariant()}_{payload.CounterMetadata.CounterName}";

Assert.Equal(3, lines.Count);
Assert.Equal(FormattableString.Invariant($"# HELP {metricName}{payload.Unit} {payload.DisplayName}"), lines[0]);
Expand Down

0 comments on commit 01acd6a

Please sign in to comment.