-
Notifications
You must be signed in to change notification settings - Fork 450
/
config.go
710 lines (590 loc) · 25.8 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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
// 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"
"fmt"
"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/api/v1/handler/prometheus/handleroptions"
"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"
"github.com/m3db/m3/src/query/storage/m3/consolidators"
"github.com/m3db/m3/src/query/storage/m3/storagemetadata"
xconfig "github.com/m3db/m3/src/x/config"
"github.com/m3db/m3/src/x/config/listenaddress"
"github.com/m3db/m3/src/x/cost"
xdocs "github.com/m3db/m3/src/x/docs"
"github.com/m3db/m3/src/x/instrument"
xlog "github.com/m3db/m3/src/x/log"
"github.com/m3db/m3/src/x/opentracing"
)
// 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"
// NoopEtcdStorageType is for a noop backend which returns empty results for
// any query and blackholes any writes, but requires that a valid etcd cluster
// is defined and can be connected to. Primarily used for standalone
// coordinators used only to serve m3admin APIs.
NoopEtcdStorageType BackendStorageType = "noop-etcd"
defaultCarbonIngesterListenAddress = "0.0.0.0:7204"
errNoIDGenerationScheme = "error: a recent breaking change means that an ID " +
"generation scheme is required in coordinator configuration settings. " +
"More information is available here: %s"
defaultQueryTimeout = 30 * time.Second
defaultPrometheusMaxSamplesPerQuery = 100000000
)
var (
// 5m is the default lookback in Prometheus.
defaultLookbackDuration = 5 * time.Minute
defaultCarbonIngesterAggregationType = aggregation.Mean
defaultStorageQuerySeriesLimit = 10000
defaultStorageQueryDocsLimit = 0 // Default OFF.
)
// Configuration is the configuration for the query service.
type Configuration struct {
// Metrics configuration.
Metrics instrument.MetricsConfiguration `yaml:"metrics"`
// Logging configuration.
Logging xlog.Configuration `yaml:"logging"`
// Tracing configures opentracing. If not provided, tracing is disabled.
Tracing opentracing.TracingConfiguration `yaml:"tracing"`
// 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"`
// WriteForwarding is the write forwarding options.
WriteForwarding WriteForwardingConfiguration `yaml:"writeForwarding"`
// 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"`
// Query is the query configuration.
Query QueryConfiguration `yaml:"query"`
// Limits specifies limits on per-query resource usage.
Limits LimitsConfiguration `yaml:"limits"`
// LookbackDuration determines the lookback duration for queries
LookbackDuration *time.Duration `yaml:"lookbackDuration"`
// ResultOptions are the results options for query.
ResultOptions ResultOptions `yaml:"resultOptions"`
// Experimental is the configuration for the experimental API group.
Experimental ExperimentalAPIConfiguration `yaml:"experimental"`
// Cache configurations.
//
// Deprecated: cache configurations are no longer supported. Remove from file
// when we can make breaking changes.
// (If/when removed it will make existing configurations with the cache
// stanza not able to startup the binary since we parse YAML in strict mode
// by default).
DeprecatedCache CacheConfiguration `yaml:"cache"`
// MultiProcess is the multi-process configuration.
MultiProcess MultiProcessConfiguration `yaml:"multiProcess"`
}
// WriteForwardingConfiguration is the write forwarding configuration.
type WriteForwardingConfiguration struct {
PromRemoteWrite handleroptions.PromWriteHandlerForwardingOptions `yaml:"promRemoteWrite"`
}
// 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"`
}
// CacheConfiguration contains the cache configurations.
type CacheConfiguration struct {
// Deprecated: remove from config.
DeprecatedQueryConversion *DeprecatedQueryConversionCacheConfiguration `yaml:"queryConversion"`
}
// DeprecatedQueryConversionCacheConfiguration is deprecated: remove from config.
type DeprecatedQueryConversionCacheConfiguration struct {
Size *int `yaml:"size"`
}
// ResultOptions are the result options for query.
type ResultOptions struct {
// KeepNans keeps NaNs before returning query results.
// The default is false, which matches Prometheus
KeepNans bool `yaml:"keepNans"`
}
// QueryConfiguration is the query configuration.
type QueryConfiguration struct {
// Timeout is the query timeout.
Timeout *time.Duration `yaml:"timeout"`
// DefaultEngine is the default query engine.
DefaultEngine string `yaml:"defaultEngine"`
// ConsolidationConfiguration are configs for consolidating fetched queries.
ConsolidationConfiguration ConsolidationConfiguration `yaml:"consolidation"`
// Prometheus is prometheus client configuration.
Prometheus PrometheusQueryConfiguration `yaml:"prometheus"`
// RestrictTags is an optional configuration that can be set to restrict
// all queries with certain tags by.
RestrictTags *RestrictTagsConfiguration `yaml:"restrictTags"`
}
// TimeoutOrDefault returns the configured timeout or default value.
func (c QueryConfiguration) TimeoutOrDefault() time.Duration {
if v := c.Timeout; v != nil {
return *v
}
return defaultQueryTimeout
}
// RestrictTagsAsStorageRestrictByTag returns restrict tags as
// storage options to restrict all queries by default.
func (c QueryConfiguration) RestrictTagsAsStorageRestrictByTag() (*storage.RestrictByTag, bool, error) {
if c.RestrictTags == nil {
return nil, false, nil
}
var (
cfg = *c.RestrictTags
result = handleroptions.StringTagOptions{
Restrict: make([]handleroptions.StringMatch, 0, len(cfg.Restrict)),
Strip: cfg.Strip,
}
)
for _, elem := range cfg.Restrict {
value := handleroptions.StringMatch(elem)
result.Restrict = append(result.Restrict, value)
}
opts, err := result.StorageOptions()
if err != nil {
return nil, false, err
}
return opts, true, nil
}
// RestrictTagsConfiguration applies tag restriction to all queries.
type RestrictTagsConfiguration struct {
Restrict []StringMatch `yaml:"match"`
Strip []string `yaml:"strip"`
}
// StringMatch is an easy to use representation of models.Matcher.
type StringMatch struct {
Name string `yaml:"name"`
Type string `yaml:"type"`
Value string `yaml:"value"`
}
// ConsolidationConfiguration are configs for consolidating fetched queries.
type ConsolidationConfiguration struct {
// MatchType determines the options by which series should match.
MatchType consolidators.MatchType `yaml:"matchType"`
}
// PrometheusQueryConfiguration is the prometheus query engine configuration.
type PrometheusQueryConfiguration struct {
// MaxSamplesPerQuery is the limit on fetched samples per query.
MaxSamplesPerQuery *int `yaml:"maxSamplesPerQuery"`
}
// MaxSamplesPerQueryOrDefault returns the max samples per query or default.
func (c PrometheusQueryConfiguration) MaxSamplesPerQueryOrDefault() int {
if v := c.MaxSamplesPerQuery; v != nil {
return *v
}
return defaultPrometheusMaxSamplesPerQuery
}
// LimitsConfiguration represents limitations on resource usage in the query
// instance. Limits are split between per-query and global limits.
type LimitsConfiguration struct {
// PerQuery configures limits which apply to each query individually.
PerQuery PerQueryLimitsConfiguration `yaml:"perQuery"`
// Global configures limits which apply across all queries running on this
// instance.
Global GlobalLimitsConfiguration `yaml:"global"`
// deprecated: use PerQuery.MaxComputedDatapoints instead.
DeprecatedMaxComputedDatapoints int `yaml:"maxComputedDatapoints"`
}
// MaxComputedDatapoints is a getter providing backwards compatibility between
// LimitsConfiguration.DeprecatedMaxComputedDatapoints and
// LimitsConfiguration.PerQuery.PrivateMaxComputedDatapoints. See
// LimitsConfiguration.PerQuery.PrivateMaxComputedDatapoints for a comment on
// the semantics.
func (lc LimitsConfiguration) MaxComputedDatapoints() int {
if lc.PerQuery.PrivateMaxComputedDatapoints != 0 {
return lc.PerQuery.PrivateMaxComputedDatapoints
}
return lc.DeprecatedMaxComputedDatapoints
}
// GlobalLimitsConfiguration represents limits on resource usage across a query
// instance. Zero or negative values imply no limit.
type GlobalLimitsConfiguration struct {
// MaxFetchedDatapoints limits the max number of datapoints allowed to be
// used by all queries at any point in time, this is applied at the query
// service after the result has been returned by a storage node.
MaxFetchedDatapoints int `yaml:"maxFetchedDatapoints"`
}
// AsLimitManagerOptions converts this configuration to
// cost.LimitManagerOptions for MaxFetchedDatapoints.
func (l *GlobalLimitsConfiguration) AsLimitManagerOptions() cost.LimitManagerOptions {
return toLimitManagerOptions(l.MaxFetchedDatapoints)
}
// PerQueryLimitsConfiguration represents limits on resource usage within a
// single query. Zero or negative values imply no limit.
type PerQueryLimitsConfiguration struct {
// MaxFetchedSeries limits the number of time series returned for any given
// individual storage node per query, before returning result to query
// service.
MaxFetchedSeries int `yaml:"maxFetchedSeries"`
// MaxFetchedDocs limits the number of index documents matched for any given
// individual storage node per query, before returning result to query
// service.
MaxFetchedDocs int `yaml:"maxFetchedDocs"`
// RequireExhaustive results in an error if the query exceeds any limit.
RequireExhaustive bool `yaml:"requireExhaustive"`
// MaxFetchedDatapoints limits the max number of datapoints allowed to be
// used by a given query, this is applied at the query service after the
// result has been returned by a storage node.
MaxFetchedDatapoints int `yaml:"maxFetchedDatapoints"`
// PrivateMaxComputedDatapoints limits the number of datapoints that can be
// returned by a query. It's determined purely
// from the size of the time range and the step size (end - start / step).
//
// N.B.: the hacky "Private" prefix is to indicate that callers should use
// LimitsConfiguration.MaxComputedDatapoints() instead of accessing
// this field directly.
PrivateMaxComputedDatapoints int `yaml:"maxComputedDatapoints"`
}
// AsLimitManagerOptions converts this configuration to
// cost.LimitManagerOptions for MaxFetchedDatapoints.
func (l *PerQueryLimitsConfiguration) AsLimitManagerOptions() cost.LimitManagerOptions {
return toLimitManagerOptions(l.MaxFetchedDatapoints)
}
// AsFetchOptionsBuilderLimitsOptions converts this configuration to
// handleroptions.FetchOptionsBuilderLimitsOptions.
func (l *PerQueryLimitsConfiguration) AsFetchOptionsBuilderLimitsOptions() handleroptions.FetchOptionsBuilderLimitsOptions {
seriesLimit := defaultStorageQuerySeriesLimit
if v := l.MaxFetchedSeries; v > 0 {
seriesLimit = v
}
docsLimit := defaultStorageQueryDocsLimit
if v := l.MaxFetchedDocs; v > 0 {
docsLimit = v
}
return handleroptions.FetchOptionsBuilderLimitsOptions{
SeriesLimit: int(seriesLimit),
DocsLimit: int(docsLimit),
RequireExhaustive: l.RequireExhaustive,
}
}
func toLimitManagerOptions(limit int) cost.LimitManagerOptions {
return cost.NewLimitManagerOptions().SetDefaultLimit(cost.Limit{
Threshold: cost.Cost(limit),
Enabled: limit > 0,
})
}
// 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 if set defines an ingester to run for carbon.
Ingester *CarbonIngesterConfiguration `yaml:"ingester"`
// AggregateNamespacesAllData configures whether all aggregate
// namespaces contain entire copies of the data set.
// This affects whether queries can be optimized or not, if false
// they cannot be since it's unclear if data matching an expression
// sits in one or many or none of the aggregate namespaces so all
// must be queried, but if true then it can be determined based
// on the query range whether a single namespace can fulfill the
// entire query and if so to only fetch from that one aggregated namespace.
AggregateNamespacesAllData bool `yaml:"aggregateNamespacesAllData"`
}
// CarbonIngesterConfiguration is the configuration struct for carbon ingestion.
type CarbonIngesterConfiguration struct {
// Deprecated: simply use the logger debug level, this has been deprecated
// in favor of setting the log level to debug.
DeprecatedDebug 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
}
// ListenAddressOrDefault returns the specified carbon ingester listen address if provided, or the
// default value if not.
func (c *CarbonIngesterConfiguration) ListenAddressOrDefault() string {
if c.ListenAddress != "" {
return c.ListenAddress
}
return defaultCarbonIngesterListenAddress
}
// 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 == storagemetadata.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"`
Continue bool `yaml:"continue"`
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"`
}
// RemoteConfigurations is a set of remote host configurations.
type RemoteConfigurations []RemoteConfiguration
// RemoteConfiguration is the configuration for a single remote host.
type RemoteConfiguration struct {
// Name is the name for the remote zone.
Name string `yaml:"name"`
// RemoteListenAddresses is the remote listen addresses to call for remote
// coordinator calls in the remote zone.
RemoteListenAddresses []string `yaml:"remoteListenAddresses"`
// ErrorBehavior overrides the default error behavior for this host.
//
// NB: defaults to warning on error.
ErrorBehavior *storage.ErrorBehavior `yaml:"errorBehavior"`
}
// 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.
//
// NB: this is no longer necessary to set to true if RPC is desired; enabled
// status is inferred based on which other options are provided;
// this remains for back-compat, and for disabling any existing RPC options.
Enabled *bool `yaml:"enabled"`
// ListenAddress is the RPC server listen address.
ListenAddress string `yaml:"listenAddress"`
// Remotes are the configuration settings for remote coordinator zones.
Remotes RemoteConfigurations `yaml:"remotes"`
// RemoteListenAddresses is the remote listen addresses to call for
// remote coordinator calls.
//
// NB: this is deprecated in favor of using RemoteZones, as setting
// RemoteListenAddresses will only allow for a single remote zone to be used.
RemoteListenAddresses []string `yaml:"remoteListenAddresses"`
// ErrorBehavior overrides the default error behavior for all rpc hosts.
//
// NB: defaults to warning on error.
ErrorBehavior *storage.ErrorBehavior `yaml:"errorBehavior"`
// ReflectionEnabled will enable reflection on the GRPC server, useful
// for testing connectivity with grpcurl, etc.
ReflectionEnabled bool `yaml:"reflectionEnabled"`
}
// 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"`
// BucketName specifies the tag name that corresponds to the metric's bucket.
// If not provided, defaults to `le`.
BucketName string `yaml:"bucketName"`
// Scheme determines the default ID generation scheme. Defaults to TypeLegacy.
Scheme models.IDSchemeType `yaml:"idScheme"`
// Filters are optional tag filters, removing all series with tags
// matching the filter from computations.
Filters []TagFilter `yaml:"filters"`
// AllowTagNameDuplicates allows for duplicate tags to appear on series.
AllowTagNameDuplicates bool `yaml:"allowTagNameDuplicates"`
// AllowTagValueEmpty allows for empty tags to appear on series.
AllowTagValueEmpty bool `yaml:"allowTagValueEmpty"`
}
// TagFilter is a tag filter.
type TagFilter struct {
// Values are the values to filter.
//
// NB:If this is unset, all series containing
// a tag with given `Name` are filtered.
Values []string `yaml:"values"`
// Name is the tag name.
Name string `yaml:"name"`
}
// 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))
}
bucket := cfg.BucketName
if bucket != "" {
opts = opts.SetBucketName([]byte(bucket))
}
if cfg.Scheme == models.TypeDefault {
// If no config has been set, error.
docLink := xdocs.Path("how_to/query#migration")
return nil, fmt.Errorf(errNoIDGenerationScheme, docLink)
}
opts = opts.SetIDSchemeType(cfg.Scheme)
if err := opts.Validate(); err != nil {
return nil, err
}
if cfg.Filters != nil {
filters := make([]models.Filter, 0, len(cfg.Filters))
for _, filter := range cfg.Filters {
values := make([][]byte, 0, len(filter.Values))
for _, strVal := range filter.Values {
values = append(values, []byte(strVal))
}
filters = append(filters, models.Filter{
Name: []byte(filter.Name),
Values: values,
})
}
opts = opts.SetFilters(filters)
}
opts = opts.SetAllowTagNameDuplicates(cfg.AllowTagNameDuplicates)
opts = opts.SetAllowTagValueEmpty(cfg.AllowTagValueEmpty)
return opts, nil
}
// ExperimentalAPIConfiguration is the configuration for the experimental API group.
type ExperimentalAPIConfiguration struct {
Enabled bool `yaml:"enabled"`
}
// MultiProcessConfiguration is the multi-process configuration which
// allows running multiple sub-processes of an instance reusing the
// same listen ports.
type MultiProcessConfiguration struct {
// Enabled is whether to enable multi-process execution.
Enabled bool `yaml:"enabled"`
// Count is the number of sub-processes to run, leave zero
// to auto-detect based on number of CPUs.
Count int `yaml:"count" validate:"min=0"`
// PerCPU is the factor of processes to run per CPU, leave
// zero to use the default of 0.5 per CPU (i.e. one process for
// every two CPUs).
PerCPU float64 `yaml:"perCPU" validate:"min=0.0, max=0.0"`
// GoMaxProcs if set will explicitly set the child GOMAXPROCs env var.
GoMaxProcs int `yaml:"goMaxProcs"`
}