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

query-tee: add per-backend request headers #10081

Merged

Conversation

dimitarvdimitrov
Copy link
Contributor

What this PR does

One of my backends needs a specific header so that it returns "correct" results.

Currently we don't have a way to add per-backend configuration. This PR introduces a new flag which takes JSON and allows to configure each backend separately. It will be used like so

-backend.config='{"mimir.com": {"request_headers": "X-Some-Header": ["value1", "value2"]}}'

I'm open to suggestions in case this is not a route we want to go on.

Which issue(s) this PR fixes or relates to

Fixes #

Checklist

  • Tests updated.
  • Documentation added.
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX].
  • about-versioning.md updated with experimental features.

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@dimitarvdimitrov dimitarvdimitrov requested a review from a team as a code owner December 2, 2024 11:00
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@charleskorn
Copy link
Contributor

What if we used a YAML config file instead? Putting JSON into a CLI flag feels a little awkward.

@dimitarvdimitrov
Copy link
Contributor Author

What if we used a YAML config file instead? Putting JSON into a CLI flag feels a little awkward.

that will make setting this up a bit hard. I'm thinking about the additional jsonnet to create a config map and mount it. But I'm not opposed, so I'll draft that

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@dimitarvdimitrov
Copy link
Contributor Author

What if we used a YAML config file instead? Putting JSON into a CLI flag feels a little awkward.

that will make setting this up a bit hard. I'm thinking about the additional jsonnet to create a config map and mount it. But I'm not opposed, so I'll draft that

see 3ce31d1

tools/querytee/proxy.go Show resolved Hide resolved
tools/querytee/proxy.go Show resolved Hide resolved
@charleskorn
Copy link
Contributor

Something for a future PR, not this one: would be good to move some of the config to the config file as well (eg. configuring the proportion of requests sent to a secondary backend per backend, rather than for all secondary backends).

@dimitarvdimitrov
Copy link
Contributor Author

configuring the proportion of requests sent to a secondary backend per backend, rather than for all secondary backends

I thought about this and I'm not sure if it's compatible with results comparisons: we need the same sampling rate for all backends and the primary in order to compare results. I think it doesn't work for us.

Let's keep discussing though. I'll merge this PR so we have something in the weekly next week

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Copy link
Contributor

@zenador zenador left a comment

Choose a reason for hiding this comment

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

LGTM in general, approving first to unblock since we want to merge this soon and Charles has already reviewed it

tools/querytee/proxy.go Show resolved Hide resolved
@@ -84,7 +84,7 @@ func Test_ProxyBackend_createBackendRequest_HTTPBasicAuthentication(t *testing.T
orig.Header.Set("X-Scope-OrgID", testData.clientTenant)
}

b := NewProxyBackend("test", u, time.Second, false, false)
b := NewProxyBackend("test", u, time.Second, false, false, BackendConfig{})
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Do you think we should have a defaultBackendConfig() instead (we can set it to return BackendConfig{} for now) or is it unlikely that we'll ever need to set some values as default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah let's try that. pushed in 44c8d42

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
@dimitarvdimitrov dimitarvdimitrov enabled auto-merge (squash) December 6, 2024 15:30
@dimitarvdimitrov dimitarvdimitrov merged commit 31d91bc into main Dec 6, 2024
29 checks passed
@dimitarvdimitrov dimitarvdimitrov deleted the dimitar/query-tee/add-per-backend-configuration branch December 6, 2024 15:46
bjorns163 pushed a commit to bjorns163/mimir that referenced this pull request Dec 30, 2024
* Add tests

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Add headers to proxy

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Add CHANGELOG.md entry

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Use YAML config instead

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Add comment for why we allow choosing by index too

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Validate list of backends

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Add util function for BackendConfig

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

* Fix validation

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>

---------

Signed-off-by: Dimitar Dimitrov <dimitar.dimitrov@grafana.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants