lib/fs, lib/model: Be careful about potentially negative durations (fixes #9112) (#9113)

I don't really understand under what circumstances, but sometimes these
calls panic with a "panic: counter cannot decrease in value" because the
value passed to Add() was negative.
This commit is contained in:
Jakob Borg
2023-09-20 09:04:47 +02:00
committed by GitHub
parent 58d1f3a471
commit 051cbdc713
2 changed files with 9 additions and 3 deletions
+3 -1
View File
@@ -92,7 +92,9 @@ func (m *metricsFS) account(op string) func(bytes int) {
t0 := time.Now()
root := m.next.URI()
return func(bytes int) {
metricTotalOperationSeconds.WithLabelValues(root, op).Add(time.Since(t0).Seconds())
if dur := time.Since(t0).Seconds(); dur > 0 {
metricTotalOperationSeconds.WithLabelValues(root, op).Add(dur)
}
metricTotalOperationsCount.WithLabelValues(root, op).Inc()
if bytes >= 0 {
metricTotalBytesCount.WithLabelValues(root, op).Add(float64(bytes))