@@ -27,6 +27,8 @@ import (
27
27
)
28
28
29
29
const (
30
+ prefix = "prometheus"
31
+
30
32
suffixServerURL = ".server-url"
31
33
suffixConnectTimeout = ".connect-timeout"
32
34
suffixTokenFilePath = ".token-file"
@@ -48,18 +50,13 @@ const (
48
50
defaultNormalizeDuration = false
49
51
)
50
52
51
- type namespaceConfig struct {
52
- config.Configuration `mapstructure:",squash"`
53
- namespace string
54
- }
55
-
56
53
// Options stores the configuration entries for this storage.
57
54
type Options struct {
58
- Primary namespaceConfig `mapstructure:",squash"`
55
+ config. Configuration `mapstructure:",squash"`
59
56
}
60
57
61
58
// NewOptions creates a new Options struct.
62
- func NewOptions (primaryNamespace string ) * Options {
59
+ func NewOptions () * Options {
63
60
defaultConfig := config.Configuration {
64
61
ServerURL : defaultServerURL ,
65
62
ConnectTimeout : defaultConnectTimeout ,
@@ -71,75 +68,70 @@ func NewOptions(primaryNamespace string) *Options {
71
68
}
72
69
73
70
return & Options {
74
- Primary : namespaceConfig {
75
- Configuration : defaultConfig ,
76
- namespace : primaryNamespace ,
77
- },
71
+ Configuration : defaultConfig ,
78
72
}
79
73
}
80
74
81
75
// AddFlags from this storage to the CLI.
82
76
func (opt * Options ) AddFlags (flagSet * flag.FlagSet ) {
83
- nsConfig := & opt .Primary
84
- flagSet .String (nsConfig .namespace + suffixServerURL , defaultServerURL ,
77
+ flagSet .String (prefix + suffixServerURL , defaultServerURL ,
85
78
"The Prometheus server's URL, must include the protocol scheme e.g. http://localhost:9090" )
86
- flagSet .Duration (nsConfig . namespace + suffixConnectTimeout , defaultConnectTimeout ,
79
+ flagSet .Duration (prefix + suffixConnectTimeout , defaultConnectTimeout ,
87
80
"The period to wait for a connection to Prometheus when executing queries." )
88
- flagSet .String (nsConfig . namespace + suffixTokenFilePath , defaultTokenFilePath ,
81
+ flagSet .String (prefix + suffixTokenFilePath , defaultTokenFilePath ,
89
82
"The path to a file containing the bearer token which will be included when executing queries against the Prometheus API." )
90
- flagSet .Bool (nsConfig . namespace + suffixOverrideFromContext , true ,
83
+ flagSet .Bool (prefix + suffixOverrideFromContext , true ,
91
84
"Whether the bearer token should be overridden from context (incoming request)" )
92
- flagSet .String (nsConfig . namespace + suffixMetricNamespace , defaultMetricNamespace ,
85
+ flagSet .String (prefix + suffixMetricNamespace , defaultMetricNamespace ,
93
86
`The metric namespace that is prefixed to the metric name. A '.' separator will be added between ` +
94
87
`the namespace and the metric name.` )
95
- flagSet .String (nsConfig . namespace + suffixLatencyUnit , defaultLatencyUnit ,
88
+ flagSet .String (prefix + suffixLatencyUnit , defaultLatencyUnit ,
96
89
`The units used for the "latency" histogram. It can be either "ms" or "s" and should be consistent with the ` +
97
90
`histogram unit value set in the spanmetrics connector (see: ` +
98
91
`https://github.com/open-telemetry/opentelemetry-collector-contrib/tree/main/connector/spanmetricsconnector#configurations). ` +
99
92
`This also helps jaeger-query determine the metric name when querying for "latency" metrics.` )
100
- flagSet .Bool (nsConfig . namespace + suffixNormalizeCalls , defaultNormalizeCalls ,
93
+ flagSet .Bool (prefix + suffixNormalizeCalls , defaultNormalizeCalls ,
101
94
`Whether to normalize the "calls" metric name according to ` +
102
95
`https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/translator/prometheus/README.md. ` +
103
96
`For example: ` +
104
97
`"calls" (not normalized) -> "calls_total" (normalized), ` )
105
- flagSet .Bool (nsConfig . namespace + suffixNormalizeDuration , defaultNormalizeDuration ,
98
+ flagSet .Bool (prefix + suffixNormalizeDuration , defaultNormalizeDuration ,
106
99
`Whether to normalize the "duration" metric name according to ` +
107
100
`https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/translator/prometheus/README.md. ` +
108
101
`For example: ` +
109
102
`"duration_bucket" (not normalized) -> "duration_milliseconds_bucket (normalized)"` )
110
103
111
- nsConfig .getTLSFlagsConfig ().AddFlags (flagSet )
104
+ opt .getTLSFlagsConfig ().AddFlags (flagSet )
112
105
}
113
106
114
107
// InitFromViper initializes the options struct with values from Viper.
115
108
func (opt * Options ) InitFromViper (v * viper.Viper ) error {
116
- cfg := & opt .Primary
117
- cfg .ServerURL = stripWhiteSpace (v .GetString (cfg .namespace + suffixServerURL ))
118
- cfg .ConnectTimeout = v .GetDuration (cfg .namespace + suffixConnectTimeout )
119
- cfg .TokenFilePath = v .GetString (cfg .namespace + suffixTokenFilePath )
109
+ opt .ServerURL = stripWhiteSpace (v .GetString (prefix + suffixServerURL ))
110
+ opt .ConnectTimeout = v .GetDuration (prefix + suffixConnectTimeout )
111
+ opt .TokenFilePath = v .GetString (prefix + suffixTokenFilePath )
120
112
121
- cfg .MetricNamespace = v .GetString (cfg . namespace + suffixMetricNamespace )
122
- cfg .LatencyUnit = v .GetString (cfg . namespace + suffixLatencyUnit )
123
- cfg .NormalizeCalls = v .GetBool (cfg . namespace + suffixNormalizeCalls )
124
- cfg .NormalizeDuration = v .GetBool (cfg . namespace + suffixNormalizeDuration )
125
- cfg .TokenOverrideFromContext = v .GetBool (cfg . namespace + suffixOverrideFromContext )
113
+ opt .MetricNamespace = v .GetString (prefix + suffixMetricNamespace )
114
+ opt .LatencyUnit = v .GetString (prefix + suffixLatencyUnit )
115
+ opt .NormalizeCalls = v .GetBool (prefix + suffixNormalizeCalls )
116
+ opt .NormalizeDuration = v .GetBool (prefix + suffixNormalizeDuration )
117
+ opt .TokenOverrideFromContext = v .GetBool (prefix + suffixOverrideFromContext )
126
118
127
119
isValidUnit := map [string ]bool {"ms" : true , "s" : true }
128
- if _ , ok := isValidUnit [cfg .LatencyUnit ]; ! ok {
129
- return fmt .Errorf (`duration-unit must be one of "ms" or "s", not %q` , cfg .LatencyUnit )
120
+ if _ , ok := isValidUnit [opt .LatencyUnit ]; ! ok {
121
+ return fmt .Errorf (`duration-unit must be one of "ms" or "s", not %q` , opt .LatencyUnit )
130
122
}
131
123
132
124
var err error
133
- cfg .TLS , err = cfg .getTLSFlagsConfig ().InitFromViper (v )
125
+ opt .TLS , err = opt .getTLSFlagsConfig ().InitFromViper (v )
134
126
if err != nil {
135
127
return fmt .Errorf ("failed to process Prometheus TLS options: %w" , err )
136
128
}
137
129
return nil
138
130
}
139
131
140
- func (config * namespaceConfig ) getTLSFlagsConfig () tlscfg.ClientFlagsConfig {
132
+ func (* Options ) getTLSFlagsConfig () tlscfg.ClientFlagsConfig {
141
133
return tlscfg.ClientFlagsConfig {
142
- Prefix : config . namespace ,
134
+ Prefix : prefix ,
143
135
}
144
136
}
145
137
0 commit comments