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

Instrument querier inflight requests. #11085

Merged
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
12 changes: 11 additions & 1 deletion pkg/loki/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,10 +513,20 @@ func (t *Loki) initQuerier() (services.Service, error) {
t.Server.HTTP.Path("/loki/api/v1/tail").Methods("GET", "POST").Handler(httpMiddleware.Wrap(http.HandlerFunc(t.querierAPI.TailHandler)))
t.Server.HTTP.Path("/api/prom/tail").Methods("GET", "POST").Handler(httpMiddleware.Wrap(http.HandlerFunc(t.querierAPI.TailHandler)))

internalHandler := queryrangebase.MergeMiddlewares(
serverutil.RecoveryMiddleware,
queryrange.Instrument{
QueryHandlerMetrics: queryrange.NewQueryHandlerMetrics(
prometheus.DefaultRegisterer,
t.Cfg.MetricsNamespace,
),
},
).Wrap(handler)

svc, err := querier.InitWorkerService(
querierWorkerServiceConfig,
prometheus.DefaultRegisterer,
serverutil.RecoveryMiddleware.Wrap(handler),
internalHandler,
t.Codec,
)
if err != nil {
Expand Down
47 changes: 47 additions & 0 deletions pkg/querier/queryrange/instrument.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package queryrange

import (
"context"
"fmt"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"

"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase"
)

const (
gRPC = "gRPC"
)

type QueryHandlerMetrics struct {
InflightRequests *prometheus.GaugeVec
}

func NewQueryHandlerMetrics(registerer prometheus.Registerer, metricsNamespace string) *QueryHandlerMetrics {
return &QueryHandlerMetrics{
InflightRequests: promauto.With(registerer).NewGaugeVec(prometheus.GaugeOpts{
Namespace: metricsNamespace,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we set this to loki?

metricsNamespace was added for migrating metrics that were using cortex prefix. But in this case it was already set to loki I believe, so there is no need to make the prefix configurable now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should stay flexible but thanks for the notice.

Name: "inflight_requests",
Help: "Current number of inflight requests.",
}, []string{"method", "route"}),
}
}

type Instrument struct {
*QueryHandlerMetrics
}

var _ queryrangebase.Middleware = Instrument{}

// Wrap implements the queryrangebase.Middleware
func (i Instrument) Wrap(next queryrangebase.Handler) queryrangebase.Handler {
return queryrangebase.HandlerFunc(func(ctx context.Context, r queryrangebase.Request) (queryrangebase.Response, error) {
route := fmt.Sprintf("%T", r)
inflight := i.InflightRequests.WithLabelValues(gRPC, route)
inflight.Inc()
defer inflight.Dec()

return next.Do(ctx, r)
})
}
1 change: 0 additions & 1 deletion tools/dev/loki-boltdb-storage-s3/config/loki.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ storage_config:
cache_location: /data/boltdb-cache
index_gateway_client:
server_address: index-gateway:9008
shared_store: s3
aws:
s3: s3://loki:supersecret@minio:9000/loki
s3forcepathstyle: true
Expand Down
Loading