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

Loki: Implement custom /config handler #4785

Merged
merged 2 commits into from
Nov 26, 2021

Conversation

DylanGuedes
Copy link
Contributor

What this PR does / why we need it:

  • Creates a new RunOpts used by Loki internally to customize running behavior. It is used in this PR to customize how to handle /config endpoint and can be used later to customize other behaviors.

Which issue(s) this PR fixes:
N/A

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated
  • Add an entry in the CHANGELOG.md about the changes.

@DylanGuedes DylanGuedes requested a review from a team as a code owner November 18, 2021 19:55
@DylanGuedes DylanGuedes force-pushed the custom-config-handler branch from e005d45 to 7a25335 Compare November 18, 2021 20:13
@DylanGuedes DylanGuedes force-pushed the custom-config-handler branch from 7a25335 to aaaeb4c Compare November 18, 2021 20:22
pkg/loki/loki.go Outdated
type RunOpts struct {
// customConfigEndpointHandlerFn is the handlerFunc to be used by the /config endpoint.
// If empty, default handlerFunc will be used.
customConfigEndpointHandlerFn func(http.ResponseWriter, *http.Request)
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 export it to allow defining custom values? Without that, I do not see a way to change the behaviour outside of loki package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, good point. I'll make it public then.

type RunOpts struct {
// CustomConfigEndpointHandlerFn is the handlerFunc to be used by the /config endpoint.
// If empty, default handlerFunc will be used.
CustomConfigEndpointHandlerFn func(http.ResponseWriter, *http.Request)
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, why is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Without this, other projects (ex: GEL) aren't able to customize the /config endpoint. That's a problem for projects that uses a superset of configurations that include Loki configs because their configs that aren't part of Loki aren't shown in the /config endpoint.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a very good point. It relates to https://github.com/grafana/loki-private/issues/96 though 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it has some relation to it.

CustomConfigEndpointHandlerFn func(http.ResponseWriter, *http.Request)
}

func (t *Loki) bindConfigEndpoint(opts RunOpts) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@MichelHollands Sounds like something you could have used.

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

LGTM

@cyriltovena cyriltovena merged commit 347e3e3 into grafana:main Nov 26, 2021
ssncferreira pushed a commit that referenced this pull request Jan 7, 2022
* Implement custom /config handler.

* Make `customConfigEndpointHandlerFn` public.
slim-bean pushed a commit that referenced this pull request Jan 7, 2022
* Implement custom /config handler.

* Make `customConfigEndpointHandlerFn` public.

Co-authored-by: Dylan Guedes <djmgguedes@gmail.com>
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.

4 participants