Skip to content

Commit 918bab8

Browse files
authored
Merge pull request prometheus#280 from beorn7/native-histograms
Enable Prometheus native histograms for request_duration_seconds
2 parents 1687141 + b8e3b04 commit 918bab8

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/opentracing/opentracing-go v1.1.0
2323
github.com/pkg/errors v0.9.1
2424
github.com/pmezard/go-difflib v1.0.0
25-
github.com/prometheus/client_golang v1.13.0
25+
github.com/prometheus/client_golang v1.14.0
2626
github.com/prometheus/exporter-toolkit v0.8.2
2727
github.com/sercand/kuberesolver v2.4.0+incompatible
2828
github.com/sirupsen/logrus v1.6.0

go.sum

+4-2
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,15 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn
276276
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
277277
github.com/prometheus/client_golang v1.11.0/go.mod h1:Z6t4BnS23TR94PD6BsDNk8yVqroYurpAkEiz0P2BEV0=
278278
github.com/prometheus/client_golang v1.12.1/go.mod h1:3Z9XVyYiZYEO+YQWt3RD2R3jrbd179Rt297l4aS6nDY=
279-
github.com/prometheus/client_golang v1.13.0 h1:b71QUfeo5M8gq2+evJdTPfZhYMAU0uKPkyPJ7TPsloU=
280279
github.com/prometheus/client_golang v1.13.0/go.mod h1:vTeo+zgvILHsnnj/39Ou/1fPN5nJFOEMgftOUOmlvYQ=
280+
github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj0VP62TMhnw=
281+
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
281282
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
282283
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
283284
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
284-
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
285285
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
286+
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
287+
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
286288
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
287289
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
288290
github.com/prometheus/common v0.26.0/go.mod h1:M7rCNAaPfAosfx8veZJCuw84e35h3Cfd9VFqTh1DIvc=

server/server.go

+14-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ type TLSConfig struct {
6060

6161
// Config for a Server
6262
type Config struct {
63-
MetricsNamespace string `yaml:"-"`
63+
MetricsNamespace string `yaml:"-"`
64+
// Set to > 1 to add native histograms to requestDuration.
65+
// See documentation for NativeHistogramBucketFactor in
66+
// https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#HistogramOpts
67+
// for details. A generally useful value is 1.1.
68+
MetricsNativeHistogramFactor float64 `yaml:"-"`
69+
6470
HTTPListenNetwork string `yaml:"http_listen_network"`
6571
HTTPListenAddress string `yaml:"http_listen_address"`
6672
HTTPListenPort int `yaml:"http_listen_port"`
@@ -292,10 +298,13 @@ func New(cfg Config) (*Server, error) {
292298

293299
// Prometheus histograms for requests.
294300
requestDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{
295-
Namespace: cfg.MetricsNamespace,
296-
Name: "request_duration_seconds",
297-
Help: "Time (in seconds) spent serving HTTP requests.",
298-
Buckets: instrument.DefBuckets,
301+
Namespace: cfg.MetricsNamespace,
302+
Name: "request_duration_seconds",
303+
Help: "Time (in seconds) spent serving HTTP requests.",
304+
Buckets: instrument.DefBuckets,
305+
NativeHistogramBucketFactor: cfg.MetricsNativeHistogramFactor,
306+
NativeHistogramMaxBucketNumber: 100,
307+
NativeHistogramMinResetDuration: time.Hour,
299308
}, []string{"method", "route", "status_code", "ws"})
300309
reg.MustRegister(requestDuration)
301310

0 commit comments

Comments
 (0)