diff --git a/core/metrics/cgroups/v1/metrics.go b/core/metrics/cgroups/v1/metrics.go index bdc137c7964a..dd2c50957373 100644 --- a/core/metrics/cgroups/v1/metrics.go +++ b/core/metrics/cgroups/v1/metrics.go @@ -148,16 +148,12 @@ func (c *Collector) collect(entry entry, ch chan<- prometheus.Metric, block bool return } - data, err := typeurl.UnmarshalAny(stats) - if err != nil { + s := &v1.Metrics{} + if err := typeurl.UnmarshalTo(stats, s); err != nil { log.L.WithError(err).Errorf("unmarshal stats for %s", t.ID()) return } - s, ok := data.(*v1.Metrics) - if !ok { - log.L.WithError(err).Errorf("invalid metric type for %s", t.ID()) - return - } + ns := entry.ns if ns == nil { ns = c.ns diff --git a/core/metrics/cgroups/v2/metrics.go b/core/metrics/cgroups/v2/metrics.go index a92c235a9854..29916326ca6d 100644 --- a/core/metrics/cgroups/v2/metrics.go +++ b/core/metrics/cgroups/v2/metrics.go @@ -141,16 +141,11 @@ func (c *Collector) collect(entry entry, ch chan<- prometheus.Metric, block bool return } - data, err := typeurl.UnmarshalAny(stats) - if err != nil { + s := &v2.Metrics{} + if err := typeurl.UnmarshalTo(stats, s); err != nil { log.L.WithError(err).Errorf("unmarshal stats for %s", t.ID()) return } - s, ok := data.(*v2.Metrics) - if !ok { - log.L.WithError(err).Errorf("invalid metric type for %s", t.ID()) - return - } ns := entry.ns if ns == nil { ns = c.ns