-
Notifications
You must be signed in to change notification settings - Fork 812
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
API Implementation #2372
API Implementation #2372
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.
Good job @jtlisi. It quite a tricky PR to review to accurately find if breaking changes have been introduced. I've left some comments and questions, but overall the design looks good to me.
I also have few more comments:
- Could you update
docs/apis.md
accordingly, please? - What's the impact of these changes on Loki?
- Can you also reflect the changes in the CHANGELOG? Ie. I noticed these changes (but there are probably more):
- Alertmanager:
/status
is available only when running in microservices mode and the target is the alertmanager - Ruler:
/ruler_ring
>/ruler/ring
- Alertmanager:
@@ -98,6 +90,22 @@ func (m *ModuleName) UnmarshalYAML(unmarshal func(interface{}) error) error { | |||
return m.Set(s) | |||
} | |||
|
|||
func (t *Cortex) initAPI(cfg *Config) (services.Service, error) { | |||
cfg.API.ServerPrefix = cfg.Server.PathPrefix | |||
cfg.API.LegacyHTTPPrefix = cfg.HTTPPrefix |
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 is potentially a breaking change. If an user has customised HTTPPrefix
, the behaviour will be different, because for most of the routes before the /api/prom
was hard-coded while now it's always based on HTTPPrefix
. Should be at least mentioned in the CHANGELOG as CHANGE
, but not sure if it breaks the 1.0.0 stability guarantees.
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'm not sure either. I always felt it was an issue if not a bug that services did not respect the configured prefix. I will add a line in the changelog explaining the change in behaviour. However, I don't think this goes against any of our 1.0 guarantees:
Additional API endpoints for management of Cortex itself, such as the ring. These APIs are not part of the any compatibility guarantees.
0fb552c
to
0295435
Compare
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Co-Authored-By: Marco Pracucci <[email protected]> Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
eec97a3
to
4dabad2
Compare
Signed-off-by: Jacob Lisi <[email protected]>
pkg/api/api.go
Outdated
handler = a.authMiddleware.Wrap(handler) | ||
} | ||
if len(methods) == 0 { | ||
a.server.HTTP.Path(path).Handler(handler) |
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.
a.server.HTTP.Path()
> a.server.HTTP.PathPrefix()
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.
Sorry about that, I was just looking into the failed integration tests and that looked to be the issue. Also the primary reason for not explicitly registering the alertmanager routes is because the Alertmanager UI routing is relatively complex and I didn't want to handle it in this PR. I also think it is fine to serve the Alertmanager directly if it is routed under the /alertmanager/
prefix.
// RegisterDistributor registers the endpoints associated with the distributor. | ||
func (a *API) RegisterDistributor(d *distributor.Distributor, pushConfig distributor.Config) { | ||
a.registerRoute("/api/v1/push", push.Handler(pushConfig, d.Push), true) | ||
a.registerRoute("/distributor/all_user_stats", http.HandlerFunc(d.AllUserStatsHandler), false) |
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.
Then I think all new routes should use underscores (I also prefer dashes, but my personal preference doesn't matter when it breaks consistency, so agree on underscores).
pkg/api/api.go
Outdated
a.server.HTTP.Path(path).Methods(methods...).Handler(handler) | ||
} | ||
|
||
func (a *API) registerRoutesWithPrefix(path string, handler http.Handler, auth bool, methods ...string) { |
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 rename path
to prefix
to make it clearer
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.
👍
@@ -62,6 +62,15 @@ Where default_value is the value to use if the environment variable is undefined | |||
# CLI flag: -http.prefix | |||
[http_prefix: <string> | default = "/api/prom"] | |||
|
|||
api: | |||
# Base path for data storage. |
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.
Remember to address this.
Signed-off-by: Jacob Lisi <[email protected]>
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 @jtlisi for addressing my feedback. I've few more minor comments. May you also look at the failing lint and integration tests, please?
Signed-off-by: Jacob Lisi <[email protected]>
I just wanted to circle back and address:
I don't know if that is worth addressing since there is no current way to run the alertmanager in the single binary. Even after this PR that functionality has not been enabled. |
Signed-off-by: Jacob Lisi <[email protected]>
🤦♂ You're definitely right. All good on this 👍 |
Signed-off-by: Jacob Lisi <[email protected]>
Signed-off-by: Jacob Lisi <[email protected]>
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.
Good job @jtlisi! LGTM. I just left few minor nits. Would be great to update the docs/apis.md
(not necessarily in this PR, we can do in a subsequent one, but would be great doing it).
CHANGELOG.md
Outdated
@@ -2,6 +2,9 @@ | |||
|
|||
## master / unreleased | |||
|
|||
* [CHANGE] Added v1 API routes documented in #2327. #2372 | |||
* Added `-http.alertmanager-http-prefix` and `http.prometheus-http-prefix` flags. |
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.
* Added `-http.alertmanager-http-prefix` and `http.prometheus-http-prefix` flags. | |
* Added `-http.alertmanager-http-prefix` and `-http.prometheus-http-prefix` flags. |
@@ -2,6 +2,9 @@ | |||
|
|||
## master / unreleased | |||
|
|||
* [CHANGE] Added v1 API routes documented in #2327. #2372 | |||
* Added `-http.alertmanager-http-prefix` and `http.prometheus-http-prefix` flags. | |||
* Updated the index hosted at the root prefix to point to the updated routes. |
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.
Could you try to make it more clear? I think it's a bit difficult to understand for the final user.
CHANGELOG.md
Outdated
* [CHANGE] Added v1 API routes documented in #2327. #2372 | ||
* Added `-http.alertmanager-http-prefix` and `http.prometheus-http-prefix` flags. | ||
* Updated the index hosted at the root prefix to point to the updated routes. | ||
* Legacy routes hardcoded with the `/api/prom` prefix now respect the `http.prefix` flag. |
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.
* Legacy routes hardcoded with the `/api/prom` prefix now respect the `http.prefix` flag. | |
* Legacy routes hardcoded with the `/api/prom` prefix now respect the `-http.prefix` flag. |
Signed-off-by: Jacob Lisi <[email protected]>
What this PR does:
This is the implementation associated with the design document in #2327.
In this implementation the API struct mainly just handles routing for Cortex. In the future this package will centralize non-component based handlers and create a set of functions and structs that can be reused by Cortex handlers to make the API consistent.
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]