Skip to content

Commit

Permalink
DEVOPS-829 format Timer as summary/histogram type (#893)
Browse files Browse the repository at this point in the history
  • Loading branch information
rekibnikufesin authored Jun 9, 2023
1 parent 114c02b commit 81b06d6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
14 changes: 6 additions & 8 deletions metrics/prometheus/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (

var (
typeGaugeTpl = "# TYPE %s gauge\n"
typeCounterTpl = "# TYPE %s counter\n"
typeSummaryTpl = "# TYPE %s summary\n"
keyValueTpl = "%s %v\n\n"
keyCounterTpl = "%s %v\n"
Expand Down Expand Up @@ -82,11 +81,16 @@ func (c *collector) addMeter(name string, m metrics.Meter) {
func (c *collector) addTimer(name string, m metrics.Timer) {
pv := []float64{0.5, 0.75, 0.95, 0.99, 0.999, 0.9999}
ps := m.Percentiles(pv)
c.writeCounter(name, m.Count())

var sum float64 = 0
c.buff.WriteString(fmt.Sprintf(typeSummaryTpl, mutateKey(name)))
for i := range pv {
c.writeSummaryPercentile(name, strconv.FormatFloat(pv[i], 'f', -1, 64), ps[i])
sum += ps[i]
}

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

Expand Down Expand Up @@ -118,12 +122,6 @@ func (c *collector) writeGaugeCounter(name string, value interface{}) {
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
}

func (c *collector) writeCounter(name string, value interface{}) {
name = mutateKey(name + "_count")
c.buff.WriteString(fmt.Sprintf(typeCounterTpl, name))
c.buff.WriteString(fmt.Sprintf(keyValueTpl, name, value))
}

func (c *collector) writeSummaryCounter(name string, value interface{}) {
name = mutateKey(name + "_count")
c.buff.WriteString(fmt.Sprintf(keyCounterTpl, name, value))
Expand Down
5 changes: 2 additions & 3 deletions metrics/prometheus/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,15 @@ test_histogram_count 6
# TYPE test_meter gauge
test_meter 9999999
# TYPE test_timer_count counter
test_timer_count 6
# TYPE test_timer summary
test_timer {quantile="0.5"} 2.25e+07
test_timer {quantile="0.75"} 4.8e+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
# TYPE test_resetting_timer summary
test_resetting_timer {quantile="0.50"} 12000000
Expand Down

0 comments on commit 81b06d6

Please sign in to comment.