Skip to content

Commit

Permalink
Merge pull request containerd#10814 from Iceber/release-1.7/unmarshal…
Browse files Browse the repository at this point in the history
…-metrics-to-type

[release/1.7] metrics: Use UnmarshalTo instead of UnmarshalAny
  • Loading branch information
dmcgowan authored Oct 16, 2024
2 parents 57f17b0 + d6f5778 commit 7d2d0c6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 3 additions & 7 deletions 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
10 changes: 3 additions & 7 deletions metrics/cgroups/v2/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,12 @@ 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 7d2d0c6

Please sign in to comment.