@@ -30,7 +30,8 @@ const (
30
30
31
31
// expoHistogramDataPoint is a single data point in an exponential histogram.
32
32
type expoHistogramDataPoint [N int64 | float64 ] struct {
33
- res exemplar.Reservoir [N ]
33
+ attrs attribute.Set
34
+ res exemplar.Reservoir [N ]
34
35
35
36
count uint64
36
37
min N
@@ -48,7 +49,7 @@ type expoHistogramDataPoint[N int64 | float64] struct {
48
49
zeroCount uint64
49
50
}
50
51
51
- func newExpoHistogramDataPoint [N int64 | float64 ](maxSize , maxScale int , noMinMax , noSum bool ) * expoHistogramDataPoint [N ] {
52
+ func newExpoHistogramDataPoint [N int64 | float64 ](attrs attribute. Set , maxSize , maxScale int , noMinMax , noSum bool ) * expoHistogramDataPoint [N ] {
52
53
f := math .MaxFloat64
53
54
max := N (f ) // if N is int64, max will overflow to -9223372036854775808
54
55
min := N (- f )
@@ -57,6 +58,7 @@ func newExpoHistogramDataPoint[N int64 | float64](maxSize, maxScale int, noMinMa
57
58
min = N (minInt64 )
58
59
}
59
60
return & expoHistogramDataPoint [N ]{
61
+ attrs : attrs ,
60
62
min : max ,
61
63
max : min ,
62
64
maxSize : maxSize ,
@@ -289,7 +291,7 @@ func newExponentialHistogram[N int64 | float64](maxSize, maxScale int32, noMinMa
289
291
290
292
newRes : r ,
291
293
limit : newLimiter [* expoHistogramDataPoint [N ]](limit ),
292
- values : make (map [attribute.Set ]* expoHistogramDataPoint [N ]),
294
+ values : make (map [attribute.Distinct ]* expoHistogramDataPoint [N ]),
293
295
294
296
start : now (),
295
297
}
@@ -305,7 +307,7 @@ type expoHistogram[N int64 | float64] struct {
305
307
306
308
newRes func () exemplar.Reservoir [N ]
307
309
limit limiter [* expoHistogramDataPoint [N ]]
308
- values map [attribute.Set ]* expoHistogramDataPoint [N ]
310
+ values map [attribute.Distinct ]* expoHistogramDataPoint [N ]
309
311
valuesMu sync.Mutex
310
312
311
313
start time.Time
@@ -323,12 +325,12 @@ func (e *expoHistogram[N]) measure(ctx context.Context, value N, fltrAttr attrib
323
325
defer e .valuesMu .Unlock ()
324
326
325
327
attr := e .limit .Attributes (fltrAttr , e .values )
326
- v , ok := e .values [attr ]
328
+ v , ok := e .values [attr . Equivalent () ]
327
329
if ! ok {
328
- v = newExpoHistogramDataPoint [N ](e .maxSize , e .maxScale , e .noMinMax , e .noSum )
330
+ v = newExpoHistogramDataPoint [N ](attr , e .maxSize , e .maxScale , e .noMinMax , e .noSum )
329
331
v .res = e .newRes ()
330
332
331
- e .values [attr ] = v
333
+ e .values [attr . Equivalent () ] = v
332
334
}
333
335
v .record (value )
334
336
v .res .Offer (ctx , t , value , droppedAttr )
@@ -349,32 +351,32 @@ func (e *expoHistogram[N]) delta(dest *metricdata.Aggregation) int {
349
351
hDPts := reset (h .DataPoints , n , n )
350
352
351
353
var i int
352
- for a , b := range e .values {
353
- hDPts [i ].Attributes = a
354
+ for _ , val := range e .values {
355
+ hDPts [i ].Attributes = val . attrs
354
356
hDPts [i ].StartTime = e .start
355
357
hDPts [i ].Time = t
356
- hDPts [i ].Count = b .count
357
- hDPts [i ].Scale = int32 (b .scale )
358
- hDPts [i ].ZeroCount = b .zeroCount
358
+ hDPts [i ].Count = val .count
359
+ hDPts [i ].Scale = int32 (val .scale )
360
+ hDPts [i ].ZeroCount = val .zeroCount
359
361
hDPts [i ].ZeroThreshold = 0.0
360
362
361
- hDPts [i ].PositiveBucket .Offset = int32 (b .posBuckets .startBin )
362
- hDPts [i ].PositiveBucket .Counts = reset (hDPts [i ].PositiveBucket .Counts , len (b .posBuckets .counts ), len (b .posBuckets .counts ))
363
- copy (hDPts [i ].PositiveBucket .Counts , b .posBuckets .counts )
363
+ hDPts [i ].PositiveBucket .Offset = int32 (val .posBuckets .startBin )
364
+ hDPts [i ].PositiveBucket .Counts = reset (hDPts [i ].PositiveBucket .Counts , len (val .posBuckets .counts ), len (val .posBuckets .counts ))
365
+ copy (hDPts [i ].PositiveBucket .Counts , val .posBuckets .counts )
364
366
365
- hDPts [i ].NegativeBucket .Offset = int32 (b .negBuckets .startBin )
366
- hDPts [i ].NegativeBucket .Counts = reset (hDPts [i ].NegativeBucket .Counts , len (b .negBuckets .counts ), len (b .negBuckets .counts ))
367
- copy (hDPts [i ].NegativeBucket .Counts , b .negBuckets .counts )
367
+ hDPts [i ].NegativeBucket .Offset = int32 (val .negBuckets .startBin )
368
+ hDPts [i ].NegativeBucket .Counts = reset (hDPts [i ].NegativeBucket .Counts , len (val .negBuckets .counts ), len (val .negBuckets .counts ))
369
+ copy (hDPts [i ].NegativeBucket .Counts , val .negBuckets .counts )
368
370
369
371
if ! e .noSum {
370
- hDPts [i ].Sum = b .sum
372
+ hDPts [i ].Sum = val .sum
371
373
}
372
374
if ! e .noMinMax {
373
- hDPts [i ].Min = metricdata .NewExtrema (b .min )
374
- hDPts [i ].Max = metricdata .NewExtrema (b .max )
375
+ hDPts [i ].Min = metricdata .NewExtrema (val .min )
376
+ hDPts [i ].Max = metricdata .NewExtrema (val .max )
375
377
}
376
378
377
- b .res .Collect (& hDPts [i ].Exemplars )
379
+ val .res .Collect (& hDPts [i ].Exemplars )
378
380
379
381
i ++
380
382
}
@@ -402,32 +404,32 @@ func (e *expoHistogram[N]) cumulative(dest *metricdata.Aggregation) int {
402
404
hDPts := reset (h .DataPoints , n , n )
403
405
404
406
var i int
405
- for a , b := range e .values {
406
- hDPts [i ].Attributes = a
407
+ for _ , val := range e .values {
408
+ hDPts [i ].Attributes = val . attrs
407
409
hDPts [i ].StartTime = e .start
408
410
hDPts [i ].Time = t
409
- hDPts [i ].Count = b .count
410
- hDPts [i ].Scale = int32 (b .scale )
411
- hDPts [i ].ZeroCount = b .zeroCount
411
+ hDPts [i ].Count = val .count
412
+ hDPts [i ].Scale = int32 (val .scale )
413
+ hDPts [i ].ZeroCount = val .zeroCount
412
414
hDPts [i ].ZeroThreshold = 0.0
413
415
414
- hDPts [i ].PositiveBucket .Offset = int32 (b .posBuckets .startBin )
415
- hDPts [i ].PositiveBucket .Counts = reset (hDPts [i ].PositiveBucket .Counts , len (b .posBuckets .counts ), len (b .posBuckets .counts ))
416
- copy (hDPts [i ].PositiveBucket .Counts , b .posBuckets .counts )
416
+ hDPts [i ].PositiveBucket .Offset = int32 (val .posBuckets .startBin )
417
+ hDPts [i ].PositiveBucket .Counts = reset (hDPts [i ].PositiveBucket .Counts , len (val .posBuckets .counts ), len (val .posBuckets .counts ))
418
+ copy (hDPts [i ].PositiveBucket .Counts , val .posBuckets .counts )
417
419
418
- hDPts [i ].NegativeBucket .Offset = int32 (b .negBuckets .startBin )
419
- hDPts [i ].NegativeBucket .Counts = reset (hDPts [i ].NegativeBucket .Counts , len (b .negBuckets .counts ), len (b .negBuckets .counts ))
420
- copy (hDPts [i ].NegativeBucket .Counts , b .negBuckets .counts )
420
+ hDPts [i ].NegativeBucket .Offset = int32 (val .negBuckets .startBin )
421
+ hDPts [i ].NegativeBucket .Counts = reset (hDPts [i ].NegativeBucket .Counts , len (val .negBuckets .counts ), len (val .negBuckets .counts ))
422
+ copy (hDPts [i ].NegativeBucket .Counts , val .negBuckets .counts )
421
423
422
424
if ! e .noSum {
423
- hDPts [i ].Sum = b .sum
425
+ hDPts [i ].Sum = val .sum
424
426
}
425
427
if ! e .noMinMax {
426
- hDPts [i ].Min = metricdata .NewExtrema (b .min )
427
- hDPts [i ].Max = metricdata .NewExtrema (b .max )
428
+ hDPts [i ].Min = metricdata .NewExtrema (val .min )
429
+ hDPts [i ].Max = metricdata .NewExtrema (val .max )
428
430
}
429
431
430
- b .res .Collect (& hDPts [i ].Exemplars )
432
+ val .res .Collect (& hDPts [i ].Exemplars )
431
433
432
434
i ++
433
435
// TODO (#3006): This will use an unbounded amount of memory if there
0 commit comments