Skip to content

Commit

Permalink
non-monotonic sums have the /gauge suffix added in GMP exporter (#676)
Browse files Browse the repository at this point in the history
  • Loading branch information
dashpole authored Jul 18, 2023
1 parent 3258806 commit 191af02
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions exporter/collector/googlemanagedprometheus/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ func GetMetricName(baseName string, metric pmetric.Metric) (string, error) {
// Second, ad the GMP-specific suffix
switch metric.Type() {
case pmetric.MetricTypeSum:
if !metric.Sum().IsMonotonic() {
// Non-monotonic sums are converted to GCM gauges
return compliantName + "/gauge", nil
}
return compliantName + getUnknownMetricSuffix(metric.Sum().DataPoints(), "/counter", "counter"), nil
case pmetric.MetricTypeGauge:
return compliantName + getUnknownMetricSuffix(metric.Gauge().DataPoints(), "/gauge", ""), nil
Expand Down
12 changes: 12 additions & 0 deletions exporter/collector/googlemanagedprometheus/naming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ func TestGetMetricName(t *testing.T) {
},
expected: "foo_total/counter",
},
{
desc: "non-monotonic sum",
baseName: "foo_total",
metric: func(m pmetric.Metric) {
m.SetName("foo_total")
sum := m.SetEmptySum()
sum.SetIsMonotonic(false)
},
expected: "foo_total/gauge",
},
{
desc: "gauge",
baseName: "bar",
Expand Down Expand Up @@ -150,6 +160,7 @@ func TestGetMetricName(t *testing.T) {
featuregate.GlobalRegistry().Set(gcpUntypedDoubleExportGateKey, false)
m.SetName("bar")
m.SetEmptySum()
m.Sum().SetIsMonotonic(true)
m.Sum().DataPoints().AppendEmpty().Attributes().PutStr(GCPOpsAgentUntypedMetricKey, "true")
},
expected: "bar/counter",
Expand All @@ -174,6 +185,7 @@ func TestGetMetricName(t *testing.T) {
featuregate.GlobalRegistry().Set(gcpUntypedDoubleExportGateKey, true)
m.SetName("bar")
m.SetEmptySum()
m.Sum().SetIsMonotonic(true)
m.Sum().DataPoints().AppendEmpty().Attributes().PutStr(GCPOpsAgentUntypedMetricKey, "true")
},
expected: "bar/unknown:counter",
Expand Down

0 comments on commit 191af02

Please sign in to comment.