Skip to content

Commit

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

metrics: Use UnmarshalTo instead of UnmarshalAny
  • Loading branch information
estesp authored Oct 16, 2024
2 parents dac9419 + c6d0890 commit d1245c6
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 d1245c6

Please sign in to comment.