Skip to content

Commit

Permalink
Replaced summary in extprom metrics with histogram
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Rabenhorst <[email protected]>
  • Loading branch information
rabenhorst committed May 2, 2023
1 parent a1ec4d5 commit 02af6f1
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 26 deletions.
2 changes: 1 addition & 1 deletion cmd/thanos/compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ func runCompact(
if !conf.disableWeb {
r := route.New()

ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil, nil, 0, 0)

global := ui.NewBucketUI(logger, conf.webConf.externalPrefix, conf.webConf.prefixHeaderName, component)
global.Register(r, ins)
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ func runQuery(
// Configure Request Logging for HTTP calls.
logMiddleware := logging.NewHTTPServerMiddleware(logger, httpLogOpts...)

ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil, nil, 0, 0)
// TODO(bplotka in PR #513 review): pass all flags, not only the flags needed by prefix rewriting.
ui.NewQueryUI(logger, endpoints, webExternalPrefix, webPrefixHeaderName, alertQueryURL).Register(router, ins)

Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/query_frontend.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func runQueryFrontend(

// Configure Request Logging for HTTP calls.
logMiddleware := logging.NewHTTPServerMiddleware(logger, httpLogOpts...)
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil, nil, 0, 0)

// Start metrics HTTP server.
{
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ func runRule(
}
})

ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil, nil, 0, 0)

// Configure Request Logging for HTTP calls.
logMiddleware := logging.NewHTTPServerMiddleware(logger, httpLogOpts...)
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ func runStore(
}
// Add bucket UI for loaded blocks.
{
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil, nil, 0, 0)

if !conf.disableWeb {
compactorView := ui.NewBucketUI(logger, conf.webConfig.externalPrefix, conf.webConfig.prefixHeaderName, conf.component)
Expand Down
2 changes: 1 addition & 1 deletion cmd/thanos/tools_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ func registerBucketWeb(app extkingpin.AppClause, objStoreConfig *extflag.PathOrC
router = router.WithPrefix(tbc.webRoutePrefix)
}

ins := extpromhttp.NewInstrumentationMiddleware(reg, nil)
ins := extpromhttp.NewInstrumentationMiddleware(reg, nil, nil, 0, 0)

bucketUI := ui.NewBucketUI(logger, tbc.webExternalPrefix, tbc.webPrefixHeaderName, component.Bucket)
bucketUI.Register(router, ins)
Expand Down
4 changes: 2 additions & 2 deletions pkg/extprom/http/instrument_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ type defaultInstrumentationMiddleware struct {

// NewInstrumentationMiddleware provides default InstrumentationMiddleware.
// Passing nil as buckets uses the default buckets.
func NewInstrumentationMiddleware(reg prometheus.Registerer, buckets []float64) InstrumentationMiddleware {
func NewInstrumentationMiddleware(reg prometheus.Registerer, durationBuckets []float64, bytesBuckets []float64, bucketFactor float64, maxBuckets uint32) InstrumentationMiddleware {
return &defaultInstrumentationMiddleware{
metrics: newDefaultMetrics(reg, buckets, []string{}),
metrics: newDefaultMetrics(reg, durationBuckets, bytesBuckets, bucketFactor, maxBuckets, []string{}),
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/extprom/http/instrument_tenant_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ type tenantInstrumentationMiddleware struct {
// NewTenantInstrumentationMiddleware provides the same instrumentation as defaultInstrumentationMiddleware,
// but with a tenant label fetched from the given tenantHeaderName header.
// Passing nil as buckets uses the default buckets.
func NewTenantInstrumentationMiddleware(tenantHeaderName string, reg prometheus.Registerer, buckets []float64) InstrumentationMiddleware {
func NewTenantInstrumentationMiddleware(tenantHeaderName string, reg prometheus.Registerer, durationBuckets []float64, bytesBuckets []float64, bucketFactor float64, maxBuckets uint32) InstrumentationMiddleware {
return &tenantInstrumentationMiddleware{
tenantHeaderName: tenantHeaderName,
metrics: newDefaultMetrics(reg, buckets, []string{"tenant"}),
metrics: newDefaultMetrics(reg, durationBuckets, bytesBuckets, bucketFactor, maxBuckets, []string{"tenant"}),
}
}

Expand Down
52 changes: 36 additions & 16 deletions pkg/extprom/http/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,48 @@ import (

type defaultMetrics struct {
requestDuration *prometheus.HistogramVec
requestSize *prometheus.SummaryVec
requestSize *prometheus.HistogramVec
requestsTotal *prometheus.CounterVec
responseSize *prometheus.SummaryVec
responseSize *prometheus.HistogramVec
inflightHTTPRequests *prometheus.GaugeVec
}

func newDefaultMetrics(reg prometheus.Registerer, buckets []float64, extraLabels []string) *defaultMetrics {
if buckets == nil {
buckets = []float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120, 240, 360, 720}
func newDefaultMetrics(reg prometheus.Registerer, durationBuckets []float64, bytesBuckets []float64, bucketFactor float64, maxBuckets uint32, extraLabels []string) *defaultMetrics {
if durationBuckets == nil {
durationBuckets = []float64{0.001, 0.01, 0.1, 0.3, 0.6, 1, 3, 6, 9, 20, 30, 60, 90, 120, 240, 360, 720}
}

if bytesBuckets == nil {
bytesBuckets = prometheus.ExponentialBuckets(64, 2, 10)
}

if bucketFactor == 0 {
bucketFactor = 1.1
}

if maxBuckets == 0 {
maxBuckets = 100
}

return &defaultMetrics{
requestDuration: promauto.With(reg).NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_duration_seconds",
Help: "Tracks the latencies for HTTP requests.",
Buckets: buckets,
Name: "http_request_duration_seconds",
Help: "Tracks the latencies for HTTP requests.",
Buckets: durationBuckets,
NativeHistogramBucketFactor: bucketFactor,
NativeHistogramMaxBucketNumber: maxBuckets,
},
append([]string{"code", "handler", "method"}, extraLabels...),
),

requestSize: promauto.With(reg).NewSummaryVec(
prometheus.SummaryOpts{
Name: "http_request_size_bytes",
Help: "Tracks the size of HTTP requests.",
requestSize: promauto.With(reg).NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_request_size_bytes",
Help: "Tracks the size of HTTP requests.",
Buckets: bytesBuckets,
NativeHistogramBucketFactor: bucketFactor,
NativeHistogramMaxBucketNumber: maxBuckets,
},
append([]string{"code", "handler", "method"}, extraLabels...),
),
Expand All @@ -47,10 +64,13 @@ func newDefaultMetrics(reg prometheus.Registerer, buckets []float64, extraLabels
append([]string{"code", "handler", "method"}, extraLabels...),
),

responseSize: promauto.With(reg).NewSummaryVec(
prometheus.SummaryOpts{
Name: "http_response_size_bytes",
Help: "Tracks the size of HTTP responses.",
responseSize: promauto.With(reg).NewHistogramVec(
prometheus.HistogramOpts{
Name: "http_response_size_bytes",
Help: "Tracks the size of HTTP responses.",
Buckets: bytesBuckets,
NativeHistogramBucketFactor: bucketFactor,
NativeHistogramMaxBucketNumber: maxBuckets,
},
append([]string{"code", "handler", "method"}, extraLabels...),
),
Expand Down
3 changes: 3 additions & 0 deletions pkg/receive/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ func NewHandler(logger log.Logger, o *Options) *Handler {
o.TenantHeader,
o.Registry,
[]float64{0.001, 0.005, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1, 0.25, 0.5, 0.75, 1, 2, 3, 4, 5},
nil,
0,
0,
)
}

Expand Down

0 comments on commit 02af6f1

Please sign in to comment.