Skip to content

Commit

Permalink
Add label size bytes native histogram
Browse files Browse the repository at this point in the history
Signed-off-by: Anna Tran <[email protected]>
  • Loading branch information
anna-tran committed Nov 27, 2024
1 parent 006cab3 commit 8889f1b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
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
12 changes: 12 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",
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
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

0 comments on commit 8889f1b

Please sign in to comment.