-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathdistribution.go
57 lines (38 loc) · 1.43 KB
/
distribution.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT
package distribution
import (
"errors"
"math"
"go.opentelemetry.io/collector/pdata/pmetric"
)
var (
ErrUnsupportedWeight = errors.New("weight must be larger than 0")
ErrUnsupportedValue = errors.New("value cannot be negative, NaN, Inf, or greater than 2^360")
MinValue = -math.Pow(2, 360)
MaxValue = math.Pow(2, 360)
)
type Distribution interface {
Maximum() float64
Minimum() float64
SampleCount() float64
Sum() float64
ValuesAndCounts() ([]float64, []float64)
Unit() string
Size() int
// weight is 1/samplingRate
AddEntryWithUnit(value float64, weight float64, unit string) error
// weight is 1/samplingRate
AddEntry(value float64, weight float64) error
AddDistribution(distribution Distribution)
AddDistributionWithWeight(distribution Distribution, weight float64)
ConvertToOtel(dp pmetric.HistogramDataPoint)
ConvertFromOtel(dp pmetric.HistogramDataPoint, unit string)
}
var NewDistribution func() Distribution
// IsSupportedValue checks to see if the metric is between the min value and 2^360 and not a NaN.
// This matches the accepted range described in the MetricDatum documentation
// https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html
func IsSupportedValue(value, min, max float64) bool {
return !math.IsNaN(value) && value >= min && value <= max
}