Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -202,6 +202,7 @@ private static string GetMetricType(EventType eventType)
{
// In Prometheus, rates are treated as gauges due to their non-monotonic nature
case EventType.Rate:
case EventType.UpDownCounter:
case EventType.Gauge:
return "gauge";
case EventType.Histogram:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public async Task HistogramFormat_Test()
using MemoryStream stream = await GetMetrics(payload);
List<string> lines = ReadStream(stream);

// Question - this is manually recreating what PrometheusDataModel.GetPrometheusNormalizedName does to get the metric name;
// should we call this method, or should this also be implicitly testing its behavior by having this hard-coded?
string metricName = $"{MeterName.ToLowerInvariant()}_{payload[0].Name}";

const string quantile_50 = "{quantile=\"0.5\"}";
Expand All @@ -74,8 +72,6 @@ public async Task GaugeFormat_Test()

List<string> lines = ReadStream(stream);

// Question - this is manually recreating what PrometheusDataModel.GetPrometheusNormalizedName does to get the metric name;
// should we call this method, or should this also be implicitly testing its behavior by having this hard-coded?
string metricName = $"{MeterName.ToLowerInvariant()}_{payload.Name}";

Assert.Equal(3, lines.Count);
Expand All @@ -93,8 +89,6 @@ public async Task CounterFormat_Test()

List<string> lines = ReadStream(stream);

// Question - this is manually recreating what PrometheusDataModel.GetPrometheusNormalizedName does to get the metric name;
// should we call this method, or should this also be implicitly testing its behavior by having this hard-coded?
string metricName = $"{MeterName.ToLowerInvariant()}_{payload.Name}";

Assert.Equal(3, lines.Count);
Expand All @@ -103,6 +97,23 @@ public async Task CounterFormat_Test()
Assert.Equal($"{metricName} {payload.Value} {new DateTimeOffset(payload.Timestamp).ToUnixTimeMilliseconds()}", lines[2]);
}

[Fact]
public async Task UpDownCounterFormat_Test()
{
ICounterPayload payload = new UpDownCounterPayload(MeterName, InstrumentName, "DisplayName", "", null, Value1, Timestamp);

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

List<string> lines = ReadStream(stream);

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

Assert.Equal(3, lines.Count);
Assert.Equal(FormattableString.Invariant($"# HELP {metricName}{payload.Unit} {payload.DisplayName}"), lines[0]);
Assert.Equal(FormattableString.Invariant($"# TYPE {metricName} gauge"), lines[1]);
Assert.Equal(FormattableString.Invariant($"{metricName} {payload.Value} {new DateTimeOffset(payload.Timestamp).ToUnixTimeMilliseconds()}"), lines[2]);
}

private async Task<MemoryStream> GetMetrics(List<ICounterPayload> payloads)
{
IMetricsStore metricsStore = new MetricsStore(_logger, MetricCount);
Expand Down