Skip to content

Commit

Permalink
Correctly set ValueType to Counter or Gauge
Browse files Browse the repository at this point in the history
  • Loading branch information
james-bebbington committed May 11, 2020
1 parent a37c735 commit 52bb9c4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,10 +312,10 @@ func protoMetricToPrometheusMetric(ctx context.Context, point *metricspb.Point,

case *metricspb.Point_Int64Value:
// Derive the Prometheus
return prometheus.NewConstMetric(desc, prometheus.CounterValue, float64(value.Int64Value), labelValues...)
return prometheus.NewConstMetric(desc, derivedPrometheusType, float64(value.Int64Value), labelValues...)

case *metricspb.Point_DoubleValue:
return prometheus.NewConstMetric(desc, prometheus.CounterValue, value.DoubleValue, labelValues...)
return prometheus.NewConstMetric(desc, derivedPrometheusType, value.DoubleValue, labelValues...)

default:
return nil, fmt.Errorf("Unhandled type: %T", point.Value)
Expand Down
6 changes: 5 additions & 1 deletion prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func TestOnlyCumulativeWindowSupported(t *testing.T) {
Name: "counter",
Description: "This is a counter",
Unit: "1",
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64,
},
Timeseries: []*metricspb.TimeSeries{
{
Expand Down Expand Up @@ -190,6 +191,7 @@ func TestCollectNonRacy(t *testing.T) {
Name: "counter",
Description: "This is a counter",
Unit: "1",
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64,
},
Timeseries: []*metricspb.TimeSeries{
{
Expand Down Expand Up @@ -292,6 +294,7 @@ func makeMetrics() []*metricspb.Metric {
Name: "this/one/there(where)",
Description: "Extra ones",
Unit: "1",
Type: metricspb.MetricDescriptor_GAUGE_INT64,
LabelKeys: []*metricspb.LabelKey{
{Key: "os", Description: "Operating system"},
{Key: "arch", Description: "Architecture"},
Expand Down Expand Up @@ -339,6 +342,7 @@ func makeMetrics() []*metricspb.Metric {
Name: strings.Repeat("a_", 60),
Description: "Unlimited metric key lengths",
Unit: "1",
Type: metricspb.MetricDescriptor_CUMULATIVE_INT64,
LabelKeys: []*metricspb.LabelKey{
{Key: "os", Description: "Operating system"},
{Key: "arch", Description: "Architecture"},
Expand Down Expand Up @@ -421,7 +425,7 @@ func TestMetricsEndpointOutput(t *testing.T) {
# 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
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
# HELP this_one_there_where_ Extra ones
# TYPE this_one_there_where_ counter
# TYPE this_one_there_where_ gauge
this_one_there_where_{arch="386",my_org_department="Ops",os="darwin"} 49.5
this_one_there_where_{arch="x86",my_org_department="Storage",os="windows"} 99
# HELP with_metric_descriptor This is a test
Expand Down

0 comments on commit 52bb9c4

Please sign in to comment.