Skip to content

Commit

Permalink
dont attempt to create metric descriptors for metrics without an aggr…
Browse files Browse the repository at this point in the history
…egation or data points (#530)
  • Loading branch information
dashpole committed Nov 14, 2022
1 parent e955c20 commit 03657bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions exporter/collector/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,14 @@ func (m *metricMapper) metricDescriptor(
return m.summaryMetricDescriptors(pm, extraLabels)
}
kind, typ := mapMetricPointKind(pm)
if kind == metricpb.MetricDescriptor_METRIC_KIND_UNSPECIFIED {
m.obs.log.Debug("Failed to get metric kind (i.e. aggregation) for metric descriptor. Dropping the metric descriptor.", zap.Any("metric", pm))
return nil
}
if typ == metricpb.MetricDescriptor_VALUE_TYPE_UNSPECIFIED {
m.obs.log.Debug("Failed to get metric type (int / double) for metric descriptor. Dropping the metric descriptor.", zap.Any("metric", pm))
return nil
}
metricType, err := m.metricNameToType(pm.Name(), pm)
if err != nil {
m.obs.log.Debug("Failed to get metric type (i.e. name) for metric descriptor. Dropping the metric descriptor.", zap.Error(err), zap.Any("metric", pm))
Expand Down
21 changes: 21 additions & 0 deletions exporter/collector/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,27 @@ func TestMetricDescriptorMapping(t *testing.T) {
},
},
},
{
name: "No data points",
metricCreator: func() pmetric.Metric {
metric := pmetric.NewMetric()
metric.SetName("custom.googleapis.com/test.metric")
metric.SetDescription("Description")
metric.SetUnit("1")
metric.SetEmptyGauge()
return metric
},
},
{
name: "No aggregation",
metricCreator: func() pmetric.Metric {
metric := pmetric.NewMetric()
metric.SetName("custom.googleapis.com/test.metric")
metric.SetDescription("Description")
metric.SetUnit("1")
return metric
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit 03657bf

Please sign in to comment.