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

Separate HTTP Instrumentation for Querier #2708

Merged
merged 7 commits into from
Jun 17, 2020

Conversation

jtlisi
Copy link
Contributor

@jtlisi jtlisi commented Jun 10, 2020

What this PR does:

When running cortex as a single binary the requests processed by the querier are not instrumented. This PR adds a separate histogram metric cortex_querier_request_duration_seconds that allows the operator to make this distinction.

The metric is registered in both single binary and microservice mode. This will allow the new metric to be used for dashboards/panels in both modes.

Which issue(s) this PR fixes:
Fixes #2707

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

Signed-off-by: Jacob Lisi <jacob.t.lisi@gmail.com>
Signed-off-by: Jacob Lisi <jacob.t.lisi@gmail.com>
Signed-off-by: Jacob Lisi <jacob.t.lisi@gmail.com>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

Thanks @jtlisi for working on it. I see the need for it! I left few comments: could you take a look, please?

Could you also add a CHANGELOG entry, please?

pkg/api/api.go Outdated
// Ensure the encoded path is used. Required for the rules API
s.HTTP.UseEncodedPath()

// Prometheus histograms for requests.
querierRequestDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{
Copy link
Contributor

Choose a reason for hiding this comment

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

You can simply use promauto.With(reg).NewHistogramVec().

pkg/api/api.go Outdated
// RegisterQueryAPI registers the Prometheus routes supported by the
// Cortex querier service. Currently this can not be registered simultaneously
// with the Querier.
func (a *API) RegisterQueryAPI(handler http.Handler) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this refactoring related to the scope of the PR? I'm not against it if you need it in a project vendoring Cortex but, if it's not required, probably the previous version was more clear.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you comment on this? I'm fine if you need it in a project vendoring Cortex, otherwise the previous version looks more explicit to me.

pkg/api/api.go Outdated
// Ensure the encoded path is used. Required for the rules API
s.HTTP.UseEncodedPath()

// Prometheus histograms for requests.
querierRequestDuration := prometheus.NewHistogramVec(prometheus.HistogramOpts{
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you considered moving this to RegisterQuerier()? The metric would be registered only if RegisterQuerier() is used and the change isolated there.

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 wanted to avoid passing a prometheus.Registerer to that function. However, maybe it would make more sense to store the Registerer in the API struct and and initiate the metric is in the RegisterQuerier function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, or you can pass the metric itself to the RegisterQuerier() (ie. in Thanos it's quite a common design pattern).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Cool I updated it to pass a metric as a parameter.

Signed-off-by: Jacob Lisi <jacob.t.lisi@gmail.com>
Signed-off-by: Jacob Lisi <jacob.t.lisi@gmail.com>
Signed-off-by: Jacob Lisi <jacob.t.lisi@gmail.com>
Copy link
Contributor

@pracucci pracucci left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! I just left a non-blocking question.

pkg/api/api.go Outdated
// RegisterQueryAPI registers the Prometheus routes supported by the
// Cortex querier service. Currently this can not be registered simultaneously
// with the Querier.
func (a *API) RegisterQueryAPI(handler http.Handler) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you comment on this? I'm fine if you need it in a project vendoring Cortex, otherwise the previous version looks more explicit to me.

@jtlisi
Copy link
Contributor Author

jtlisi commented Jun 16, 2020

#2708 (comment)

I don't have any particular use case for that function. It came about when I was expirementing with alternative ways of solving the "separate querier instrumentation" problem. I kept it because I thought it looked cleaner. However, I can return it to it's previous form if you fell otherwise.

@pracucci
Copy link
Contributor

pracucci commented Jun 16, 2020 via email

Signed-off-by: Jacob Lisi <jacob.t.lisi@gmail.com>
@pracucci pracucci merged commit e3221b2 into master Jun 17, 2020
@tomwilkie tomwilkie deleted the 20200610_separate_instrumentation_querier branch April 27, 2021 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Querier API Metrics are not reported when running in Single-Binary mode
2 participants