Merge pull request #10815 from Iceber/unmarshal-metrics-to-type

metrics: Use UnmarshalTo instead of UnmarshalAny
This commit is contained in:
Phil Estes 2024-10-16 13:50:24 +00:00 committed by GitHub
commit d1245c6faf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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
}
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

View File

@ -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