From 91be79b041bab0dcaa0d79e6e73ba6d4d24434ba Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Tue, 8 Apr 2025 18:08:01 +0200 Subject: [PATCH 1/4] fix(metrics/prometheus): add case for `StandardGaugeInfo` to skip --- metrics/prometheus/prometheus.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/metrics/prometheus/prometheus.go b/metrics/prometheus/prometheus.go index bfa73245c9..93845feef6 100644 --- a/metrics/prometheus/prometheus.go +++ b/metrics/prometheus/prometheus.go @@ -197,6 +197,9 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err }, }}, }, nil + case metrics.StandardGaugeInfo: + // TODO(qdm12) handle this somehow maybe with dto.MetricType_UNTYPED + return nil, fmt.Errorf("%w: %q is a %T", errMetricSkip, name, metric) default: return nil, fmt.Errorf("metric %q: type is not supported: %T", name, metric) } From 662de26e520eaf744d6510d08734f02285abf6c8 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Tue, 8 Apr 2025 19:16:28 +0200 Subject: [PATCH 2/4] Pointer type --- metrics/prometheus/prometheus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/prometheus/prometheus.go b/metrics/prometheus/prometheus.go index 93845feef6..0a3d45c9b9 100644 --- a/metrics/prometheus/prometheus.go +++ b/metrics/prometheus/prometheus.go @@ -197,7 +197,7 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err }, }}, }, nil - case metrics.StandardGaugeInfo: + case *metrics.StandardGaugeInfo: // TODO(qdm12) handle this somehow maybe with dto.MetricType_UNTYPED return nil, fmt.Errorf("%w: %q is a %T", errMetricSkip, name, metric) default: From 0ac245976b35cbb8f8a66a2f4db599ed07f08a0b Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Tue, 8 Apr 2025 19:23:05 +0200 Subject: [PATCH 3/4] Update test --- metrics/prometheus/prometheus.go | 5 +++-- metrics/prometheus/prometheus_test.go | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/metrics/prometheus/prometheus.go b/metrics/prometheus/prometheus.go index 0a3d45c9b9..12834a05a4 100644 --- a/metrics/prometheus/prometheus.go +++ b/metrics/prometheus/prometheus.go @@ -57,7 +57,8 @@ func (g *Gatherer) Gather() (mfs []*dto.MetricFamily, err error) { } var ( - errMetricSkip = errors.New("metric skipped") + errMetricSkip = errors.New("metric skipped") + errMetricTypeNotSupported = errors.New("metric type is not supported") ) func ptrTo[T any](x T) *T { return &x } @@ -201,6 +202,6 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err // TODO(qdm12) handle this somehow maybe with dto.MetricType_UNTYPED return nil, fmt.Errorf("%w: %q is a %T", errMetricSkip, name, metric) default: - return nil, fmt.Errorf("metric %q: type is not supported: %T", name, metric) + return nil, fmt.Errorf("%w: metric %q type %T", errMetricTypeNotSupported, name, metric) } } diff --git a/metrics/prometheus/prometheus_test.go b/metrics/prometheus/prometheus_test.go index 4263abed7d..71d506efa5 100644 --- a/metrics/prometheus/prometheus_test.go +++ b/metrics/prometheus/prometheus_test.go @@ -90,8 +90,8 @@ func TestGatherer_Gather(t *testing.T) { } assert.Equal(t, want, familyStrings) - register(t, "unsupported", metrics.NewGaugeInfo()) + register(t, "unsupported", metrics.NewHealthcheck(nil)) families, err = gatherer.Gather() - assert.EqualError(t, err, "metric \"unsupported\": type is not supported: *metrics.StandardGaugeInfo") + assert.ErrorIs(t, err, errMetricTypeNotSupported) assert.Empty(t, families) } From 3582d815c2f57f99cbfa22a99759c4c05a9f4e68 Mon Sep 17 00:00:00 2001 From: Quentin Mc Gaw Date: Tue, 8 Apr 2025 19:34:05 +0200 Subject: [PATCH 4/4] Use metrics.GaugeInfo --- metrics/prometheus/prometheus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/prometheus/prometheus.go b/metrics/prometheus/prometheus.go index 12834a05a4..9db1495af8 100644 --- a/metrics/prometheus/prometheus.go +++ b/metrics/prometheus/prometheus.go @@ -198,7 +198,7 @@ func metricFamily(registry Registry, name string) (mf *dto.MetricFamily, err err }, }}, }, nil - case *metrics.StandardGaugeInfo: + case metrics.GaugeInfo: // TODO(qdm12) handle this somehow maybe with dto.MetricType_UNTYPED return nil, fmt.Errorf("%w: %q is a %T", errMetricSkip, name, metric) default: