Skip to content

Add label size bytes native histogram #6380

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 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
* [ENHANCEMENT] Ingester: Introduce a new experimental feature for caching expanded postings on the ingester. #6296
* [ENHANCEMENT] Querier/Ruler: Expose `store_gateway_consistency_check_max_attempts` for max retries when querying store gateway in consistency check. #6276
* [ENHANCEMENT] StoreGateway: Add new `cortex_bucket_store_chunk_pool_inuse_bytes` metric to track the usage in chunk pool. #6310
* [ENHANCEMENT] Distributor: Expose `cortex_label_size_bytes` native histogram metric. #6372
* [BUGFIX] Runtime-config: Handle absolute file paths when working directory is not / #6224
* [BUGFIX] Ruler: Allow rule evaluation to complete during shutdown. #6326
* [BUGFIX] Ring: update ring with new ip address when instance is lost, rejoins, but heartbeat is disabled #6271
Expand Down
15 changes: 15 additions & 0 deletions pkg/util/validation/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ type ValidateMetrics struct {
DiscardedExemplars *prometheus.CounterVec
DiscardedMetadata *prometheus.CounterVec
HistogramSamplesReducedResolution *prometheus.CounterVec
LabelSizeBytes *prometheus.HistogramVec
}

func registerCollector(r prometheus.Registerer, c prometheus.Collector) {
Expand Down Expand Up @@ -120,11 +121,21 @@ func NewValidateMetrics(r prometheus.Registerer) *ValidateMetrics {
[]string{"user"},
)
registerCollector(r, histogramSamplesReducedResolution)
labelSizeBytes := prometheus.NewHistogramVec(prometheus.HistogramOpts{
Name: "cortex_label_size_bytes",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we call it cortex_series_label_size_bytes? cortex_label_size_bytes makes me confused that this metric is for a single label not combined label size total

Help: "The combined size in bytes of all labels and label values for a time series.",
NativeHistogramBucketFactor: 1.1,
NativeHistogramMaxBucketNumber: 100,
NativeHistogramMinResetDuration: 1 * time.Hour,
}, []string{"user"})
registerCollector(r, labelSizeBytes)

m := &ValidateMetrics{
DiscardedSamples: discardedSamples,
DiscardedExemplars: discardedExemplars,
DiscardedMetadata: discardedMetadata,
HistogramSamplesReducedResolution: histogramSamplesReducedResolution,
LabelSizeBytes: labelSizeBytes,
}

return m
Expand Down Expand Up @@ -236,6 +247,7 @@ func ValidateLabels(validateMetrics *ValidateMetrics, limits *Limits, userID str
lastLabelName = l.Name
labelsSizeBytes += l.Size()
}
validateMetrics.LabelSizeBytes.WithLabelValues(userID).Observe(float64(labelsSizeBytes))
if maxLabelsSizeBytes > 0 && labelsSizeBytes > maxLabelsSizeBytes {
validateMetrics.DiscardedSamples.WithLabelValues(labelsSizeBytesExceeded, userID).Inc()
return labelSizeBytesExceededError(ls, labelsSizeBytes, maxLabelsSizeBytes)
Expand Down Expand Up @@ -352,4 +364,7 @@ func DeletePerUserValidationMetrics(validateMetrics *ValidateMetrics, userID str
if err := util.DeleteMatchingLabels(validateMetrics.HistogramSamplesReducedResolution, filter); err != nil {
level.Warn(log).Log("msg", "failed to remove cortex_reduced_resolution_histogram_samples_total metric for user", "user", userID, "err", err)
}
if err := util.DeleteMatchingLabels(validateMetrics.LabelSizeBytes, filter); err != nil {
level.Warn(log).Log("msg", "failed to remove cortex_label_size_bytes metric for user", "user", userID, "err", err)
}
}
8 changes: 8 additions & 0 deletions pkg/util/validation/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ func TestValidateLabels(t *testing.T) {
cortex_discarded_samples_total{reason="random reason",user="different user"} 1
`), "cortex_discarded_samples_total"))

require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
# HELP cortex_label_size_bytes The combined size in bytes of all labels and label values for a time series.
# TYPE cortex_label_size_bytes histogram
cortex_label_size_bytes_bucket{user="testUser",le="+Inf"} 3
cortex_label_size_bytes_sum{user="testUser"} 148
cortex_label_size_bytes_count{user="testUser"} 3
`), "cortex_label_size_bytes"))

DeletePerUserValidationMetrics(validateMetrics, userID, util_log.Logger)

require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
Expand Down