Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aos
GitHub Repository: aos/grafana-agent
Path: blob/main/pkg/metrics/cluster/config.go
4094 views
1
package cluster
2
3
import (
4
"flag"
5
"reflect"
6
"strings"
7
"time"
8
9
util_log "github.com/cortexproject/cortex/pkg/util/log"
10
"github.com/grafana/agent/pkg/metrics/cluster/client"
11
flagutil "github.com/grafana/agent/pkg/util"
12
"github.com/grafana/dskit/kv"
13
"github.com/grafana/dskit/ring"
14
)
15
16
// DefaultConfig provides default values for the config
17
var DefaultConfig = *flagutil.DefaultConfigFromFlags(&Config{}).(*Config)
18
19
// KVConfig wraps the kv.Config type to allow defining IsZero, which is required to make omitempty work when marshalling YAML.
20
type KVConfig struct {
21
kv.Config `yaml:",inline"`
22
}
23
24
func (k KVConfig) IsZero() bool {
25
return reflect.DeepEqual(k, KVConfig{}) || reflect.DeepEqual(k, DefaultConfig.KVStore)
26
}
27
28
// LifecyclerConfig wraps the ring.LifecyclerConfig type to allow defining IsZero, which is required to make omitempty work when marshalling YAML.
29
type LifecyclerConfig struct {
30
ring.LifecyclerConfig `yaml:",inline"`
31
}
32
33
func (l LifecyclerConfig) IsZero() bool {
34
return reflect.DeepEqual(l, LifecyclerConfig{}) || reflect.DeepEqual(l, DefaultConfig.Lifecycler)
35
}
36
37
// Config describes how to instantiate a scraping service Server instance.
38
type Config struct {
39
Enabled bool `yaml:"enabled,omitempty"`
40
ReshardInterval time.Duration `yaml:"reshard_interval,omitempty"`
41
ReshardTimeout time.Duration `yaml:"reshard_timeout,omitempty"`
42
ClusterReshardEventTimeout time.Duration `yaml:"cluster_reshard_event_timeout,omitempty"`
43
KVStore KVConfig `yaml:"kvstore,omitempty"`
44
Lifecycler LifecyclerConfig `yaml:"lifecycler,omitempty"`
45
46
DangerousAllowReadingFiles bool `yaml:"dangerous_allow_reading_files,omitempty"`
47
48
// TODO(rfratto): deprecate scraping_service_client in Agent and replace with this.
49
Client client.Config `yaml:"-"`
50
APIEnableGetConfiguration bool `yaml:"-"`
51
}
52
53
// UnmarshalYAML implements yaml.Unmarshaler.
54
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
55
*c = DefaultConfig
56
57
type plain Config
58
err := unmarshal((*plain)(c))
59
if err != nil {
60
return err
61
}
62
c.Lifecycler.RingConfig.ReplicationFactor = 1
63
return nil
64
}
65
66
func (c Config) IsZero() bool {
67
return reflect.DeepEqual(c, Config{}) || reflect.DeepEqual(c, DefaultConfig)
68
}
69
70
// RegisterFlags adds the flags required to config the Server to the given
71
// FlagSet.
72
func (c *Config) RegisterFlags(f *flag.FlagSet) {
73
c.RegisterFlagsWithPrefix("", f)
74
}
75
76
// RegisterFlagsWithPrefix adds the flags required to config this to the given
77
// FlagSet with a specified prefix.
78
func (c *Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) {
79
f.BoolVar(&c.Enabled, prefix+"enabled", false, "enables the scraping service mode")
80
f.DurationVar(&c.ReshardInterval, prefix+"reshard-interval", time.Minute*1, "how often to manually refresh configuration")
81
f.DurationVar(&c.ReshardTimeout, prefix+"reshard-timeout", time.Second*30, "timeout for refreshing the configuration. Timeout of 0s disables timeout.")
82
f.DurationVar(&c.ClusterReshardEventTimeout, prefix+"cluster-reshard-event-timeout", time.Second*30, "timeout for the cluster reshard. Timeout of 0s disables timeout.")
83
c.KVStore.RegisterFlagsWithPrefix(prefix+"config-store.", "configurations/", f)
84
c.Lifecycler.RegisterFlagsWithPrefix(prefix, f, util_log.Logger)
85
86
// GRPCClientConfig.RegisterFlags expects that prefix does not end in a ".",
87
// unlike all other flags.
88
noDotPrefix := strings.TrimSuffix(prefix, ".")
89
c.Client.GRPCClientConfig.RegisterFlagsWithPrefix(noDotPrefix, f)
90
}
91
92