Skip to content

Commit

Permalink
fix doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ying-jeanne committed Dec 4, 2024
1 parent 50df8fa commit ca5af9f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 19 deletions.
43 changes: 43 additions & 0 deletions docs/sources/mimir/configure/configuration-parameters/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,18 @@ overrides_exporter:
# (experimental) Enables optimized marshaling of timeseries.
# CLI flag: -timeseries-unmarshal-caching-optimization-enabled
[timeseries_unmarshal_caching_optimization_enabled: <boolean> | default = true]

# (experimental) Time interval at which inactive cost attributions are evicted
# from the counter, ensuring they are not included in the cost attribution
# cardinality per user limit.
# CLI flag: -cost-attribution.eviction-interval
[cost_attribution_eviction_interval: <duration> | default = 20m]

# (experimental) Defines a custom path for the registry. When specified, Mimir
# will expose cost attribution metrics through this custom path, if not
# specified, cost attribution metrics won't be exposed.
# CLI flag: -cost-attribution.registry-path
[cost_attribution_registry_path: <string> | default = ""]
```
### common
Expand Down Expand Up @@ -3572,6 +3584,37 @@ The `limits` block configures default and per-tenant limits imposed by component
# CLI flag: -querier.active-series-results-max-size-bytes
[active_series_results_max_size_bytes: <int> | default = 419430400]

# (experimental) List of labels used to define cost attribution. These labels
# will be included in the specified distributor and ingester metrics for each
# write request, allowing them to be distinguished by the label. The label
# applies to the following metrics:
# cortex_distributor_attributed_received_samples_total,
# cortex_ingester_attributed_active_series, and
# cortex_attributed_discarded_samples_total. Set to an empty string to disable
# cost attribution.
# CLI flag: -validation.cost-attribution-labels
[cost_attribution_labels: <string> | default = ""]

# (experimental) Maximum number of cost attribution labels allowed per user. Set
# to 0 to disable.
# CLI flag: -validation.max-cost-attribution-labels-per-user
[max_cost_attribution_labels_per_user: <int> | default = 2]

# (experimental) Maximum cardinality of cost attribution labels allowed per
# user.
# CLI flag: -validation.max-cost-attribution-cardinality-per-user
[max_cost_attribution_cardinality_per_user: <int> | default = 10000]

# (experimental) Cooldown period for cost attribution labels. Specifies the
# duration the cost attribution remains in overflow before attempting a reset.
# If the cardinality remains above the limit after this period, the system will
# stay in overflow mode and extend the cooldown. Setting this value to 0
# disables the cooldown, causing the system to continuously check whether the
# cardinality has dropped below the limit. A reset will occur once the
# cardinality falls below the limit.
# CLI flag: -validation.cost-attribution-cooldown
[cost_attribution_cooldown: <duration> | default = 0s]

# Duration to delay the evaluation of rules to ensure the underlying metrics
# have been pushed.
# CLI flag: -ruler.evaluation-delay-duration
Expand Down
18 changes: 9 additions & 9 deletions pkg/costattribution/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func Test_CreateDeleteTracker(t *testing.T) {
expectedMetrics := `
# HELP cortex_discarded_attributed_samples_total The total number of samples that were discarded per attribution.
# TYPE cortex_discarded_attributed_samples_total counter
cortex_discarded_attributed_samples_total{reason="invalid-metrics-name",team="foo",tenant="user1",tracker="custom_attribution"} 1
cortex_discarded_attributed_samples_total{reason="invalid-metrics-name",team="foo",tenant="user1",tracker="cost-attribution"} 1
# HELP cortex_received_attributed_samples_total The total number of samples that were received per attribution.
# TYPE cortex_received_attributed_samples_total counter
cortex_received_attributed_samples_total{department="foo",service="dodo",tenant="user3",tracker="custom_attribution"} 1
cortex_received_attributed_samples_total{department="foo",service="dodo",tenant="user3",tracker="cost-attribution"} 1
`
assert.NoError(t, testutil.GatherAndCompare(manager.reg, strings.NewReader(expectedMetrics), "cortex_discarded_attributed_samples_total", "cortex_received_attributed_samples_total"))
})
Expand All @@ -102,7 +102,7 @@ func Test_CreateDeleteTracker(t *testing.T) {
expectedMetrics := `
# HELP cortex_discarded_attributed_samples_total The total number of samples that were discarded per attribution.
# TYPE cortex_discarded_attributed_samples_total counter
cortex_discarded_attributed_samples_total{reason="invalid-metrics-name",team="foo",tenant="user1",tracker="custom_attribution"} 1
cortex_discarded_attributed_samples_total{reason="invalid-metrics-name",team="foo",tenant="user1",tracker="cost-attribution"} 1
`
assert.NoError(t, testutil.GatherAndCompare(manager.reg, strings.NewReader(expectedMetrics), "cortex_discarded_attributed_samples_total"))
})
Expand All @@ -115,7 +115,7 @@ func Test_CreateDeleteTracker(t *testing.T) {
expectedMetrics := `
# HELP cortex_received_attributed_samples_total The total number of samples that were received per attribution.
# TYPE cortex_received_attributed_samples_total counter
cortex_received_attributed_samples_total{department="foo",service="dodo",tenant="user3",tracker="custom_attribution"} 1
cortex_received_attributed_samples_total{department="foo",service="dodo",tenant="user3",tracker="cost-attribution"} 1
`
assert.NoError(t, testutil.GatherAndCompare(manager.reg, strings.NewReader(expectedMetrics), "cortex_received_attributed_samples_total"))
})
Expand All @@ -131,7 +131,7 @@ func Test_CreateDeleteTracker(t *testing.T) {
expectedMetrics := `
# HELP cortex_discarded_attributed_samples_total The total number of samples that were discarded per attribution.
# TYPE cortex_discarded_attributed_samples_total counter
cortex_discarded_attributed_samples_total{feature="__missing__",reason="invalid-metrics-name",team="foo",tenant="user3",tracker="custom_attribution"} 1
cortex_discarded_attributed_samples_total{feature="__missing__",reason="invalid-metrics-name",team="foo",tenant="user3",tracker="cost-attribution"} 1
`
assert.NoError(t, testutil.GatherAndCompare(manager.reg, strings.NewReader(expectedMetrics), "cortex_discarded_attributed_samples_total"))
})
Expand All @@ -144,7 +144,7 @@ func Test_CreateDeleteTracker(t *testing.T) {
expectedMetrics := `
# HELP cortex_received_attributed_samples_total The total number of samples that were received per attribution.
# TYPE cortex_received_attributed_samples_total counter
cortex_received_attributed_samples_total{feature="__overflow__",team="__overflow__",tenant="user3",tracker="custom_attribution"} 2
cortex_received_attributed_samples_total{feature="__overflow__",team="__overflow__",tenant="user3",tracker="cost-attribution"} 2
`
assert.NoError(t, testutil.GatherAndCompare(manager.reg, strings.NewReader(expectedMetrics), "cortex_received_attributed_samples_total"))
})
Expand All @@ -168,8 +168,8 @@ func Test_PurgeInactiveAttributionsUntil(t *testing.T) {
expectedMetrics := `
# HELP cortex_discarded_attributed_samples_total The total number of samples that were discarded per attribution.
# TYPE cortex_discarded_attributed_samples_total counter
cortex_discarded_attributed_samples_total{reason="invalid-metrics-name",team="foo",tenant="user1",tracker="custom_attribution"} 1
cortex_discarded_attributed_samples_total{department="foo",reason="out-of-window",service="bar",tenant="user3",tracker="custom_attribution"} 1
cortex_discarded_attributed_samples_total{reason="invalid-metrics-name",team="foo",tenant="user1",tracker="cost-attribution"} 1
cortex_discarded_attributed_samples_total{department="foo",reason="out-of-window",service="bar",tenant="user3",tracker="cost-attribution"} 1
`
metricNames := []string{
"cortex_discarded_attributed_samples_total",
Expand All @@ -189,7 +189,7 @@ func Test_PurgeInactiveAttributionsUntil(t *testing.T) {
expectedMetrics := `
# HELP cortex_discarded_attributed_samples_total The total number of samples that were discarded per attribution.
# TYPE cortex_discarded_attributed_samples_total counter
cortex_discarded_attributed_samples_total{department="foo",reason="out-of-window",service="bar",tenant="user3",tracker="custom_attribution"} 1
cortex_discarded_attributed_samples_total{department="foo",reason="out-of-window",service="bar",tenant="user3",tracker="cost-attribution"} 1
`
metricNames := []string{
"cortex_discarded_attributed_samples_total",
Expand Down
11 changes: 6 additions & 5 deletions pkg/costattribution/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ type Observation struct {
}

const (
TrackerLabel = "tracker"
TenantLabel = "tenant"
TrackerLabel = "tracker"
TenantLabel = "tenant"
defaultTrackerName = "cost-attribution"
)

type Tracker struct {
Expand Down Expand Up @@ -61,19 +62,19 @@ func newTracker(userID string, trackedLabels []string, limit int, cooldown time.
discardedSampleAttribution: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "cortex_discarded_attributed_samples_total",
Help: "The total number of samples that were discarded per attribution.",
ConstLabels: prometheus.Labels{TrackerLabel: "custom_attribution"},
ConstLabels: prometheus.Labels{TrackerLabel: defaultTrackerName},
}, append(trackedLabels, TenantLabel, "reason")),
//lint:ignore faillint the metrics are registered in the mimir package
receivedSamplesAttribution: prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "cortex_received_attributed_samples_total",
Help: "The total number of samples that were received per attribution.",
ConstLabels: prometheus.Labels{TrackerLabel: "custom_attribution"},
ConstLabels: prometheus.Labels{TrackerLabel: defaultTrackerName},
}, append(trackedLabels, TenantLabel)),
//lint:ignore faillint the metrics are registered in the mimir package
activeSeriesPerUserAttribution: prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "cortex_ingester_attributed_active_series",
Help: "The total number of active series per user and attribution.",
ConstLabels: prometheus.Labels{TrackerLabel: "custom_attribution"},
ConstLabels: prometheus.Labels{TrackerLabel: defaultTrackerName},
}, append(trackedLabels, TenantLabel)),
hashBuffer: make([]byte, 0, 1024),
cooldownDuration: int64(cooldown.Seconds()),
Expand Down
10 changes: 5 additions & 5 deletions pkg/costattribution/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ func Test_CreateCleanupTracker(t *testing.T) {
expectedMetrics := `
# HELP cortex_discarded_attributed_samples_total The total number of samples that were discarded per attribution.
# TYPE cortex_discarded_attributed_samples_total counter
cortex_discarded_attributed_samples_total{platform="foo",reason="sample-out-of-order", tenant="user4",tracker="custom_attribution"} 2
cortex_discarded_attributed_samples_total{platform="foo",reason="sample-out-of-order", tenant="user4",tracker="cost-attribution"} 2
# HELP cortex_ingester_attributed_active_series The total number of active series per user and attribution.
# TYPE cortex_ingester_attributed_active_series gauge
cortex_ingester_attributed_active_series{platform="bar",tenant="user4",tracker="custom_attribution"} 1
cortex_ingester_attributed_active_series{platform="foo",tenant="user4",tracker="custom_attribution"} 1
cortex_ingester_attributed_active_series{platform="bar",tenant="user4",tracker="cost-attribution"} 1
cortex_ingester_attributed_active_series{platform="foo",tenant="user4",tracker="cost-attribution"} 1
# HELP cortex_received_attributed_samples_total The total number of samples that were received per attribution.
# TYPE cortex_received_attributed_samples_total counter
cortex_received_attributed_samples_total{platform="foo",tenant="user4",tracker="custom_attribution"} 5
cortex_received_attributed_samples_total{platform="foo",tenant="user4",tracker="cost-attribution"} 5
`

metricNames := []string{
Expand All @@ -70,7 +70,7 @@ func Test_CreateCleanupTracker(t *testing.T) {
expectedMetrics = `
# HELP cortex_ingester_attributed_active_series The total number of active series per user and attribution.
# TYPE cortex_ingester_attributed_active_series gauge
cortex_ingester_attributed_active_series{platform="bar",tenant="user4",tracker="custom_attribution"} 1
cortex_ingester_attributed_active_series{platform="bar",tenant="user4",tracker="cost-attribution"} 1
`
assert.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(expectedMetrics), metricNames...))

Expand Down

0 comments on commit ca5af9f

Please sign in to comment.