-
Notifications
You must be signed in to change notification settings - Fork 820
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
Add HTTP endpoint to show overrides (#1324) #3639
Conversation
There was a problem hiding this 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.
pkg/api/handlers.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
b24a71b
to
6e3e7ff
Compare
@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 |
There was a problem hiding this 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?
docs/api/_index.md
Outdated
GET /runtime_config | ||
``` | ||
|
||
Displays the runtime configuration currently applied to Cortex (in YAML format), including default values. |
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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)"
pkg/cortex/modules.go
Outdated
return serv, err | ||
} | ||
|
||
func (t *Cortex) initOverrides() (serv services.Service, err error) { | ||
t.Overrides, err = validation.NewOverrides(t.Cfg.LimitsConfig, tenantLimitsFromRuntimeConfig(t.RuntimeConfig)) | ||
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
Can we mention new |
There was a problem hiding this 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 🙏
pkg/api/handlers.go
Outdated
@@ -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) { |
There was a problem hiding this comment.
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.
This doesn’t apply to runtime config. |
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>
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 |
Signed-off-by: Mario de Frutos <mario@defrutos.org>
febd992
to
6a515c2
Compare
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 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. |
There was a problem hiding this 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.
pkg/api/handlers.go
Outdated
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) |
There was a problem hiding this comment.
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.
docs/api/_index.md
Outdated
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`. |
There was a problem hiding this comment.
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>
@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 :-) |
Thank you for addressing my feedback! |
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
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]