Skip to content

Commit e277f75

Browse files
Fix: Skip SUMMARY and other unsupported metric types in ParsePrometheusMetrics
The OpenTelemetry Prometheus exporter exports additional metric types like SUMMARY (e.g., go_gc_duration_seconds) that were not handled by the parser. Instead of returning an error for unsupported types, we now skip them since NPD only cares about its own COUNTER and GAUGE metrics. Co-authored-by: MartinForReal <[email protected]>
1 parent 62f051b commit e277f75

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

pkg/util/metrics/helpers.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func getAttributeKeysFromNames(tagNames []string) []attribute.Key {
6666
// ParsePrometheusMetrics parses Prometheus formatted metrics into metrics under Float64MetricRepresentation.
6767
//
6868
// Note: Prometheus's go library stores all counter/gauge-typed metric values under float64.
69+
// Note: Only COUNTER and GAUGE metric types are parsed. Other types (SUMMARY, HISTOGRAM, UNTYPED) are skipped.
6970
func ParsePrometheusMetrics(metricsText string) ([]Float64MetricRepresentation, error) {
7071
var metrics []Float64MetricRepresentation
7172

@@ -90,8 +91,9 @@ func ParsePrometheusMetrics(metricsText string) ([]Float64MetricRepresentation,
9091
case pcm.MetricType_GAUGE:
9192
value = *metric.Gauge.Value
9293
default:
93-
return metrics, fmt.Errorf("unexpected MetricType %s for metric %s",
94-
pcm.MetricType_name[int32(*metricFamily.Type)], *metricFamily.Name)
94+
// Skip unsupported metric types (SUMMARY, HISTOGRAM, UNTYPED, GAUGE_HISTOGRAM)
95+
// These are typically Go runtime metrics and not NPD-specific metrics
96+
continue
9597
}
9698

9799
metrics = append(metrics, Float64MetricRepresentation{*metricFamily.Name, labels, value})

0 commit comments

Comments
 (0)