forked from grafana/loki
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
89 lines (71 loc) · 2.87 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
package ruler
import (
"flag"
"fmt"
"time"
"github.com/pkg/errors"
"github.com/prometheus/prometheus/config"
"gopkg.in/yaml.v2"
ruler "github.com/frelon/loki/v2/pkg/ruler/base"
"github.com/frelon/loki/v2/pkg/ruler/storage/cleaner"
"github.com/frelon/loki/v2/pkg/ruler/storage/instance"
)
type Config struct {
ruler.Config `yaml:",inline"`
WAL instance.Config `yaml:"wal,omitempty"`
// we cannot define this in the WAL config since it creates an import cycle
WALCleaner cleaner.Config `yaml:"wal_cleaner,omitempty"`
RemoteWrite RemoteWriteConfig `yaml:"remote_write,omitempty"`
}
func (c *Config) RegisterFlags(f *flag.FlagSet) {
c.Config.RegisterFlags(f)
c.RemoteWrite.RegisterFlags(f)
c.WAL.RegisterFlags(f)
c.WALCleaner.RegisterFlags(f)
// TODO(owen-d, 3.0.0): remove deprecated experimental prefix in Cortex if they'll accept it.
f.BoolVar(&c.Config.EnableAPI, "ruler.enable-api", true, "Enable the ruler api")
}
// Validate overrides the embedded cortex variant which expects a cortex limits struct. Instead copy the relevant bits over.
func (c *Config) Validate() error {
if err := c.StoreConfig.Validate(); err != nil {
return fmt.Errorf("invalid ruler store config: %w", err)
}
if err := c.RemoteWrite.Validate(); err != nil {
return fmt.Errorf("invalid ruler remote-write config: %w", err)
}
return nil
}
type RemoteWriteConfig struct {
Client config.RemoteWriteConfig `yaml:"client"`
Enabled bool `yaml:"enabled"`
ConfigRefreshPeriod time.Duration `yaml:"config_refresh_period"`
}
func (c *RemoteWriteConfig) Validate() error {
if c.Enabled && c.Client.URL == nil {
return errors.New("remote-write enabled but client URL is not configured")
}
return nil
}
func (c *RemoteWriteConfig) Clone() (*RemoteWriteConfig, error) {
out, err := yaml.Marshal(c)
if err != nil {
return nil, err
}
var n *RemoteWriteConfig
err = yaml.Unmarshal(out, &n)
if err != nil {
return nil, err
}
// BasicAuth.Password has a type of Secret (github.com/prometheus/common/config/config.go),
// so when its value is marshaled it is obfuscated as "<secret>".
// Here we copy the original password into the cloned config.
if n.Client.HTTPClientConfig.BasicAuth != nil {
n.Client.HTTPClientConfig.BasicAuth.Password = c.Client.HTTPClientConfig.BasicAuth.Password
}
return n, nil
}
// RegisterFlags adds the flags required to config this to the given FlagSet.
func (c *RemoteWriteConfig) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&c.Enabled, "ruler.remote-write.enabled", false, "Remote-write recording rule samples to Prometheus-compatible remote-write receiver.")
f.DurationVar(&c.ConfigRefreshPeriod, "ruler.remote-write.config-refresh-period", 10*time.Second, "Minimum period to wait between refreshing remote-write reconfigurations. This should be greater than or equivalent to -limits.per-user-override-period.")
}