-
Notifications
You must be signed in to change notification settings - Fork 532
/
Copy pathconfig.go
66 lines (58 loc) · 1.97 KB
/
config.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
58
59
60
61
62
63
64
65
66
package spanmetrics
import (
"flag"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
)
const (
Name = "span-metrics"
dimService = "service"
dimSpanName = "span_name"
dimSpanKind = "span_kind"
dimStatusCode = "status_code"
dimStatusMessage = "status_message"
)
type Config struct {
// Buckets for latency histogram in seconds.
HistogramBuckets []float64 `yaml:"histogram_buckets"`
// Intrinsic dimensions (labels) added to the metric, that are generated from fixed span
// data. The dimensions service, span_name, span_kind, and status_code are enabled by
// default, whereas the dimension status_message must be enabled explicitly.
IntrinsicDimensions IntrinsicDimensions `yaml:"intrinsic_dimensions"`
// Additional dimensions (labels) to be added to the metric. The dimensions are generated
// from span attributes and are created along with the intrinsic dimensions.
Dimensions []string `yaml:"dimensions"`
}
func (cfg *Config) RegisterFlagsAndApplyDefaults(prefix string, f *flag.FlagSet) {
cfg.HistogramBuckets = prometheus.ExponentialBuckets(0.002, 2, 14)
cfg.IntrinsicDimensions.Service = true
cfg.IntrinsicDimensions.SpanName = true
cfg.IntrinsicDimensions.SpanKind = true
cfg.IntrinsicDimensions.StatusCode = true
}
type IntrinsicDimensions struct {
Service bool `yaml:"service"`
SpanName bool `yaml:"span_name"`
SpanKind bool `yaml:"span_kind"`
StatusCode bool `yaml:"status_code"`
StatusMessage bool `yaml:"status_message,omitempty"`
}
func (ic *IntrinsicDimensions) ApplyFromMap(dimensions map[string]bool) error {
for label, active := range dimensions {
switch label {
case dimService:
ic.Service = active
case dimSpanName:
ic.SpanName = active
case dimSpanKind:
ic.SpanKind = active
case dimStatusCode:
ic.StatusCode = active
case dimStatusMessage:
ic.StatusMessage = active
default:
return errors.Errorf("%s is not a valid intrinsic dimension", label)
}
}
return nil
}