Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Commit

Permalink
Export LastValueData as Gauge for Prometheus exporter. (#737)
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 committed May 2, 2018
1 parent e17c4b1 commit c116366
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion exporter/prometheus/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func (c *collector) toMetric(desc *prometheus.Desc, v *view.View, row *view.Row)
return prometheus.NewConstMetric(desc, prometheus.UntypedValue, data.Value, tagValues(row.Tags)...)

case *view.LastValueData:
return prometheus.NewConstMetric(desc, prometheus.UntypedValue, data.Value, tagValues(row.Tags)...)
return prometheus.NewConstMetric(desc, prometheus.GaugeValue, data.Value, tagValues(row.Tags)...)

default:
return nil, fmt.Errorf("aggregation %T is not yet supported", v.Aggregation)
Expand Down
10 changes: 10 additions & 0 deletions exporter/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func newView(measureName string, agg *view.Aggregation) *view.View {
func TestOnlyCumulativeWindowSupported(t *testing.T) {
// See Issue https://github.com/census-instrumentation/opencensus-go/issues/214.
count1 := &view.CountData{Value: 1}
lastValue1 := &view.LastValueData{Value: 56.7}
tests := []struct {
vds *view.Data
want int
Expand All @@ -64,6 +65,15 @@ func TestOnlyCumulativeWindowSupported(t *testing.T) {
},
want: 1,
},
2: {
vds: &view.Data{
View: newView("TestOnlyCumulativeWindowSupported/m3", view.LastValue()),
Rows: []*view.Row{
{Data: lastValue1},
},
},
want: 1,
},
}

for i, tt := range tests {
Expand Down

0 comments on commit c116366

Please sign in to comment.