-
Notifications
You must be signed in to change notification settings - Fork 820
feat: Emit per-tenant limit overrides as metrics #3785
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# file: runtime.yaml | ||
# In this example, we're overriding ingestion limits for a single tenant. | ||
overrides: | ||
"user1": | ||
ingestion_burst_size: 350000 | ||
ingestion_rate: 350000 | ||
max_global_series_per_metric: 300000 | ||
max_global_series_per_user: 300000 | ||
max_series_per_metric: 0 | ||
max_series_per_user: 0 | ||
max_samples_per_query: 100000 | ||
max_series_per_query: 100000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
--- | ||
title: "Overrides Exporter" | ||
linkTitle: "Overrides Exporter" | ||
weight: 10 | ||
slug: overrides-exporter | ||
--- | ||
|
||
Since Cortex is a multi-tenant system, it supports applying limits to each tenant to prevent | ||
any single one from using too many resources. In order to help operators understand how close | ||
to their limits tenants are, the `overrides-exporter` module can expose limits as Prometheus metrics. | ||
|
||
## Context | ||
|
||
To update configuration without restarting, Cortex allows operators to supply a `runtime_config` | ||
file that will be periodically reloaded. This file can be specified under the `runtime_config` section | ||
of the main [configuration file](../configuration/arguments.md#runtime-configuration-file) or using the `-runtime-config.file` | ||
command line flag. This file is used to apply tenant-specific limits. | ||
|
||
## Example | ||
|
||
The `overrides-exporter` is not enabled by default, it must be explicitly enabled. We recommend | ||
only running a single instance of it in your cluster due to the cardinality of the metrics | ||
emitted. | ||
|
||
With a `runtime.yaml` file given below | ||
|
||
[embedmd]:# (./overrides-exporter-runtime.yaml) | ||
```yaml | ||
# file: runtime.yaml | ||
# In this example, we're overriding ingestion limits for a single tenant. | ||
overrides: | ||
"user1": | ||
ingestion_burst_size: 350000 | ||
ingestion_rate: 350000 | ||
max_global_series_per_metric: 300000 | ||
max_global_series_per_user: 300000 | ||
max_series_per_metric: 0 | ||
max_series_per_user: 0 | ||
max_samples_per_query: 100000 | ||
max_series_per_query: 100000 | ||
``` | ||
|
||
The `overrides-exporter` is configured to run as follows | ||
|
||
``` | ||
cortex -target overrides-exporter -runtime-config.file runtime.yaml -server.http-listen-port=8080 | ||
``` | ||
|
||
After the `overrides-exporter` starts, you can to use `curl` to inspect the tenant overrides. | ||
|
||
```text | ||
curl -s http://localhost:8080/metrics | grep cortex_overrides | ||
# HELP cortex_overrides Resource limit overrides applied to tenants | ||
# TYPE cortex_overrides gauge | ||
cortex_overrides{limit_name="ingestion_burst_size",user="user1"} 350000 | ||
cortex_overrides{limit_name="ingestion_rate",user="user1"} 350000 | ||
cortex_overrides{limit_name="max_global_series_per_metric",user="user1"} 300000 | ||
cortex_overrides{limit_name="max_global_series_per_user",user="user1"} 300000 | ||
cortex_overrides{limit_name="max_local_series_per_metric",user="user1"} 0 | ||
cortex_overrides{limit_name="max_local_series_per_user",user="user1"} 0 | ||
cortex_overrides{limit_name="max_samples_per_query",user="user1"} 100000 | ||
cortex_overrides{limit_name="max_series_per_query",user="user1"} 100000 | ||
``` | ||
|
||
With these metrics, you can set up alerts to know when tenants are close to hitting their limits | ||
before they exceed them. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package validation | ||
|
||
import ( | ||
"github.com/prometheus/client_golang/prometheus" | ||
) | ||
|
||
// OverridesExporter exposes per-tenant resource limit overrides as Prometheus metrics | ||
type OverridesExporter struct { | ||
limitSupplier func() map[string]*Limits | ||
description *prometheus.Desc | ||
} | ||
|
||
// NewOverridesExporter creates an OverridesExporter that reads updates to per-tenant | ||
// limits using the provided function. | ||
func NewOverridesExporter(limitSupplier func() map[string]*Limits) *OverridesExporter { | ||
return &OverridesExporter{ | ||
limitSupplier: limitSupplier, | ||
description: prometheus.NewDesc( | ||
"cortex_overrides", | ||
"Resource limit overrides applied to tenants", | ||
[]string{"limit_name", "user"}, | ||
nil, | ||
), | ||
} | ||
} | ||
|
||
func (oe *OverridesExporter) Describe(ch chan<- *prometheus.Desc) { | ||
ch <- oe.description | ||
} | ||
|
||
func (oe *OverridesExporter) Collect(ch chan<- prometheus.Metric) { | ||
allLimits := oe.limitSupplier() | ||
for tenant, limits := range allLimits { | ||
pstibrany marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, limits.IngestionRate, "ingestion_rate", tenant) | ||
ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.IngestionBurstSize), "ingestion_burst_size", tenant) | ||
|
||
ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxSeriesPerQuery), "max_series_per_query", tenant) | ||
ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxSamplesPerQuery), "max_samples_per_query", tenant) | ||
ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxLocalSeriesPerUser), "max_local_series_per_user", tenant) | ||
ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxLocalSeriesPerMetric), "max_local_series_per_metric", tenant) | ||
ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxGlobalSeriesPerUser), "max_global_series_per_user", tenant) | ||
ch <- prometheus.MustNewConstMetric(oe.description, prometheus.GaugeValue, float64(limits.MaxGlobalSeriesPerMetric), "max_global_series_per_metric", tenant) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package validation | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prometheus/client_golang/prometheus/testutil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestOverridesExporter_noConfig(t *testing.T) { | ||
limitSupplier := func() map[string]*Limits { return nil } | ||
exporter := NewOverridesExporter(limitSupplier) | ||
|
||
// With no updated override configurations, there should be no override metrics | ||
count := testutil.CollectAndCount(exporter, "cortex_overrides") | ||
assert.Equal(t, 0, count) | ||
} | ||
|
||
func TestOverridesExporter_withConfig(t *testing.T) { | ||
limitSupplier := func() map[string]*Limits { | ||
cfg := make(map[string]*Limits) | ||
cfg["user1"] = &Limits{} | ||
return cfg | ||
} | ||
exporter := NewOverridesExporter(limitSupplier) | ||
|
||
// There should be at least a few metrics generated by receiving an override configuration map | ||
count := testutil.CollectAndCount(exporter, "cortex_overrides") | ||
assert.Greater(t, count, 0) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.