Skip to content

Commit e9d2ed7

Browse files
authored
Add label size bytes native histogram (#6380)
* Add label size bytes native histogram Signed-off-by: Anna Tran <[email protected]> * Update DeletePerUserValidationMetrics with labelSizeBytes Signed-off-by: Anna Tran <[email protected]> --------- Signed-off-by: Anna Tran <[email protected]>
1 parent 7845df4 commit e9d2ed7

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* [ENHANCEMENT] Querier/Ruler: Expose `store_gateway_consistency_check_max_attempts` for max retries when querying store gateway in consistency check. #6276
4040
* [ENHANCEMENT] StoreGateway: Add new `cortex_bucket_store_chunk_pool_inuse_bytes` metric to track the usage in chunk pool. #6310
4141
* [ENHANCEMENT] Distributor: Add new `cortex_distributor_inflight_client_requests` metric to track number of ingester client inflight requests. #6358
42+
* [ENHANCEMENT] Distributor: Expose `cortex_label_size_bytes` native histogram metric. #6372
4243
* [BUGFIX] Runtime-config: Handle absolute file paths when working directory is not / #6224
4344
* [BUGFIX] Ruler: Allow rule evaluation to complete during shutdown. #6326
4445
* [BUGFIX] Ring: update ring with new ip address when instance is lost, rejoins, but heartbeat is disabled #6271

pkg/util/validation/validate.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type ValidateMetrics struct {
7878
DiscardedExemplars *prometheus.CounterVec
7979
DiscardedMetadata *prometheus.CounterVec
8080
HistogramSamplesReducedResolution *prometheus.CounterVec
81+
LabelSizeBytes *prometheus.HistogramVec
8182
}
8283

8384
func registerCollector(r prometheus.Registerer, c prometheus.Collector) {
@@ -120,11 +121,21 @@ func NewValidateMetrics(r prometheus.Registerer) *ValidateMetrics {
120121
[]string{"user"},
121122
)
122123
registerCollector(r, histogramSamplesReducedResolution)
124+
labelSizeBytes := prometheus.NewHistogramVec(prometheus.HistogramOpts{
125+
Name: "cortex_label_size_bytes",
126+
Help: "The combined size in bytes of all labels and label values for a time series.",
127+
NativeHistogramBucketFactor: 1.1,
128+
NativeHistogramMaxBucketNumber: 100,
129+
NativeHistogramMinResetDuration: 1 * time.Hour,
130+
}, []string{"user"})
131+
registerCollector(r, labelSizeBytes)
132+
123133
m := &ValidateMetrics{
124134
DiscardedSamples: discardedSamples,
125135
DiscardedExemplars: discardedExemplars,
126136
DiscardedMetadata: discardedMetadata,
127137
HistogramSamplesReducedResolution: histogramSamplesReducedResolution,
138+
LabelSizeBytes: labelSizeBytes,
128139
}
129140

130141
return m
@@ -236,6 +247,7 @@ func ValidateLabels(validateMetrics *ValidateMetrics, limits *Limits, userID str
236247
lastLabelName = l.Name
237248
labelsSizeBytes += l.Size()
238249
}
250+
validateMetrics.LabelSizeBytes.WithLabelValues(userID).Observe(float64(labelsSizeBytes))
239251
if maxLabelsSizeBytes > 0 && labelsSizeBytes > maxLabelsSizeBytes {
240252
validateMetrics.DiscardedSamples.WithLabelValues(labelsSizeBytesExceeded, userID).Inc()
241253
return labelSizeBytesExceededError(ls, labelsSizeBytes, maxLabelsSizeBytes)
@@ -352,4 +364,7 @@ func DeletePerUserValidationMetrics(validateMetrics *ValidateMetrics, userID str
352364
if err := util.DeleteMatchingLabels(validateMetrics.HistogramSamplesReducedResolution, filter); err != nil {
353365
level.Warn(log).Log("msg", "failed to remove cortex_reduced_resolution_histogram_samples_total metric for user", "user", userID, "err", err)
354366
}
367+
if err := util.DeleteMatchingLabels(validateMetrics.LabelSizeBytes, filter); err != nil {
368+
level.Warn(log).Log("msg", "failed to remove cortex_label_size_bytes metric for user", "user", userID, "err", err)
369+
}
355370
}

pkg/util/validation/validate_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ func TestValidateLabels(t *testing.T) {
119119
cortex_discarded_samples_total{reason="random reason",user="different user"} 1
120120
`), "cortex_discarded_samples_total"))
121121

122+
require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
123+
# HELP cortex_label_size_bytes The combined size in bytes of all labels and label values for a time series.
124+
# TYPE cortex_label_size_bytes histogram
125+
cortex_label_size_bytes_bucket{user="testUser",le="+Inf"} 3
126+
cortex_label_size_bytes_sum{user="testUser"} 148
127+
cortex_label_size_bytes_count{user="testUser"} 3
128+
`), "cortex_label_size_bytes"))
129+
122130
DeletePerUserValidationMetrics(validateMetrics, userID, util_log.Logger)
123131

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

0 commit comments

Comments
 (0)