Skip to content

Add HTTP endpoint to show overrides (#1324) #3639

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

Merged

Conversation

ethervoid
Copy link
Contributor

What this PR does:

This PR introduces a new endpoint that would retrieve the override configuration, per tenant, that is loaded as part of the runtime configuration

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

Checklist

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

Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thanks for your PR! It looks good, I've left some comments to check before we can merge.

@@ -131,6 +132,22 @@ func configHandler(cfg interface{}) http.HandlerFunc {
}
}

func overridesHandler(runtimeCfgManager *runtimeconfig.Manager) http.HandlerFunc {
return func(w http.ResponseWriter, r *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.

Can we refactor common code for writing YAML response to util package? (see util.WriteJSONResponse)

Copy link
Contributor

Choose a reason for hiding this comment

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

Please note that this has now been done in #3645 too. To avoid duplicate work, it may be good idea to rebase on top of recent master, once #3645 is merged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Great, thank you for pointing me to the new change. I'll wait until that PR is merged to make the rebase

Copy link
Contributor

Choose a reason for hiding this comment

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

I just merged #3645, so you can rebase master and just use that helper.

@ethervoid ethervoid force-pushed the issue_1324_overrides_endpoint branch 2 times, most recently from b24a71b to 6e3e7ff Compare January 7, 2021 18:32
@ethervoid
Copy link
Contributor Author

@pstibrany I've made the requested changes but I'm waiting for the mentioned PR to be merged to do the last one referring to the refactoring of the YAML response code

Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thank you, this looks good. One more detail that may be worth handling: if runtimeCfgManager.GetConfig() in the handler returns nil (which can happen if you define -runtime-config.file but file doesn't exist, then the output of /runtime_config is just "null". Perhaps some message like "runtime config file doesn't exist" would be more appropriate?

GET /runtime_config
```

Displays the runtime configuration currently applied to Cortex (in YAML format), including default values.
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a note saying that if Cortex is not configured with any -runtime-config.file, then this will not be available.

pkg/api/api.go Outdated
@@ -7,6 +7,8 @@ import (
"strings"
"time"

"github.com/cortexproject/cortex/pkg/util/runtimeconfig"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: this should go between cortex imports, and not be standalone.

pkg/api/api.go Outdated
@@ -174,6 +176,13 @@ func (a *API) RegisterAPI(httpPathPrefix string, cfg interface{}) {
a.RegisterRoute("/debug/fgprof", fgprof.Handler(), false, "GET")
}

// RegisterRuntimeConfig registers the endpoints associates with the runtime configuration
func (a *API) RegisterRuntimeConfig(runtimeCfgManager *runtimeconfig.Manager) {
a.indexPage.AddLink(SectionAdminEndpoints, "/runtime_config", "Current Runtime Config")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd mention it includes overrides too: "Current Runtime Config (incl. Overrides)"

return serv, err
}

func (t *Cortex) initOverrides() (serv services.Service, err error) {
t.Overrides, err = validation.NewOverrides(t.Cfg.LimitsConfig, tenantLimitsFromRuntimeConfig(t.RuntimeConfig))

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extra empty line added

CHANGELOG.md Outdated
@@ -25,6 +25,7 @@
* [ENHANCEMENT] Compactor: tenants marked for deletion will now be fully cleaned up after some delay since deletion of last block. Cleanup includes removal of remaining marker files (including tenant deletion mark file) and files under `debug/metas`. #3613
* [ENHANCEMENT] Compactor: retry compaction of a single tenant on failure instead of re-running compaction for all tenants. #3627
* [ENHANCEMENT] Querier: Implement result caching for tenant query federation. #3640
* [ENHANCEMENT] New /runtime_config endpoint that returns the defined runtime configuration in YAML format. #3639
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also mention that it includes overrides here.

@pstibrany
Copy link
Contributor

Can we mention new /runtime_config endpoint in docs/configuration/arguments.md file ("Runtime Configuration file" section) too?

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.

Pretty cool! LGTM, modulo Peter's feedback.

In a separate PR, would be fantastic if you could also add the mode=diff support like in #3645 because it's a bit hard to read the output due to the large quantity of default valued fields. If you don't, please open an issue to leave it for someone else 🙏

@@ -131,6 +132,22 @@ func configHandler(cfg interface{}) http.HandlerFunc {
}
}

func overridesHandler(runtimeCfgManager *runtimeconfig.Manager) http.HandlerFunc {
return func(w http.ResponseWriter, r *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.

I just merged #3645, so you can rebase master and just use that helper.

@pstibrany
Copy link
Contributor

In a separate PR, would be fantastic if you could also add the mode=diff support like in #3645 because it's a bit hard to read the output due to the large quantity of default valued fields. If you don't, please open an issue to leave it for someone else 🙏

This doesn’t apply to runtime config. /runtime_config only shows your changes (yaml file) nothing else.

This PR introduces a new endpoint that would retrieve the override
configuration, per tenant, that is loaded as part of the runtime
configuration

Signed-off-by: Mario de Frutos <mario@defrutos.org>
Signed-off-by: Mario de Frutos <mario@defrutos.org>
Signed-off-by: Mario de Frutos <mario@defrutos.org>
Signed-off-by: Mario de Frutos <mario@defrutos.org>
Signed-off-by: Mario de Frutos <mario@defrutos.org>
@ethervoid
Copy link
Contributor Author

I"ve been checking about the diff option and looks like we're setting the default values here to have it in the YAML unmarshal operation so I think we can add a diff option but it would be only for the overrides part

Signed-off-by: Mario de Frutos <mario@defrutos.org>
@ethervoid ethervoid force-pushed the issue_1324_overrides_endpoint branch from febd992 to 6a515c2 Compare January 8, 2021 19:33
@ethervoid ethervoid requested a review from pstibrany January 8, 2021 19:34
@pstibrany
Copy link
Contributor

pstibrany commented Jan 8, 2021

This doesn’t apply to runtime config. /runtime_config only shows your changes (yaml file) nothing else.

I am wrong about this. I tested this PR earlier today, but without actually setting any overrides 🤦 and just modifying other parts of runtime config.

I"ve been checking about the diff option and looks like we're setting the default values here to have it in the YAML unmarshal operation so I think we can add a diff option but it would be only for the overrides part

I think diff makes sense for entire runtime config, but is mostly interesting for overrides. However it is also somewhat tricky for overrides... when diffing, each per-tenant override should be diffed against default limits individually, and not the whole structure.

As Marco suggested, let's leave that for another PR to get this merged.

Copy link
Contributor

@pstibrany pstibrany left a comment

Choose a reason for hiding this comment

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

Thanks for patiently addressing our feedback. Let’s fix the nil case, and merge.

return func(w http.ResponseWriter, r *http.Request) {
runtimeConfig := runtimeCfgManager.GetConfig()
if runtimeConfig == nil {
http.Error(w, "runtime config file doesn't exist", http.StatusInternalServerError)
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn’t error, it just means that overrides file is empty or doesn’t exist. Both are perfectly fine. Writing text message with code 200 is preferred.

GET /runtime_config
```

Displays the runtime configuration currently applied to Cortex (in YAML format), including default values. Please be aware that the configuration will be available only if Cortex is configured with a valid `-runtime-config.file`.
Copy link
Contributor

Choose a reason for hiding this comment

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

-runtime-config.file option must be set for this endpoint to be available, but actual file doesn’t need to exist or be valid. But that’s just nitpicking.

Signed-off-by: Mario de Frutos <mario@defrutos.org>
@ethervoid
Copy link
Contributor Author

@pstibrany I think that's all. I want to thank you for your amazing patiente guiding me and providing really valuable feedback. I've learn a lot about the the project and the way the thins are done so I can be more accurate for future PRs :-)

@pstibrany
Copy link
Contributor

Thank you for addressing my feedback!

@pstibrany pstibrany merged commit 363eed8 into cortexproject:master Jan 11, 2021
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.

Idea: Add HTTP endpoint to show overrides.
3 participants