Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metrics/prometheus: fix count field of metric #965

Merged
merged 1 commit into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions metrics/prometheus/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (c *collector) addHistogram(name string, m metrics.Histogram) {
}

c.writeSummarySum(name, fmt.Sprintf("%f", sum))
c.writeSummaryCounter(name, len(ps))
c.writeSummaryCounter(name, m.Count())
c.buff.WriteRune('\n')
}

Expand All @@ -97,7 +97,7 @@ func (c *collector) addTimer(name string, m metrics.Timer) {
}

c.writeSummarySum(name, fmt.Sprintf("%f", sum))
c.writeSummaryCounter(name, len(ps))
c.writeSummaryCounter(name, m.Count())
c.buff.WriteRune('\n')
}

Expand Down
18 changes: 10 additions & 8 deletions metrics/prometheus/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func TestCollector(t *testing.T) {
timer.Update(120 * time.Millisecond)
timer.Update(23 * time.Millisecond)
timer.Update(24 * time.Millisecond)
timer.Update(30 * time.Millisecond)
c.addTimer("test/timer", timer)

resettingTimer := metrics.NewResettingTimer()
Expand All @@ -58,6 +59,7 @@ func TestCollector(t *testing.T) {
resettingTimer.Update(120 * time.Millisecond)
resettingTimer.Update(13 * time.Millisecond)
resettingTimer.Update(14 * time.Millisecond)
resettingTimer.Update(30 * time.Millisecond)
c.addResettingTimer("test/resetting_timer", resettingTimer.Snapshot())

emptyResettingTimer := metrics.NewResettingTimer().Snapshot()
Expand All @@ -83,27 +85,27 @@ test_histogram {quantile="0.99"} 0
test_histogram {quantile="0.999"} 0
test_histogram {quantile="0.9999"} 0
test_histogram_sum 0.000000
test_histogram_count 6
test_histogram_count 0

# TYPE test_meter gauge
test_meter 9999999

# TYPE test_timer summary
test_timer {quantile="0.5"} 2.25e+07
test_timer {quantile="0.75"} 4.8e+07
test_timer {quantile="0.5"} 2.3e+07
test_timer {quantile="0.75"} 3e+07
test_timer {quantile="0.95"} 1.2e+08
test_timer {quantile="0.99"} 1.2e+08
test_timer {quantile="0.999"} 1.2e+08
test_timer {quantile="0.9999"} 1.2e+08
test_timer_sum 550500000.000000
test_timer_count 6
test_timer_sum 533000000.000000
test_timer_count 7

# TYPE test_resetting_timer summary
test_resetting_timer {quantile="0.50"} 12000000
test_resetting_timer {quantile="0.50"} 13000000
test_resetting_timer {quantile="0.95"} 120000000
test_resetting_timer {quantile="0.99"} 120000000
test_resetting_timer_sum 180000000
test_resetting_timer_count 6
test_resetting_timer_sum 210000000
test_resetting_timer_count 7

`

Expand Down
Loading