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

Remove deprecated ruler endpoints #2182

Merged
merged 4 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion cmd/query-tee/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
}
4 changes: 2 additions & 2 deletions cmd/query-tee/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<prometheus-http-prefix>/config/v1/rules/**` equivalents instead.
- `<prometheus-http-prefix>/rules/**` configuration endpoints. These will be removed in version 2.2.0. Use their `<prometheus-http-prefix>/config/v1/rules/**` equivalents instead.
36 changes: 0 additions & 36 deletions docs/sources/operators-guide/reference-http-api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,6 @@ Requires [authentication](#authentication).

```
GET <prometheus-http-prefix>/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 <prometheus-http-prefix>/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.
Expand Down Expand Up @@ -620,12 +614,6 @@ Requires [authentication](#authentication).

```
GET <prometheus-http-prefix>/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 <prometheus-http-prefix>/rules/{namespace}
```

Returns the rule groups defined for a given namespace.
Expand Down Expand Up @@ -657,12 +645,6 @@ rules:

```
GET <prometheus-http-prefix>/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 <prometheus-http-prefix>/rules/{namespace}/{groupName}
```

Returns the rule group matching the request namespace and group name.
Expand All @@ -675,12 +657,6 @@ Requires [authentication](#authentication).

```
POST /<prometheus-http-prefix>/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 <prometheus-http-prefix>/rules/{namespace}
```

Creates or updates a rule group.
Expand Down Expand Up @@ -709,12 +685,6 @@ rules:

```
DELETE /<prometheus-http-prefix>/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 <prometheus-http-prefix>/rules/{namespace}/{groupName}
```

Deletes a rule group by namespace and group name. This endpoints returns `202` on success.
Expand All @@ -727,12 +697,6 @@ Requires [authentication](#authentication).

```
DELETE /<prometheus-http-prefix>/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 <prometheus-http-prefix>/rules/{namespace}
```

Deletes all the rule groups in a namespace (including the namespace itself). This endpoint returns `202` on success.
Expand Down
2 changes: 1 addition & 1 deletion docs/sources/operators-guide/tools/query-tee.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The following Prometheus API endpoints are supported by `query-tee`:
- `GET <prefix>/api/v1/series`
- `GET <prefix>/api/v1/metadata`
- `GET <prefix>/api/v1/alerts`
- `GET <prefix>/api/v1/rules`
- `GET <prefix>/prometheus/config/v1/rules`

You can configure the `<prefix>` by setting the `-server.path-prefix` flag, which defaults to an empty string.

Expand Down
10 changes: 5 additions & 5 deletions integration/e2emimir/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
13 changes: 7 additions & 6 deletions integration/ruler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -988,23 +988,24 @@ 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"},

{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"},
},
},
}
Expand Down
6 changes: 0 additions & 6 deletions operations/helm/charts/mimir-distributed/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
18 changes: 0 additions & 18 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <prometheus-http-prefix>/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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/mimirtool/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
)

const (
rulerAPIPath = "/api/v1/rules"
legacyAPIPath = "/api/prom/rules"
rulerAPIPath = "/prometheus/config/v1/rules"
legacyAPIPath = "/api/v1/rules"
)

var (
Expand Down
36 changes: 18 additions & 18 deletions pkg/mimirtool/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down