-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bring back RED metrics for querier when processing scheduler requests. (
#11097) **What this PR does / why we need it**: A previous change removed the RED metrics for the querier. This adds them back as part of a middleware. **Checklist** - [ ] Reviewed the [`CONTRIBUTING.md`](https://github.com/grafana/loki/blob/main/CONTRIBUTING.md) guide (**required**) - [ ] Documentation added - [ ] Tests updated - [ ] `CHANGELOG.md` updated - [ ] If the change is worth mentioning in the release notes, add `add-to-release-notes` label - [ ] Changes that require user attention or interaction to upgrade are documented in `docs/sources/setup/upgrade/_index.md` - [ ] For Helm chart changes bump the Helm chart version in `production/helm/loki/Chart.yaml` and update `production/helm/loki/CHANGELOG.md` and `production/helm/loki/README.md`. [Example PR](d10549e) - [ ] If the change is deprecating or removing a configuration option, update the `deprecated-config.yaml` and `deleted-config.yaml` files respectively in the `tools/deprecated-config-checker` directory. [Example PR](0d4416a)
- Loading branch information
Showing
4 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package queryrange | ||
|
||
import ( | ||
"context" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/grafana/dskit/httpgrpc" | ||
"github.com/grafana/dskit/instrument" | ||
"github.com/grafana/dskit/middleware" | ||
|
||
"github.com/grafana/dskit/server" | ||
|
||
"github.com/grafana/loki/pkg/querier/queryrange/queryrangebase" | ||
) | ||
|
||
const ( | ||
method = "GET" | ||
) | ||
|
||
type Instrument struct { | ||
*server.Metrics | ||
} | ||
|
||
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 := DefaultCodec.Path(r) | ||
route = middleware.MakeLabelValue(route) | ||
inflight := i.InflightRequests.WithLabelValues(method, route) | ||
inflight.Inc() | ||
defer inflight.Dec() | ||
|
||
begin := time.Now() | ||
result, err := next.Do(ctx, r) | ||
i.observe(ctx, route, err, time.Since(begin)) | ||
|
||
return result, err | ||
}) | ||
} | ||
|
||
func (i Instrument) observe(ctx context.Context, route string, err error, duration time.Duration) { | ||
respStatus := "200" | ||
if err != nil { | ||
if errResp, ok := httpgrpc.HTTPResponseFromError(err); ok { | ||
respStatus = strconv.Itoa(int(errResp.Code)) | ||
} else { | ||
respStatus = "500" | ||
} | ||
} | ||
instrument.ObserveWithExemplar(ctx, i.RequestDuration.WithLabelValues(method, route, respStatus, "false"), duration.Seconds()) | ||
} |