-
Notifications
You must be signed in to change notification settings - Fork 458
/
Copy pathconfig.go
324 lines (265 loc) · 11.4 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
// Copyright (c) 2018 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package config
import (
"errors"
"time"
etcdclient "github.com/m3db/m3/src/cluster/client/etcd"
"github.com/m3db/m3/src/cmd/services/m3coordinator/downsample"
ingestm3msg "github.com/m3db/m3/src/cmd/services/m3coordinator/ingest/m3msg"
"github.com/m3db/m3/src/cmd/services/m3coordinator/server/m3msg"
"github.com/m3db/m3/src/metrics/aggregation"
"github.com/m3db/m3/src/query/graphite/graphite"
"github.com/m3db/m3/src/query/models"
"github.com/m3db/m3/src/query/storage"
"github.com/m3db/m3/src/query/storage/m3"
xconfig "github.com/m3db/m3x/config"
"github.com/m3db/m3x/config/listenaddress"
"github.com/m3db/m3x/instrument"
)
// BackendStorageType is an enum for different backends.
type BackendStorageType string
const (
// GRPCStorageType is for backends which only support grpc endpoints.
GRPCStorageType BackendStorageType = "grpc"
// M3DBStorageType is for m3db backend.
M3DBStorageType BackendStorageType = "m3db"
defaultCarbonIngesterListenAddress = "0.0.0.0:7204"
)
var (
// 5m is the default lookback in Prometheus
defaultLookbackDuration = 5 * time.Minute
defaultCarbonIngesterWriteTimeout = 15 * time.Second
defaultCarbonIngesterAggregationType = aggregation.Mean
// defaultLimitsConfiguration is applied if `limits` isn't specified.
defaultLimitsConfiguration = &LimitsConfiguration{
// this is sufficient for 1 day span / 1s step, or 60 days with a 1m step.
MaxComputedDatapoints: 86400,
}
)
// Configuration is the configuration for the query service.
type Configuration struct {
// Metrics configuration.
Metrics instrument.MetricsConfiguration `yaml:"metrics"`
// Clusters is the DB cluster configurations for read, write and
// query endpoints.
Clusters m3.ClustersStaticConfiguration `yaml:"clusters"`
// LocalConfiguration is the local embedded configuration if running
// coordinator embedded in the DB.
Local *LocalConfiguration `yaml:"local"`
// ClusterManagement for placemement, namespaces and database management
// endpoints (optional).
ClusterManagement *ClusterManagementConfiguration `yaml:"clusterManagement"`
// ListenAddress is the server listen address.
ListenAddress *listenaddress.Configuration `yaml:"listenAddress" validate:"nonzero"`
// Filter is the read/write/complete tags filter configuration.
Filter FilterConfiguration `yaml:"filter"`
// RPC is the RPC configuration.
RPC *RPCConfiguration `yaml:"rpc"`
// Backend is the backend store for query service. We currently support grpc and m3db (default).
Backend BackendStorageType `yaml:"backend"`
// TagOptions is the tag configuration options.
TagOptions TagOptionsConfiguration `yaml:"tagOptions"`
// ReadWorkerPool is the worker pool policy for read requests.
ReadWorkerPool xconfig.WorkerPoolPolicy `yaml:"readWorkerPoolPolicy"`
// WriteWorkerPool is the worker pool policy for write requests.
WriteWorkerPool xconfig.WorkerPoolPolicy `yaml:"writeWorkerPoolPolicy"`
// Downsample configurates how the metrics should be downsampled.
Downsample downsample.Configuration `yaml:"downsample"`
// Ingest is the ingest server.
Ingest *IngestConfiguration `yaml:"ingest"`
// Carbon is the carbon configuration.
Carbon *CarbonConfiguration `yaml:"carbon"`
// Limits specifies limits on per-query resource usage.
Limits LimitsConfiguration `yaml:"limits"`
// LookbackDuration determines the lookback duration for queries
LookbackDuration *time.Duration `yaml:"lookbackDuration"`
}
// Filter is a query filter type.
type Filter string
const (
// FilterLocalOnly is a filter that specifies local only storage should be used.
FilterLocalOnly Filter = "local_only"
// FilterRemoteOnly is a filter that specifies remote only storage should be used.
FilterRemoteOnly Filter = "remote_only"
// FilterAllowAll is a filter that specifies all storages should be used.
FilterAllowAll Filter = "allow_all"
// FilterAllowNone is a filter that specifies no storages should be used.
FilterAllowNone Filter = "allow_none"
)
// FilterConfiguration is the filters for write/read/complete tags storage filters.
type FilterConfiguration struct {
Read Filter `yaml:"read"`
Write Filter `yaml:"write"`
CompleteTags Filter `yaml:"completeTags"`
}
// LimitsConfiguration represents limitations on per-query resource usage. Zero or negative values imply no limit.
type LimitsConfiguration struct {
MaxComputedDatapoints int64 `yaml:"maxComputedDatapoints"`
}
// IngestConfiguration is the configuration for ingestion server.
type IngestConfiguration struct {
// Ingester is the configuration for storage based ingester.
Ingester ingestm3msg.Configuration `yaml:"ingester"`
// M3Msg is the configuration for m3msg server.
M3Msg m3msg.Configuration `yaml:"m3msg"`
}
// CarbonConfiguration is the configuration for the carbon server.
type CarbonConfiguration struct {
Ingester *CarbonIngesterConfiguration `yaml:"ingester"`
}
// CarbonIngesterConfiguration is the configuration struct for carbon ingestion.
type CarbonIngesterConfiguration struct {
Debug bool `yaml:"debug"`
ListenAddress string `yaml:"listenAddress"`
MaxConcurrency int `yaml:"maxConcurrency"`
Rules []CarbonIngesterRuleConfiguration `yaml:"rules"`
}
// LookbackDurationOrDefault validates the LookbackDuration
func (c Configuration) LookbackDurationOrDefault() (time.Duration, error) {
if c.LookbackDuration == nil {
return defaultLookbackDuration, nil
}
v := *c.LookbackDuration
if v < 0 {
return 0, errors.New("lookbackDuration must be > 0")
}
return v, nil
}
// RulesOrDefault returns the specified carbon ingester rules if provided, or generates reasonable
// defaults using the provided aggregated namespaces if not.
func (c *CarbonIngesterConfiguration) RulesOrDefault(namespaces m3.ClusterNamespaces) []CarbonIngesterRuleConfiguration {
if len(c.Rules) > 0 {
return c.Rules
}
if namespaces.NumAggregatedClusterNamespaces() == 0 {
return nil
}
// Default to fanning out writes for all metrics to all aggregated namespaces if any exists.
policies := []CarbonIngesterStoragePolicyConfiguration{}
for _, ns := range namespaces {
if ns.Options().Attributes().MetricsType == storage.AggregatedMetricsType {
policies = append(policies, CarbonIngesterStoragePolicyConfiguration{
Resolution: ns.Options().Attributes().Resolution,
Retention: ns.Options().Attributes().Retention,
})
}
}
if len(policies) == 0 {
return nil
}
// Create a single catch-all rule with a policy for each of the aggregated namespaces we
// enumerated above.
aggregationEnabled := true
return []CarbonIngesterRuleConfiguration{
{
Pattern: graphite.MatchAllPattern,
Aggregation: CarbonIngesterAggregationConfiguration{
Enabled: &aggregationEnabled,
Type: &defaultCarbonIngesterAggregationType,
},
Policies: policies,
},
}
}
// CarbonIngesterRuleConfiguration is the configuration struct for a carbon
// ingestion rule.
type CarbonIngesterRuleConfiguration struct {
Pattern string `yaml:"pattern"`
Aggregation CarbonIngesterAggregationConfiguration `yaml:"aggregation"`
Policies []CarbonIngesterStoragePolicyConfiguration `yaml:"policies"`
}
// CarbonIngesterAggregationConfiguration is the configuration struct
// for the aggregation for a carbon ingest rule's storage policy.
type CarbonIngesterAggregationConfiguration struct {
Enabled *bool `yaml:"enabled"`
Type *aggregation.Type `yaml:"type"`
}
// EnabledOrDefault returns whether aggregation should be enabled based on the provided configuration,
// or a default value otherwise.
func (c *CarbonIngesterAggregationConfiguration) EnabledOrDefault() bool {
if c.Enabled != nil {
return *c.Enabled
}
return true
}
// TypeOrDefault returns the aggregation type that should be used based on the provided configuration,
// or a default value otherwise.
func (c *CarbonIngesterAggregationConfiguration) TypeOrDefault() aggregation.Type {
if c.Type != nil {
return *c.Type
}
return defaultCarbonIngesterAggregationType
}
// CarbonIngesterStoragePolicyConfiguration is the configuration struct for
// a carbon rule's storage policies.
type CarbonIngesterStoragePolicyConfiguration struct {
Resolution time.Duration `yaml:"resolution" validate:"nonzero"`
Retention time.Duration `yaml:"retention" validate:"nonzero"`
}
// LocalConfiguration is the local embedded configuration if running
// coordinator embedded in the DB.
type LocalConfiguration struct {
// Namespaces is the list of namespaces that the local embedded DB has.
Namespaces []m3.ClusterStaticNamespaceConfiguration `yaml:"namespaces"`
}
// ClusterManagementConfiguration is configuration for the placemement,
// namespaces and database management endpoints (optional).
type ClusterManagementConfiguration struct {
// Etcd is the client configuration for etcd.
Etcd etcdclient.Configuration `yaml:"etcd"`
}
// RPCConfiguration is the RPC configuration for the coordinator for
// the GRPC server used for remote coordinator to coordinator calls.
type RPCConfiguration struct {
// Enabled determines if coordinator RPC is enabled for remote calls.
Enabled bool `yaml:"enabled"`
// ListenAddress is the RPC server listen address.
ListenAddress string `yaml:"listenAddress"`
// RemoteListenAddresses is the remote listen addresses to call for remote
// coordinator calls.
RemoteListenAddresses []string `yaml:"remoteListenAddresses"`
}
// TagOptionsConfiguration is the configuration for shared tag options
// Currently only name, but can expand to cover deduplication settings, or other
// relevant options.
type TagOptionsConfiguration struct {
// MetricName specifies the tag name that corresponds to the metric's name tag
// If not provided, defaults to `__name__`.
MetricName string `yaml:"metricName"`
// Scheme determines the default ID generation scheme. Defaults to TypeLegacy.
Scheme models.IDSchemeType `yaml:"idScheme"`
}
// TagOptionsFromConfig translates tag option configuration into tag options.
func TagOptionsFromConfig(cfg TagOptionsConfiguration) (models.TagOptions, error) {
opts := models.NewTagOptions()
name := cfg.MetricName
if name != "" {
opts = opts.SetMetricName([]byte(name))
}
if cfg.Scheme == models.TypeDefault {
cfg.Scheme = models.TypeLegacy
}
opts = opts.SetIDSchemeType(cfg.Scheme)
if err := opts.Validate(); err != nil {
return nil, err
}
return opts, nil
}