Skip to content

Commit

Permalink
Add an additional test to ensure that non-counter metrics use the ori…
Browse files Browse the repository at this point in the history
…ginal metric name despite using the truncated name for metadata lookup.
  • Loading branch information
bmoyles0117 committed Aug 14, 2019
1 parent 47c0e8d commit b719493
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions retrieval/transform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,8 @@ func TestSampleBuilder(t *testing.T) {
},
},
},
// Metrics with the _total suffix should be preserved if metadata can be found for the original metric name.
// Any counter metric with the _total suffix should be treated as normal if metadata
// can be found for the original metric name.
{
series: seriesMap{
1: labels.FromStrings("job", "job1", "instance", "instance1", "a", "1", "__name__", "metric1_total"),
Expand Down Expand Up @@ -670,7 +671,9 @@ func TestSampleBuilder(t *testing.T) {
},
},
},
// Metrics with the _total suffix should fail over to the metadata for the metric with the _total suffix removed.
// Any counter metric with the _total suffix should fail over to the metadata for
// the metric with the _total suffix removed while reporting the metric with the
// _total suffix removed in the metric name as well.
{
series: seriesMap{
1: labels.FromStrings("job", "job1", "instance", "instance1", "a", "1", "__name__", "metric1_total"),
Expand Down Expand Up @@ -714,6 +717,49 @@ func TestSampleBuilder(t *testing.T) {
},
},
},
// Any non-counter metric with the _total suffix should fail over to the metadata
// for the metric with the _total suffix removed while reporting the metric with
// the original name.
{
series: seriesMap{
1: labels.FromStrings("job", "job1", "instance", "instance1", "a", "1", "__name__", "metric1_total"),
},
targets: targetMap{
"job1/instance1": &targets.Target{
Labels: promlabels.FromStrings("job", "job1", "instance", "instance1"),
DiscoveredLabels: promlabels.FromStrings("__resource_a", "resource2_a"),
},
},
metadata: metadataMap{
"job1/instance1/metric1": &scrape.MetricMetadata{Type: textparse.MetricTypeGauge, Metric: "metric1"},
},
metricPrefix: "test.googleapis.com",
input: []tsdb.RefSample{
{Ref: 1, T: 3000, V: 8},
},
result: []*monitoring_pb.TimeSeries{
{
Resource: &monitoredres_pb.MonitoredResource{
Type: "resource2",
Labels: map[string]string{"resource_a": "resource2_a"},
},
Metric: &metric_pb.Metric{
Type: "test.googleapis.com/metric1_total",
Labels: map[string]string{"a": "1"},
},
MetricKind: metric_pb.MetricDescriptor_GAUGE,
ValueType: metric_pb.MetricDescriptor_DOUBLE,
Points: []*monitoring_pb.Point{{
Interval: &monitoring_pb.TimeInterval{
EndTime: &timestamp_pb.Timestamp{Seconds: 3},
},
Value: &monitoring_pb.TypedValue{
Value: &monitoring_pb.TypedValue_DoubleValue{8},
},
}},
},
},
},
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down

0 comments on commit b719493

Please sign in to comment.