Skip to content

Commit

Permalink
feat/custom_buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
aiden.ma authored and aiden.ma committed Aug 11, 2024
1 parent f4b6e5e commit 31a4613
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions rest/handler/prometheushandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
const serverNamespace = "http_server"

var (
rpcServerReqDurBuckets = []float64{5, 10, 25, 50, 100, 250, 500, 750, 1000}
serverReqDurBuckets = []float64{5, 10, 25, 50, 100, 250, 500, 750, 1000}
metricServerReqDurOnce sync.Once

metricServerReqDur metric.HistogramVec
Expand All @@ -30,7 +30,7 @@ var (
// SetServerReqDurBuckets sets buckets for rest server requests duration.
// It must be called before PrometheusHandler is used.
func SetServerReqDurBuckets(buckets []float64) {
rpcServerReqDurBuckets = buckets
serverReqDurBuckets = buckets
}

// PrometheusHandler returns a middleware that reports stats to prometheus.
Expand Down Expand Up @@ -60,7 +60,7 @@ func initMetricServerReqDur() {
Name: "duration_ms",
Help: "http server requests duration(ms).",
Labels: []string{"path", "method", "code"},
Buckets: rpcServerReqDurBuckets,
Buckets: serverReqDurBuckets,
})
})
}
2 changes: 1 addition & 1 deletion rest/handler/prometheushandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ func TestPromMetricHandler_Enabled(t *testing.T) {

func TestSetRpcServerReqDurBuckets(t *testing.T) {
SetServerReqDurBuckets([]float64{0.1})
assert.Equal(t, []float64{0.1}, rpcServerReqDurBuckets)
assert.Equal(t, []float64{0.1}, serverReqDurBuckets)
}

0 comments on commit 31a4613

Please sign in to comment.