-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
options.go
43 lines (38 loc) · 1.12 KB
/
options.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
package datadog
import (
"fmt"
"strconv"
"time"
)
// ReporterOption is function-option used during the construction of a *Reporter
type ReporterOption func(*Reporter) error
// UseFlushInterval configures the flush tick interval to use with `Flush`
func UseFlushInterval(d time.Duration) ReporterOption {
return func(r *Reporter) error {
r.interval = d
return nil
}
}
// UsePercentiles builds a *Reporter that reports the specified percentiles
// for Histograms and TimedMetrics
func UsePercentiles(percentiles []float64) ReporterOption {
return func(r *Reporter) error {
if len(percentiles) == 0 {
return fmt.Errorf("Must specify at least 1 percentile")
}
var err error
r.percentiles = percentiles
r.p, err = getPercentileNames(percentiles)
return err
}
}
func getPercentileNames(percentiles []float64) ([]string, error) {
names := make([]string, len(percentiles))
for i, percentile := range percentiles {
if percentile <= 0 || percentile >= 1 {
return nil, fmt.Errorf("Percentile must lie in interval (0,1)")
}
names[i] = ".p" + strconv.FormatFloat(percentile, 'f', -1, 64)[2:]
}
return names, nil
}