From 0a10ae724a59ef888d9530499967d5aacf0cfae0 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Wed, 22 Jun 2022 19:06:31 +0200 Subject: [PATCH 1/4] Remove deprecated ruler endpoints Removes /api/v1/rules* and /prometheus/rules* endpoints in preparation for the 2.2.0 release. Replaces their usages throughout the repo with /prometheus/config/v1/rules* Signed-off-by: Dimitar Dimitrov --- cmd/query-tee/main.go | 2 +- .../configuring/about-versioning.md | 3 -- .../reference-http-api/index.md | 36 ------------------- .../operators-guide/tools/query-tee.md | 2 +- integration/e2emimir/client.go | 10 +++--- integration/ruler_test.go | 11 +++--- .../helm/charts/mimir-distributed/values.yaml | 6 ---- .../templates/nginx/nginx-configmap.yaml | 6 ---- pkg/api/api.go | 18 ---------- pkg/mimirtool/client/client.go | 4 +-- pkg/mimirtool/client/client_test.go | 36 +++++++++---------- pkg/mimirtool/client/rules_test.go | 10 +++--- pkg/mimirtool/commands/rules.go | 2 +- pkg/ruler/api_test.go | 26 +++++++------- 14 files changed, 52 insertions(+), 120 deletions(-) diff --git a/cmd/query-tee/main.go b/cmd/query-tee/main.go index 632703c652..e651ad58b7 100644 --- a/cmd/query-tee/main.go +++ b/cmd/query-tee/main.go @@ -86,7 +86,7 @@ func mimirReadRoutes(cfg Config) []querytee.Route { {Path: prefix + "/api/v1/label/{name}/values", RouteName: "api_v1_label_name_values", Methods: []string{"GET", "POST"}, ResponseComparator: nil}, {Path: prefix + "/api/v1/series", RouteName: "api_v1_series", Methods: []string{"GET", "POST"}, ResponseComparator: nil}, {Path: prefix + "/api/v1/metadata", RouteName: "api_v1_metadata", Methods: []string{"GET", "POST"}, ResponseComparator: nil}, - {Path: prefix + "/api/v1/rules", RouteName: "api_v1_rules", Methods: []string{"GET", "POST"}, ResponseComparator: nil}, + {Path: prefix + "/prometheus/config/v1/rules", RouteName: "prometheus_config_v1_rules", Methods: []string{"GET", "POST"}, ResponseComparator: nil}, {Path: prefix + "/api/v1/alerts", RouteName: "api_v1_alerts", Methods: []string{"GET", "POST"}, ResponseComparator: nil}, } } diff --git a/docs/sources/operators-guide/configuring/about-versioning.md b/docs/sources/operators-guide/configuring/about-versioning.md index d459f9ca5d..c113726457 100644 --- a/docs/sources/operators-guide/configuring/about-versioning.md +++ b/docs/sources/operators-guide/configuring/about-versioning.md @@ -96,6 +96,3 @@ The following features are currently deprecated: - Ingester: - `-blocks-storage.tsdb.isolation-enabled` CLI flag and `isolation_enabled` YAML config parameter. This will be removed in version 2.3.0. - `active_series_custom_trackers` YAML config parameter in the ingester block. The configuration has been moved to limit config, the ingester config will be removed in version 2.3.0. -- Ruler: - - `/api/v1/rules/**` configuration endpoints. These will be removed in version 2.2.0. Use their `/config/v1/rules/**` equivalents instead. - - `/rules/**` configuration endpoints. These will be removed in version 2.2.0. Use their `/config/v1/rules/**` equivalents instead. diff --git a/docs/sources/operators-guide/reference-http-api/index.md b/docs/sources/operators-guide/reference-http-api/index.md index f02bdc9b37..a8f6d0c319 100644 --- a/docs/sources/operators-guide/reference-http-api/index.md +++ b/docs/sources/operators-guide/reference-http-api/index.md @@ -552,12 +552,6 @@ Requires [authentication](#authentication). ``` GET /config/v1/rules - -# Deprecated; will be removed in Mimir v2.2.0 -GET /api/v1/rules - -# Deprecated; will be removed in Mimir v2.2.0 -GET /rules ``` List all rules configured for the authenticated tenant. This endpoint returns a YAML dictionary with all the rule groups for each namespace and `200` status code on success. @@ -620,12 +614,6 @@ Requires [authentication](#authentication). ``` GET /config/v1/rules/{namespace} - -# Deprecated; will be removed in Mimir v2.2.0 -GET /api/v1/rules/{namespace} - -# Deprecated; will be removed in Mimir v2.2.0 -GET /rules/{namespace} ``` Returns the rule groups defined for a given namespace. @@ -657,12 +645,6 @@ rules: ``` GET /config/v1/rules/{namespace}/{groupName} - -# Deprecated; will be removed in Mimir v2.2.0 -GET /api/v1/rules/{namespace}/{groupName} - -# Deprecated; will be removed in Mimir v2.2.0 -GET /rules/{namespace}/{groupName} ``` Returns the rule group matching the request namespace and group name. @@ -675,12 +657,6 @@ Requires [authentication](#authentication). ``` POST //config/v1/rules/{namespace} - -# Deprecated; will be removed in Mimir v2.2.0 -POST /api/v1/rules/{namespace} - -# Deprecated; will be removed in Mimir v2.2.0 -POST /rules/{namespace} ``` Creates or updates a rule group. @@ -709,12 +685,6 @@ rules: ``` DELETE //config/v1/rules/{namespace}/{groupName} - -# Deprecated; will be removed in Mimir v2.2.0 -DELETE /api/v1/rules/{namespace}/{groupName} - -# Deprecated; will be removed in Mimir v2.2.0 -DELETE /rules/{namespace}/{groupName} ``` Deletes a rule group by namespace and group name. This endpoints returns `202` on success. @@ -727,12 +697,6 @@ Requires [authentication](#authentication). ``` DELETE //config/v1/rules/{namespace} - -# Deprecated; will be removed in Mimir v2.2.0 -DELETE /api/v1/rules/{namespace} - -# Deprecated; will be removed in Mimir v2.2.0 -DELETE /rules/{namespace} ``` Deletes all the rule groups in a namespace (including the namespace itself). This endpoint returns `202` on success. diff --git a/docs/sources/operators-guide/tools/query-tee.md b/docs/sources/operators-guide/tools/query-tee.md index efadd40286..b3ca317069 100644 --- a/docs/sources/operators-guide/tools/query-tee.md +++ b/docs/sources/operators-guide/tools/query-tee.md @@ -56,7 +56,7 @@ The following Prometheus API endpoints are supported by `query-tee`: - `GET /api/v1/series` - `GET /api/v1/metadata` - `GET /api/v1/alerts` -- `GET /api/v1/rules` +- `GET /prometheus/config/v1/rules` You can configure the `` by setting the `-server.path-prefix` flag, which defaults to an empty string. diff --git a/integration/e2emimir/client.go b/integration/e2emimir/client.go index 34789f8b0f..6cc9ef664e 100644 --- a/integration/e2emimir/client.go +++ b/integration/e2emimir/client.go @@ -310,7 +310,7 @@ func (c *Client) GetPrometheusRules() ([]*ruler.RuleGroup, error) { // GetRuleGroups gets the configured rule groups from the ruler. func (c *Client) GetRuleGroups() (map[string][]rulefmt.RuleGroup, error) { // Create HTTP request - req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/api/v1/rules", c.rulerAddress), nil) + req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/prometheus/config/v1/rules", c.rulerAddress), nil) if err != nil { return nil, err } @@ -350,7 +350,7 @@ func (c *Client) SetRuleGroup(rulegroup rulefmt.RuleGroup, namespace string) err } // Create HTTP request - req, err := http.NewRequest("POST", fmt.Sprintf("http://%s/api/v1/rules/%s", c.rulerAddress, url.PathEscape(namespace)), bytes.NewReader(data)) + req, err := http.NewRequest("POST", fmt.Sprintf("http://%s/prometheus/config/v1/rules/%s", c.rulerAddress, url.PathEscape(namespace)), bytes.NewReader(data)) if err != nil { return err } @@ -379,7 +379,7 @@ func (c *Client) SetRuleGroup(rulegroup rulefmt.RuleGroup, namespace string) err // GetRuleGroup gets a rule group. func (c *Client) GetRuleGroup(namespace string, groupName string) (*http.Response, error) { // Create HTTP request - req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/api/v1/rules/%s/%s", c.rulerAddress, url.PathEscape(namespace), url.PathEscape(groupName)), nil) + req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/prometheus/config/v1/rules/%s/%s", c.rulerAddress, url.PathEscape(namespace), url.PathEscape(groupName)), nil) if err != nil { return nil, err } @@ -397,7 +397,7 @@ func (c *Client) GetRuleGroup(namespace string, groupName string) (*http.Respons // DeleteRuleGroup deletes a rule group. func (c *Client) DeleteRuleGroup(namespace string, groupName string) error { // Create HTTP request - req, err := http.NewRequest("DELETE", fmt.Sprintf("http://%s/api/v1/rules/%s/%s", c.rulerAddress, url.PathEscape(namespace), url.PathEscape(groupName)), nil) + req, err := http.NewRequest("DELETE", fmt.Sprintf("http://%s/prometheus/config/v1/rules/%s/%s", c.rulerAddress, url.PathEscape(namespace), url.PathEscape(groupName)), nil) if err != nil { return err } @@ -421,7 +421,7 @@ func (c *Client) DeleteRuleGroup(namespace string, groupName string) error { // DeleteRuleNamespace deletes all the rule groups (and the namespace itself). func (c *Client) DeleteRuleNamespace(namespace string) error { // Create HTTP request - req, err := http.NewRequest("DELETE", fmt.Sprintf("http://%s/api/v1/rules/%s", c.rulerAddress, url.PathEscape(namespace)), nil) + req, err := http.NewRequest("DELETE", fmt.Sprintf("http://%s/prometheus/config/v1/rules/%s", c.rulerAddress, url.PathEscape(namespace)), nil) if err != nil { return err } diff --git a/integration/ruler_test.go b/integration/ruler_test.go index 61a8ca2c5c..5b12ead390 100644 --- a/integration/ruler_test.go +++ b/integration/ruler_test.go @@ -988,12 +988,17 @@ func TestRulerEnableAPIs(t *testing.T) { { name: "API is enabled", apiEnabled: true, - expectedRegisteredEndpoints: [][2]string{ // not going to test GET /api/v1/rules/my_namespace/my_group because it requires creating a rule group {http.MethodGet, "/prometheus/api/v1/alerts"}, {http.MethodGet, "/prometheus/api/v1/rules"}, + {http.MethodGet, "/prometheus/config/v1/rules"}, + {http.MethodGet, "/prometheus/config/v1/rules/my_namespace"}, + {http.MethodPost, "/prometheus/config/v1/rules/my_namespace"}, + }, + + expectedMissingEndpoints: [][2]string{ {http.MethodGet, "/api/v1/rules"}, {http.MethodGet, "/api/v1/rules/my_namespace"}, {http.MethodPost, "/api/v1/rules/my_namespace"}, @@ -1001,10 +1006,6 @@ func TestRulerEnableAPIs(t *testing.T) { {http.MethodGet, "/prometheus/rules"}, {http.MethodGet, "/prometheus/rules/my_namespace"}, {http.MethodPost, "/prometheus/rules/my_namespace"}, - - {http.MethodGet, "/prometheus/config/v1/rules"}, - {http.MethodGet, "/prometheus/config/v1/rules/my_namespace"}, - {http.MethodPost, "/prometheus/config/v1/rules/my_namespace"}, }, }, } diff --git a/operations/helm/charts/mimir-distributed/values.yaml b/operations/helm/charts/mimir-distributed/values.yaml index 2b8c06845a..59957b816f 100644 --- a/operations/helm/charts/mimir-distributed/values.yaml +++ b/operations/helm/charts/mimir-distributed/values.yaml @@ -1443,15 +1443,9 @@ nginx: proxy_pass http://{{ template "mimir.fullname" . }}-ruler.{{ .Release.Namespace }}.svc.{{ .Values.global.clusterDomain }}:{{ include "mimir.serverHttpListenPort" . }}$request_uri; } - location /api/v1/rules { - proxy_pass http://{{ template "mimir.fullname" . }}-ruler.{{ .Release.Namespace }}.svc.{{ .Values.global.clusterDomain }}:{{ include "mimir.serverHttpListenPort" . }}$request_uri; - } location {{ template "mimir.prometheusHttpPrefix" . }}/api/v1/alerts { proxy_pass http://{{ template "mimir.fullname" . }}-ruler.{{ .Release.Namespace }}.svc.{{ .Values.global.clusterDomain }}:{{ include "mimir.serverHttpListenPort" . }}$request_uri; } - location {{ template "mimir.prometheusHttpPrefix" . }}/rules { - proxy_pass http://{{ template "mimir.fullname" . }}-ruler.{{ .Release.Namespace }}.svc.{{ .Values.global.clusterDomain }}:{{ include "mimir.serverHttpListenPort" . }}$request_uri; - } location = /ruler/ring { proxy_pass http://{{ template "mimir.fullname" . }}-ruler.{{ .Release.Namespace }}.svc.{{ .Values.global.clusterDomain }}:{{ include "mimir.serverHttpListenPort" . }}$request_uri; } diff --git a/operations/helm/tests/test-oss-values-generated/mimir-distributed/templates/nginx/nginx-configmap.yaml b/operations/helm/tests/test-oss-values-generated/mimir-distributed/templates/nginx/nginx-configmap.yaml index 54c5b2f4ad..fe97d83067 100644 --- a/operations/helm/tests/test-oss-values-generated/mimir-distributed/templates/nginx/nginx-configmap.yaml +++ b/operations/helm/tests/test-oss-values-generated/mimir-distributed/templates/nginx/nginx-configmap.yaml @@ -82,15 +82,9 @@ data: proxy_pass http://test-oss-values-mimir-ruler.citestns.svc.cluster.local:8080$request_uri; } - location /api/v1/rules { - proxy_pass http://test-oss-values-mimir-ruler.citestns.svc.cluster.local:8080$request_uri; - } location /prometheus/api/v1/alerts { proxy_pass http://test-oss-values-mimir-ruler.citestns.svc.cluster.local:8080$request_uri; } - location /prometheus/rules { - proxy_pass http://test-oss-values-mimir-ruler.citestns.svc.cluster.local:8080$request_uri; - } location = /ruler/ring { proxy_pass http://test-oss-values-mimir-ruler.citestns.svc.cluster.local:8080$request_uri; } diff --git a/pkg/api/api.go b/pkg/api/api.go index 19df89013e..1c7075ec91 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -305,24 +305,6 @@ func (a *API) RegisterRulerAPI(r *ruler.API, configAPIEnabled bool) { a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/api/v1/alerts"), http.HandlerFunc(r.PrometheusAlerts), true, true, "GET") if configAPIEnabled { - // Ruler API Routes - // TODO remove the /api/v1/rules/** endpoints in Mimir 2.2.0 as agreed in https://github.com/grafana/mimir/pull/763#discussion_r808270581 - a.RegisterDeprecatedRoute("/api/v1/rules", http.HandlerFunc(r.ListRules), true, true, "GET") - a.RegisterDeprecatedRoute("/api/v1/rules/{namespace}", http.HandlerFunc(r.ListRules), true, true, "GET") - a.RegisterDeprecatedRoute("/api/v1/rules/{namespace}/{groupName}", http.HandlerFunc(r.GetRuleGroup), true, true, "GET") - a.RegisterDeprecatedRoute("/api/v1/rules/{namespace}", http.HandlerFunc(r.CreateRuleGroup), true, true, "POST") - a.RegisterDeprecatedRoute("/api/v1/rules/{namespace}/{groupName}", http.HandlerFunc(r.DeleteRuleGroup), true, true, "DELETE") - a.RegisterDeprecatedRoute("/api/v1/rules/{namespace}", http.HandlerFunc(r.DeleteNamespace), true, true, "DELETE") - - // Configuration endpoints with Prometheus prefix, so we keep Prometheus-compatible EPs and config EPs under the same prefix. - // TODO remove the /v1/rules/** endpoints in Mimir 2.2.0 as agreed in https://github.com/grafana/mimir/pull/1222#issuecomment-1046759965 - a.RegisterDeprecatedRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/rules"), http.HandlerFunc(r.ListRules), true, true, "GET") - a.RegisterDeprecatedRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/rules/{namespace}"), http.HandlerFunc(r.ListRules), true, true, "GET") - a.RegisterDeprecatedRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/rules/{namespace}/{groupName}"), http.HandlerFunc(r.GetRuleGroup), true, true, "GET") - a.RegisterDeprecatedRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/rules/{namespace}"), http.HandlerFunc(r.CreateRuleGroup), true, true, "POST") - a.RegisterDeprecatedRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/rules/{namespace}/{groupName}"), http.HandlerFunc(r.DeleteRuleGroup), true, true, "DELETE") - a.RegisterDeprecatedRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/rules/{namespace}"), http.HandlerFunc(r.DeleteNamespace), true, true, "DELETE") - // Long-term maintained configuration API routes a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/config/v1/rules"), http.HandlerFunc(r.ListRules), true, true, "GET") a.RegisterRoute(path.Join(a.cfg.PrometheusHTTPPrefix, "/config/v1/rules/{namespace}"), http.HandlerFunc(r.ListRules), true, true, "GET") diff --git a/pkg/mimirtool/client/client.go b/pkg/mimirtool/client/client.go index f886890cc6..a098eae451 100644 --- a/pkg/mimirtool/client/client.go +++ b/pkg/mimirtool/client/client.go @@ -22,8 +22,8 @@ import ( ) const ( - rulerAPIPath = "/api/v1/rules" - legacyAPIPath = "/api/prom/rules" + rulerAPIPath = "/prometheus/config/v1/rules" + legacyAPIPath = "/api/v1/rules" ) var ( diff --git a/pkg/mimirtool/client/client_test.go b/pkg/mimirtool/client/client_test.go index 7a87b8cc0f..76cc71842c 100644 --- a/pkg/mimirtool/client/client_test.go +++ b/pkg/mimirtool/client/client_test.go @@ -23,66 +23,66 @@ func TestBuildURL(t *testing.T) { }{ { name: "builds the correct URL with a trailing slash", - path: "/api/v1/rules", + path: "/prometheus/config/v1/rules", method: http.MethodPost, url: "http://mimirurl.com/", - resultURL: "http://mimirurl.com/api/v1/rules", + resultURL: "http://mimirurl.com/prometheus/config/v1/rules", }, { name: "builds the correct URL without a trailing slash", - path: "/api/v1/rules", + path: "/prometheus/config/v1/rules", method: http.MethodPost, url: "http://mimirurl.com", - resultURL: "http://mimirurl.com/api/v1/rules", + resultURL: "http://mimirurl.com/prometheus/config/v1/rules", }, { name: "builds the correct URL when the base url has a path", - path: "/api/v1/rules", + path: "/prometheus/config/v1/rules", method: http.MethodPost, url: "http://mimirurl.com/apathto", - resultURL: "http://mimirurl.com/apathto/api/v1/rules", + resultURL: "http://mimirurl.com/apathto/prometheus/config/v1/rules", }, { name: "builds the correct URL when the base url has a path with trailing slash", - path: "/api/v1/rules", + path: "/prometheus/config/v1/rules", method: http.MethodPost, url: "http://mimirurl.com/apathto/", - resultURL: "http://mimirurl.com/apathto/api/v1/rules", + resultURL: "http://mimirurl.com/apathto/prometheus/config/v1/rules", }, { name: "builds the correct URL with a trailing slash and the target path contains special characters", - path: "/api/v1/rules/%20%2Fspace%F0%9F%8D%BB", + path: "/prometheus/config/v1/rules/%20%2Fspace%F0%9F%8D%BB", method: http.MethodPost, url: "http://mimirurl.com/", - resultURL: "http://mimirurl.com/api/v1/rules/%20%2Fspace%F0%9F%8D%BB", + resultURL: "http://mimirurl.com/prometheus/config/v1/rules/%20%2Fspace%F0%9F%8D%BB", }, { name: "builds the correct URL without a trailing slash and the target path contains special characters", - path: "/api/v1/rules/%20%2Fspace%F0%9F%8D%BB", + path: "/prometheus/config/v1/rules/%20%2Fspace%F0%9F%8D%BB", method: http.MethodPost, url: "http://mimirurl.com", - resultURL: "http://mimirurl.com/api/v1/rules/%20%2Fspace%F0%9F%8D%BB", + resultURL: "http://mimirurl.com/prometheus/config/v1/rules/%20%2Fspace%F0%9F%8D%BB", }, { name: "builds the correct URL when the base url has a path and the target path contains special characters", - path: "/api/v1/rules/%20%2Fspace%F0%9F%8D%BB", + path: "/prometheus/config/v1/rules/%20%2Fspace%F0%9F%8D%BB", method: http.MethodPost, url: "http://mimirurl.com/apathto", - resultURL: "http://mimirurl.com/apathto/api/v1/rules/%20%2Fspace%F0%9F%8D%BB", + resultURL: "http://mimirurl.com/apathto/prometheus/config/v1/rules/%20%2Fspace%F0%9F%8D%BB", }, { name: "builds the correct URL when the base url has a path and the target path starts with a escaped slash", - path: "/api/v1/rules/%2F-first-char-slash", + path: "/prometheus/config/v1/rules/%2F-first-char-slash", method: http.MethodPost, url: "http://mimirurl.com/apathto", - resultURL: "http://mimirurl.com/apathto/api/v1/rules/%2F-first-char-slash", + resultURL: "http://mimirurl.com/apathto/prometheus/config/v1/rules/%2F-first-char-slash", }, { name: "builds the correct URL when the base url has a path and the target path ends with a escaped slash", - path: "/api/v1/rules/last-char-slash%2F", + path: "/prometheus/config/v1/rules/last-char-slash%2F", method: http.MethodPost, url: "http://mimirurl.com/apathto", - resultURL: "http://mimirurl.com/apathto/api/v1/rules/last-char-slash%2F", + resultURL: "http://mimirurl.com/apathto/prometheus/config/v1/rules/last-char-slash%2F", }, } diff --git a/pkg/mimirtool/client/rules_test.go b/pkg/mimirtool/client/rules_test.go index 023429fd00..4da1c08201 100644 --- a/pkg/mimirtool/client/rules_test.go +++ b/pkg/mimirtool/client/rules_test.go @@ -41,31 +41,31 @@ func TestMimirClient_X(t *testing.T) { test: "regular-characters", namespace: "my-namespace", name: "my-name", - expURLPath: "/api/v1/rules/my-namespace/my-name", + expURLPath: "/prometheus/config/v1/rules/my-namespace/my-name", }, { test: "special-characters-spaces", namespace: "My: Namespace", name: "My: Name", - expURLPath: "/api/v1/rules/My:%20Namespace/My:%20Name", + expURLPath: "/prometheus/config/v1/rules/My:%20Namespace/My:%20Name", }, { test: "special-characters-slashes", namespace: "My/Namespace", name: "My/Name", - expURLPath: "/api/v1/rules/My%2FNamespace/My%2FName", + expURLPath: "/prometheus/config/v1/rules/My%2FNamespace/My%2FName", }, { test: "special-characters-slash-first", namespace: "My/Namespace", name: "/first-char-slash", - expURLPath: "/api/v1/rules/My%2FNamespace/%2Ffirst-char-slash", + expURLPath: "/prometheus/config/v1/rules/My%2FNamespace/%2Ffirst-char-slash", }, { test: "special-characters-slash-first", namespace: "My/Namespace", name: "last-char-slash/", - expURLPath: "/api/v1/rules/My%2FNamespace/last-char-slash%2F", + expURLPath: "/prometheus/config/v1/rules/My%2FNamespace/last-char-slash%2F", }, } { t.Run(tc.test, func(t *testing.T) { diff --git a/pkg/mimirtool/commands/rules.go b/pkg/mimirtool/commands/rules.go index e51516ae5d..858ae34dcc 100644 --- a/pkg/mimirtool/commands/rules.go +++ b/pkg/mimirtool/commands/rules.go @@ -143,7 +143,7 @@ func (r *RuleCommand) Register(app *kingpin.Application, envVars EnvVarNames) { Required(). StringVar(&r.ClientConfig.ID) - c.Flag("use-legacy-routes", "If set, the API requests to Grafana Mimir use the legacy /api/prom/ routes; alternatively, set "+envVars.UseLegacyRoutes+"."). + c.Flag("use-legacy-routes", "If set, the API requests to Grafana Mimir use the legacy /api/v1/rules routes instead of /prometheus/config/v1/rules; alternatively, set "+envVars.UseLegacyRoutes+"."). Default("false"). Envar(envVars.UseLegacyRoutes). BoolVar(&r.ClientConfig.UseLegacyRoutes) diff --git a/pkg/ruler/api_test.go b/pkg/ruler/api_test.go index 1b09990de7..ea2051462b 100644 --- a/pkg/ruler/api_test.go +++ b/pkg/ruler/api_test.go @@ -301,10 +301,10 @@ rules: for _, tt := range tc { t.Run(tt.name, func(t *testing.T) { router := mux.NewRouter() - router.Path("/api/v1/rules/{namespace}").Methods("POST").HandlerFunc(a.CreateRuleGroup) - router.Path("/api/v1/rules/{namespace}/{groupName}").Methods("GET").HandlerFunc(a.GetRuleGroup) + router.Path("/prometheus/config/v1/rules/{namespace}").Methods("POST").HandlerFunc(a.CreateRuleGroup) + router.Path("/prometheus/config/v1/rules/{namespace}/{groupName}").Methods("GET").HandlerFunc(a.GetRuleGroup) // POST - req := requestFor(t, http.MethodPost, "https://localhost:8080/api/v1/rules/namespace", strings.NewReader(tt.input), "user1") + req := requestFor(t, http.MethodPost, "https://localhost:8080/prometheus/config/v1/rules/namespace", strings.NewReader(tt.input), "user1") w := httptest.NewRecorder() router.ServeHTTP(w, req) @@ -312,7 +312,7 @@ rules: if tt.err == nil { // GET - req = requestFor(t, http.MethodGet, "https://localhost:8080/api/v1/rules/namespace/test", nil, "user1") + req = requestFor(t, http.MethodGet, "https://localhost:8080/prometheus/config/v1/rules/namespace/test", nil, "user1") w = httptest.NewRecorder() router.ServeHTTP(w, req) @@ -373,11 +373,11 @@ func TestRuler_DeleteNamespace(t *testing.T) { a := NewAPI(r, r.store, log.NewNopLogger()) router := mux.NewRouter() - router.Path("/api/v1/rules/{namespace}").Methods(http.MethodDelete).HandlerFunc(a.DeleteNamespace) - router.Path("/api/v1/rules/{namespace}/{groupName}").Methods(http.MethodGet).HandlerFunc(a.GetRuleGroup) + router.Path("/prometheus/config/v1/rules/{namespace}").Methods(http.MethodDelete).HandlerFunc(a.DeleteNamespace) + router.Path("/prometheus/config/v1/rules/{namespace}/{groupName}").Methods(http.MethodGet).HandlerFunc(a.GetRuleGroup) // Verify namespace1 rules are there. - req := requestFor(t, http.MethodGet, "https://localhost:8080/api/v1/rules/namespace1/group1", nil, "user1") + req := requestFor(t, http.MethodGet, "https://localhost:8080/prometheus/config/v1/rules/namespace1/group1", nil, "user1") w := httptest.NewRecorder() router.ServeHTTP(w, req) @@ -385,7 +385,7 @@ func TestRuler_DeleteNamespace(t *testing.T) { require.Equal(t, "name: group1\ninterval: 1m\nrules:\n - record: UP_RULE\n expr: up\n - alert: UP_ALERT\n expr: up < 1\n", w.Body.String()) // Delete namespace1 - req = requestFor(t, http.MethodDelete, "https://localhost:8080/api/v1/rules/namespace1", nil, "user1") + req = requestFor(t, http.MethodDelete, "https://localhost:8080/prometheus/config/v1/rules/namespace1", nil, "user1") w = httptest.NewRecorder() router.ServeHTTP(w, req) @@ -393,7 +393,7 @@ func TestRuler_DeleteNamespace(t *testing.T) { require.Equal(t, "{\"status\":\"success\",\"data\":null,\"errorType\":\"\",\"error\":\"\"}", w.Body.String()) // On Partial failures - req = requestFor(t, http.MethodDelete, "https://localhost:8080/api/v1/rules/namespace2", nil, "user1") + req = requestFor(t, http.MethodDelete, "https://localhost:8080/prometheus/config/v1/rules/namespace2", nil, "user1") w = httptest.NewRecorder() router.ServeHTTP(w, req) @@ -442,9 +442,9 @@ rules: for _, tt := range tc { t.Run(tt.name, func(t *testing.T) { router := mux.NewRouter() - router.Path("/api/v1/rules/{namespace}").Methods("POST").HandlerFunc(a.CreateRuleGroup) + router.Path("/prometheus/config/v1/rules/{namespace}").Methods("POST").HandlerFunc(a.CreateRuleGroup) // POST - req := requestFor(t, http.MethodPost, "https://localhost:8080/api/v1/rules/namespace", strings.NewReader(tt.input), "user1") + req := requestFor(t, http.MethodPost, "https://localhost:8080/prometheus/config/v1/rules/namespace", strings.NewReader(tt.input), "user1") w := httptest.NewRecorder() router.ServeHTTP(w, req) @@ -499,12 +499,12 @@ rules: // define once so the requests build on each other so the number of rules can be tested router := mux.NewRouter() - router.Path("/api/v1/rules/{namespace}").Methods("POST").HandlerFunc(a.CreateRuleGroup) + router.Path("/prometheus/config/v1/rules/{namespace}").Methods("POST").HandlerFunc(a.CreateRuleGroup) for _, tt := range tc { t.Run(tt.name, func(t *testing.T) { // POST - req := requestFor(t, http.MethodPost, "https://localhost:8080/api/v1/rules/namespace", strings.NewReader(tt.input), "user1") + req := requestFor(t, http.MethodPost, "https://localhost:8080/prometheus/config/v1/rules/namespace", strings.NewReader(tt.input), "user1") w := httptest.NewRecorder() router.ServeHTTP(w, req) From ca5f0dedf14d0e3b496a90c365c0558a73e9ce35 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Wed, 22 Jun 2022 19:08:53 +0200 Subject: [PATCH 2/4] Add changelog entry Signed-off-by: Dimitar Dimitrov --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac38fcba1a..1a98473eeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ * [CHANGE] Blocks uploaded by ingester no longer contain `__org_id__` label. Compactor now ignores this label and will compact blocks with and without this label together. `mimirconvert` tool will remove the label from blocks as "unknown" label. #1972 * [CHANGE] Querier: deprecated `-querier.shuffle-sharding-ingesters-lookback-period`, instead adding `-querier.shuffle-sharding-ingesters-enabled` to enable or disable shuffle sharding on the read path. The value of `-querier.query-ingesters-within` is now used internally for shuffle sharding lookback. #2110 * [CHANGE] Memberlist: `-memberlist.abort-if-join-fails` now defaults to false. Previously it defaulted to true. #2168 +* [CHANGE] Ruler: `/api/v1/rules*` and `/prometheus/rules*` configuration endpoints are removed. Use `/prometheus/config/v1/rules*`. #2182 * [ENHANCEMENT] Distributor: Added limit to prevent tenants from sending excessive number of requests: #1843 * The following CLI flags (and their respective YAML config options) have been added: * `-distributor.request-rate-limit` From 8a8272ca35ba6aa67a0685de56dc6f64bb9e8497 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Wed, 22 Jun 2022 19:24:06 +0200 Subject: [PATCH 3/4] Fix failing tests Signed-off-by: Dimitar Dimitrov --- cmd/query-tee/main_test.go | 4 ++-- integration/ruler_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/query-tee/main_test.go b/cmd/query-tee/main_test.go index 2705aab3e8..513e1772a0 100644 --- a/cmd/query-tee/main_test.go +++ b/cmd/query-tee/main_test.go @@ -15,11 +15,11 @@ import ( func TestMimirReadRoutes(t *testing.T) { routes := mimirReadRoutes(Config{PathPrefix: ""}) for _, r := range routes { - assert.True(t, strings.HasPrefix(r.Path, "/api/v1/")) + assert.True(t, strings.HasPrefix(r.Path, "/api/v1/") || strings.HasPrefix(r.Path, "/prometheus/")) } routes = mimirReadRoutes(Config{PathPrefix: "/some/random/prefix///"}) for _, r := range routes { - assert.True(t, strings.HasPrefix(r.Path, "/some/random/prefix/api/v1/")) + assert.Regexp(t, "/some/random/prefix/[a-z].*", r.Path) } } diff --git a/integration/ruler_test.go b/integration/ruler_test.go index 5b12ead390..bd00ad3201 100644 --- a/integration/ruler_test.go +++ b/integration/ruler_test.go @@ -98,7 +98,7 @@ func TestRulerAPI(t *testing.T) { require.Equal(t, retrievedNamespace[0].Name, ruleGroup.Name) // Test compression by inspecting the response Headers - req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/api/v1/rules", ruler.HTTPEndpoint()), nil) + req, err := http.NewRequest("GET", fmt.Sprintf("http://%s/prometheus/config/v1/rules", ruler.HTTPEndpoint()), nil) require.NoError(t, err) req.Header.Set("X-Scope-OrgID", "user-1") From 3266798505e986b84deefdcfcd20dd47d6342111 Mon Sep 17 00:00:00 2001 From: Dimitar Dimitrov Date: Fri, 24 Jun 2022 11:26:21 +0200 Subject: [PATCH 4/4] Add changelog entry for mimirtool Signed-off-by: Dimitar Dimitrov --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a98473eeb..9f4937e69a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -87,6 +87,7 @@ ### Mimirtool +* [CHANGE] mimirtool rules: `--use-legacy-routes` now toggles between using `/prometheus/config/v1/rules` (default) and `/api/v1/rules` (legacy) endpoints. #2182 * [FEATURE] Added bearer token support for when Mimir is behind a gateway authenticating by bearer token. #2146 * [BUGFIX] mimirtool analyze: Fix dashboard JSON unmarshalling errors (#1840). #1973