Skip to content

Commit 42e0e55

Browse files
authored
fix panic on reading stream stats (#881)
* fix panic on reading stream stats * avoid converting potentially incorrect values for now
1 parent ebd8178 commit 42e0e55

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

pkg/pipeline/builder/stream.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -271,15 +271,31 @@ func (s *Stream) Stats() (*logging.StreamStats, bool) {
271271
if err != nil || structure == nil {
272272
return nil, false
273273
}
274+
274275
if stats := structure.(*gst.Structure).Values(); stats != nil {
275276
return &logging.StreamStats{
276277
Timestamp: time.Now().Format(time.DateTime),
277278
Keyframes: s.keyframes.Load(),
278-
OutBytesTotal: stats[outBytesTotal].(uint64),
279-
OutBytesAcked: stats[outBytesAcked].(uint64),
280-
InBytesTotal: stats[inBytesTotal].(uint64),
281-
InBytesAcked: stats[inBytesAcked].(uint64),
279+
OutBytesTotal: tryUInt64(stats, outBytesTotal),
280+
OutBytesAcked: tryUInt64(stats, outBytesAcked),
281+
InBytesTotal: tryUInt64(stats, inBytesTotal),
282+
InBytesAcked: tryUInt64(stats, inBytesAcked),
282283
}, true
283284
}
285+
284286
return nil, false
285287
}
288+
289+
// sink stats sometimes returns strings instead of uint64
290+
func tryUInt64(stats map[string]interface{}, key string) uint64 {
291+
switch val := stats[key].(type) {
292+
case uint64:
293+
return val
294+
default:
295+
logger.Infow(fmt.Sprintf("unexpected type for %s", key),
296+
"type", fmt.Sprintf("%T", val),
297+
"value", val,
298+
)
299+
return 0
300+
}
301+
}

0 commit comments

Comments
 (0)