forked from DataDog/datadog-agent
/
options.go
32 lines (27 loc) · 1.11 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
package telemetry
import "fmt"
// Options for telemetry metrics.
// Creating an Options struct without specifying any of its fields should be the
// equivalent of using the DefaultOptions var.
type Options struct {
// NoDoubleUnderscoreSep is set to true when you don't want to
// separate the subsystem and the name with a double underscore separator.
NoDoubleUnderscoreSep bool
}
// DefaultOptions for telemetry metrics which don't need to specify any option.
var DefaultOptions = Options{
// By default, we want to separate the subsystem and the metric name with a
// double underscore to be able to replace it later in the process.
NoDoubleUnderscoreSep: false,
}
// NameWithSeparator returns name prefixed according to NoDoubleUnderscoreOption.
func (opts *Options) NameWithSeparator(subsystem, name string) string {
// subsystem is optional
if subsystem != "" && !opts.NoDoubleUnderscoreSep {
// Prefix metrics with a _, prometheus will add a second _
// It will create metrics with a custom separator and
// will let us replace it to a dot later in the process.
return fmt.Sprintf("_%s", name)
}
return name
}