diff --git a/eng/dependabot/nuget.org/Versions.props b/eng/dependabot/nuget.org/Versions.props index f6d66dd72ba..285eba92209 100644 --- a/eng/dependabot/nuget.org/Versions.props +++ b/eng/dependabot/nuget.org/Versions.props @@ -2,6 +2,6 @@ - 8.0.452401 + 8.0.510501 diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/JsonCounterLogger.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/JsonCounterLogger.cs index c7f1dad0034..d3fc0b8ce52 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/JsonCounterLogger.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/JsonCounterLogger.cs @@ -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()) @@ -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) @@ -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); diff --git a/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/MetricsStore.cs b/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/MetricsStore.cs index e49ec40b194..049a281117f 100644 --- a/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/MetricsStore.cs +++ b/src/Microsoft.Diagnostics.Monitoring.WebApi/Metrics/MetricsStore.cs @@ -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(); } @@ -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; } @@ -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); @@ -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); @@ -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() diff --git a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/MetricsFormattingTests.cs b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/MetricsFormattingTests.cs index 4bbcc8972c9..a2ea5bc952b 100644 --- a/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/MetricsFormattingTests.cs +++ b/src/Tests/Microsoft.Diagnostics.Monitoring.Tool.UnitTests/MetricsFormattingTests.cs @@ -44,14 +44,15 @@ public async Task HistogramFormat_Test() { List 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 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\"}"; @@ -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 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]); @@ -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 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]); @@ -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 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]);