@@ -11,6 +11,7 @@ import (
11
11
"github.com/go-kit/log/level"
12
12
"github.com/prometheus/client_golang/prometheus"
13
13
"github.com/prometheus/common/model"
14
+ "github.com/prometheus/prometheus/model/histogram"
14
15
"github.com/weaveworks/common/httpgrpc"
15
16
16
17
"github.com/cortexproject/cortex/pkg/cortexpb"
@@ -265,57 +266,57 @@ func ValidateMetadata(validateMetrics *ValidateMetrics, cfg *Limits, userID stri
265
266
return nil
266
267
}
267
268
268
- func ValidateNativeHistogram (validateMetrics * ValidateMetrics , limits * Limits , userID string , ls []cortexpb.LabelAdapter , histogram cortexpb.Histogram ) (cortexpb.Histogram , error ) {
269
+ func ValidateNativeHistogram (validateMetrics * ValidateMetrics , limits * Limits , userID string , ls []cortexpb.LabelAdapter , histogramSample cortexpb.Histogram ) (cortexpb.Histogram , error ) {
269
270
if limits .MaxNativeHistogramBuckets == 0 {
270
- return histogram , nil
271
+ return histogramSample , nil
271
272
}
272
273
273
274
var (
274
275
exceedLimit bool
275
276
)
276
- if histogram .IsFloatHistogram () {
277
+ if histogramSample .IsFloatHistogram () {
277
278
// Initial check to see if the bucket limit is exceeded or not. If not, we can avoid type casting.
278
- exceedLimit = len (histogram .PositiveCounts )+ len (histogram .NegativeCounts ) > limits .MaxNativeHistogramBuckets
279
+ exceedLimit = len (histogramSample .PositiveCounts )+ len (histogramSample .NegativeCounts ) > limits .MaxNativeHistogramBuckets
279
280
if ! exceedLimit {
280
- return histogram , nil
281
+ return histogramSample , nil
281
282
}
282
283
// Exceed limit.
283
- if histogram .Schema <= cortexpb .ExponentialSchemaMin {
284
+ if histogramSample .Schema <= histogram .ExponentialSchemaMin {
284
285
validateMetrics .DiscardedSamples .WithLabelValues (nativeHistogramBucketCountLimitExceeded , userID ).Inc ()
285
286
return cortexpb.Histogram {}, newHistogramBucketLimitExceededError (ls , limits .MaxNativeHistogramBuckets )
286
287
}
287
- fh := cortexpb .FloatHistogramProtoToFloatHistogram (histogram )
288
+ fh := cortexpb .FloatHistogramProtoToFloatHistogram (histogramSample )
288
289
for len (fh .PositiveBuckets )+ len (fh .NegativeBuckets ) > limits .MaxNativeHistogramBuckets {
289
- if fh .Schema <= cortexpb .ExponentialSchemaMin {
290
+ if fh .Schema <= histogram .ExponentialSchemaMin {
290
291
validateMetrics .DiscardedSamples .WithLabelValues (nativeHistogramBucketCountLimitExceeded , userID ).Inc ()
291
292
return cortexpb.Histogram {}, newHistogramBucketLimitExceededError (ls , limits .MaxNativeHistogramBuckets )
292
293
}
293
294
fh = fh .ReduceResolution (fh .Schema - 1 )
294
295
}
295
296
// If resolution reduced, convert new float histogram to protobuf type again.
296
- return cortexpb .FloatHistogramToHistogramProto (histogram .TimestampMs , fh ), nil
297
+ return cortexpb .FloatHistogramToHistogramProto (histogramSample .TimestampMs , fh ), nil
297
298
}
298
299
299
300
// Initial check to see if bucket limit is exceeded or not. If not, we can avoid type casting.
300
- exceedLimit = len (histogram .PositiveDeltas )+ len (histogram .NegativeDeltas ) > limits .MaxNativeHistogramBuckets
301
+ exceedLimit = len (histogramSample .PositiveDeltas )+ len (histogramSample .NegativeDeltas ) > limits .MaxNativeHistogramBuckets
301
302
if ! exceedLimit {
302
- return histogram , nil
303
+ return histogramSample , nil
303
304
}
304
305
// Exceed limit.
305
- if histogram .Schema <= cortexpb .ExponentialSchemaMin {
306
+ if histogramSample .Schema <= histogram .ExponentialSchemaMin {
306
307
validateMetrics .DiscardedSamples .WithLabelValues (nativeHistogramBucketCountLimitExceeded , userID ).Inc ()
307
308
return cortexpb.Histogram {}, newHistogramBucketLimitExceededError (ls , limits .MaxNativeHistogramBuckets )
308
309
}
309
- h := cortexpb .HistogramProtoToHistogram (histogram )
310
+ h := cortexpb .HistogramProtoToHistogram (histogramSample )
310
311
for len (h .PositiveBuckets )+ len (h .NegativeBuckets ) > limits .MaxNativeHistogramBuckets {
311
- if h .Schema <= cortexpb .ExponentialSchemaMin {
312
+ if h .Schema <= histogram .ExponentialSchemaMin {
312
313
validateMetrics .DiscardedSamples .WithLabelValues (nativeHistogramBucketCountLimitExceeded , userID ).Inc ()
313
314
return cortexpb.Histogram {}, newHistogramBucketLimitExceededError (ls , limits .MaxNativeHistogramBuckets )
314
315
}
315
316
h = h .ReduceResolution (h .Schema - 1 )
316
317
}
317
318
// If resolution reduced, convert new histogram to protobuf type again.
318
- return cortexpb .HistogramToHistogramProto (histogram .TimestampMs , h ), nil
319
+ return cortexpb .HistogramToHistogramProto (histogramSample .TimestampMs , h ), nil
319
320
}
320
321
321
322
func DeletePerUserValidationMetrics (validateMetrics * ValidateMetrics , userID string , log log.Logger ) {
0 commit comments