metrics: Use UnmarshalTo instead of UnmarshalAny

Co-authored-by: Sam Lockart <sam.lockart@zendesk.com>
Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
This commit is contained in:
Iceber Gu 2024-10-11 15:08:07 +08:00
parent 61f91b963e
commit c6d089090c
2 changed files with 5 additions and 14 deletions

View File

@ -148,16 +148,12 @@ func (c *Collector) collect(entry entry, ch chan<- prometheus.Metric, block bool
return return
} }
data, err := typeurl.UnmarshalAny(stats) s := &v1.Metrics{}
if err != nil { if err := typeurl.UnmarshalTo(stats, s); err != nil {
log.L.WithError(err).Errorf("unmarshal stats for %s", t.ID()) log.L.WithError(err).Errorf("unmarshal stats for %s", t.ID())
return return
} }
s, ok := data.(*v1.Metrics)
if !ok {
log.L.WithError(err).Errorf("invalid metric type for %s", t.ID())
return
}
ns := entry.ns ns := entry.ns
if ns == nil { if ns == nil {
ns = c.ns ns = c.ns

View File

@ -141,16 +141,11 @@ func (c *Collector) collect(entry entry, ch chan<- prometheus.Metric, block bool
return return
} }
data, err := typeurl.UnmarshalAny(stats) s := &v2.Metrics{}
if err != nil { if err := typeurl.UnmarshalTo(stats, s); err != nil {
log.L.WithError(err).Errorf("unmarshal stats for %s", t.ID()) log.L.WithError(err).Errorf("unmarshal stats for %s", t.ID())
return return
} }
s, ok := data.(*v2.Metrics)
if !ok {
log.L.WithError(err).Errorf("invalid metric type for %s", t.ID())
return
}
ns := entry.ns ns := entry.ns
if ns == nil { if ns == nil {
ns = c.ns ns = c.ns