mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-02 22:50:18 +00:00
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:
parent
58d1f3a471
commit
051cbdc713
@ -92,7 +92,9 @@ func (m *metricsFS) account(op string) func(bytes int) {
|
|||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
root := m.next.URI()
|
root := m.next.URI()
|
||||||
return func(bytes int) {
|
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()
|
metricTotalOperationsCount.WithLabelValues(root, op).Inc()
|
||||||
if bytes >= 0 {
|
if bytes >= 0 {
|
||||||
metricTotalBytesCount.WithLabelValues(root, op).Add(float64(bytes))
|
metricTotalBytesCount.WithLabelValues(root, op).Add(float64(bytes))
|
||||||
|
@ -158,7 +158,9 @@ func inWritableDir(fn func(string) error, targetFs fs.Filesystem, path string, i
|
|||||||
func addTimeUntilCancelled(ctx context.Context, counter prometheus.Counter) {
|
func addTimeUntilCancelled(ctx context.Context, counter prometheus.Counter) {
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
defer func() {
|
defer func() {
|
||||||
counter.Add(time.Since(t0).Seconds())
|
if dur := time.Since(t0).Seconds(); dur > 0 {
|
||||||
|
counter.Add(dur)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
ticker := time.NewTicker(time.Second)
|
ticker := time.NewTicker(time.Second)
|
||||||
@ -167,7 +169,9 @@ func addTimeUntilCancelled(ctx context.Context, counter prometheus.Counter) {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case t := <-ticker.C:
|
case t := <-ticker.C:
|
||||||
counter.Add(t.Sub(t0).Seconds())
|
if dur := t.Sub(t0).Seconds(); dur > 0 {
|
||||||
|
counter.Add(dur)
|
||||||
|
}
|
||||||
t0 = t
|
t0 = t
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user