Skip to content

Commit

Permalink
metrics: Use UnmarshalTo instead of UnmarshalAny
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Lockart <sam.lockart@zendesk.com>
Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
  • Loading branch information
Iceber and alam0rt committed Oct 12, 2024
1 parent 61f91b9 commit c6d0890
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 14 deletions.
10 changes: 3 additions & 7 deletions core/metrics/cgroups/v1/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions core/metrics/cgroups/v2/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c6d0890

Please sign in to comment.