Skip to content

Commit 7197eac

Browse files
authored
Merge pull request #8 from james-bebbington/master
Correctly set ValueType to Counter or Gauge Uses the already derivedType parameter that was mistakenly not being used.
2 parents a37c735 + 52bb9c4 commit 7197eac

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

prometheus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,10 +312,10 @@ func protoMetricToPrometheusMetric(ctx context.Context, point *metricspb.Point,
312312

313313
case *metricspb.Point_Int64Value:
314314
// Derive the Prometheus
315-
return prometheus.NewConstMetric(desc, prometheus.CounterValue, float64(value.Int64Value), labelValues...)
315+
return prometheus.NewConstMetric(desc, derivedPrometheusType, float64(value.Int64Value), labelValues...)
316316

317317
case *metricspb.Point_DoubleValue:
318-
return prometheus.NewConstMetric(desc, prometheus.CounterValue, value.DoubleValue, labelValues...)
318+
return prometheus.NewConstMetric(desc, derivedPrometheusType, value.DoubleValue, labelValues...)
319319

320320
default:
321321
return nil, fmt.Errorf("Unhandled type: %T", point.Value)

prometheus_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ func TestOnlyCumulativeWindowSupported(t *testing.T) {
9393
Name: "counter",
9494
Description: "This is a counter",
9595
Unit: "1",
96+
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64,
9697
},
9798
Timeseries: []*metricspb.TimeSeries{
9899
{
@@ -190,6 +191,7 @@ func TestCollectNonRacy(t *testing.T) {
190191
Name: "counter",
191192
Description: "This is a counter",
192193
Unit: "1",
194+
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64,
193195
},
194196
Timeseries: []*metricspb.TimeSeries{
195197
{
@@ -292,6 +294,7 @@ func makeMetrics() []*metricspb.Metric {
292294
Name: "this/one/there(where)",
293295
Description: "Extra ones",
294296
Unit: "1",
297+
Type: metricspb.MetricDescriptor_GAUGE_INT64,
295298
LabelKeys: []*metricspb.LabelKey{
296299
{Key: "os", Description: "Operating system"},
297300
{Key: "arch", Description: "Architecture"},
@@ -339,6 +342,7 @@ func makeMetrics() []*metricspb.Metric {
339342
Name: strings.Repeat("a_", 60),
340343
Description: "Unlimited metric key lengths",
341344
Unit: "1",
345+
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64,
342346
LabelKeys: []*metricspb.LabelKey{
343347
{Key: "os", Description: "Operating system"},
344348
{Key: "arch", Description: "Architecture"},
@@ -421,7 +425,7 @@ func TestMetricsEndpointOutput(t *testing.T) {
421425
# TYPE a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_ counter
422426
a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_a_{arch="x86",keykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykeykey="",my_org_department="Storage",os="windows"} 99
423427
# HELP this_one_there_where_ Extra ones
424-
# TYPE this_one_there_where_ counter
428+
# TYPE this_one_there_where_ gauge
425429
this_one_there_where_{arch="386",my_org_department="Ops",os="darwin"} 49.5
426430
this_one_there_where_{arch="x86",my_org_department="Storage",os="windows"} 99
427431
# HELP with_metric_descriptor This is a test

0 commit comments

Comments
 (0)