Skip to content

Commit d6f5778

Browse files
Iceberalam0rt
andcommitted
metrics: Use UnmarshalTo instead of UnmarshalAny
Co-authored-by: Sam Lockart <[email protected]> Signed-off-by: Iceber Gu <[email protected]>
1 parent f380dee commit d6f5778

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

metrics/cgroups/v1/metrics.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,12 @@ func (c *Collector) collect(entry entry, ch chan<- prometheus.Metric, block bool
148148
return
149149
}
150150

151-
data, err := typeurl.UnmarshalAny(stats)
152-
if err != nil {
151+
s := &v1.Metrics{}
152+
if err := typeurl.UnmarshalTo(stats, s); err != nil {
153153
log.L.WithError(err).Errorf("unmarshal stats for %s", t.ID())
154154
return
155155
}
156-
s, ok := data.(*v1.Metrics)
157-
if !ok {
158-
log.L.WithError(err).Errorf("invalid metric type for %s", t.ID())
159-
return
160-
}
156+
161157
ns := entry.ns
162158
if ns == nil {
163159
ns = c.ns

metrics/cgroups/v2/metrics.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,12 @@ func (c *Collector) collect(entry entry, ch chan<- prometheus.Metric, block bool
141141
return
142142
}
143143

144-
data, err := typeurl.UnmarshalAny(stats)
145-
if err != nil {
144+
s := &v2.Metrics{}
145+
if err := typeurl.UnmarshalTo(stats, s); err != nil {
146146
log.L.WithError(err).Errorf("unmarshal stats for %s", t.ID())
147147
return
148148
}
149-
s, ok := data.(*v2.Metrics)
150-
if !ok {
151-
log.L.WithError(err).Errorf("invalid metric type for %s", t.ID())
152-
return
153-
}
149+
154150
ns := entry.ns
155151
if ns == nil {
156152
ns = c.ns

0 commit comments

Comments
 (0)