Fix unsafe type assertion panic in metrics.go when status["total_size"] is nil

Co-authored-by: kira1928 <2352900+kira1928@users.noreply.github.com>
Agent-Logs-Url: https://github.com/bililive-go/bililive-go/sessions/e3b4acf7-a4ea-47c7-98c9-c51ca1cc43ee
This commit is contained in:
copilot-swe-agent[bot]andkira1928 committed 2026-03-20 23:09:23 +00:00
1 parent 6727a3dff4
commit 31ed93da33
1 file changed
+5 -3
+5 -3
View File
@@ -80,9 +80,11 @@ func (c collector) Collect(ch chan<- prometheus.Metric) {
if r, err := c.inst.RecorderManager.(recorders.Manager).GetRecorder(context.Background(), id); err == nil {
if status, err := r.GetStatus(); err == nil {
if value, err := strconv.ParseFloat(status["total_size"].(string), 64); err == nil {
ch <- prometheus.MustNewConstMetric(recorderTotalBytes, prometheus.CounterValue, value,
string(id), l.GetRawUrl(), info.HostName, info.RoomName)
if totalSize, ok := status["total_size"].(string); ok {
if value, err := strconv.ParseFloat(totalSize, 64); err == nil {
ch <- prometheus.MustNewConstMetric(recorderTotalBytes, prometheus.CounterValue, value,
string(id), l.GetRawUrl(), info.HostName, info.RoomName)
}
}
}
}