-
Notifications
You must be signed in to change notification settings - Fork 487
/
config.go
91 lines (79 loc) · 3.12 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package spanmetrics
import (
"flag"
"fmt"
"github.com/grafana/tempo/pkg/sharedconfig"
filterconfig "github.com/grafana/tempo/pkg/spanfilter/config"
"github.com/prometheus/client_golang/prometheus"
)
const (
Name = "span-metrics"
dimService = "service"
dimSpanName = "span_name"
dimSpanKind = "span_kind"
dimStatusCode = "status_code"
dimStatusMessage = "status_message"
dimJob = "job"
dimInstance = "instance"
)
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, status_code, job and instance 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"`
// Dimension label mapping to allow the user to rename attributes in their metrics
DimensionMappings []sharedconfig.DimensionMappings `yaml:"dimension_mappings"`
// Enable target_info as a metrics
EnableTargetInfo bool `yaml:"enable_target_info"`
// If enabled attribute value will be used for metric calculation
SpanMultiplierKey string `yaml:"span_multiplier_key"`
// Subprocessor options for this Processor include Latency, Count, Size
// These are metrics categories that exist under the umbrella of Span Metrics
Subprocessors map[Subprocessor]bool
// FilterPolicies is a list of policies that will be applied to spans for inclusion or exlusion.
FilterPolicies []filterconfig.FilterPolicy `yaml:"filter_policies"`
// Allow user to specify labels they want to drop from target_info
TargetInfoExcludedDimensions []string `yaml:"target_info_excluded_dimensions"`
}
func (cfg *Config) RegisterFlagsAndApplyDefaults(string, *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
cfg.Subprocessors = make(map[Subprocessor]bool)
cfg.Subprocessors[Latency] = true
cfg.Subprocessors[Count] = true
cfg.Subprocessors[Size] = 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 fmt.Errorf("%s is not a valid intrinsic dimension", label)
}
}
return nil
}