-
Notifications
You must be signed in to change notification settings - Fork 487
/
config.go
66 lines (55 loc) · 2.13 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
package storage
import (
"flag"
"time"
prometheus_config "github.com/prometheus/prometheus/config"
"github.com/prometheus/prometheus/tsdb/agent"
)
type Config struct {
// Path to store the WAL. Each tenant will be stored in its own subdirectory.
Path string `yaml:"path"`
Wal agentOptions `yaml:"wal"`
// How long to wait when flushing sample on shutdown
RemoteWriteFlushDeadline time.Duration `yaml:"remote_write_flush_deadline"`
// Prometheus remote write config
// https://prometheus.io/docs/prometheus/latest/configuration/configuration/#remote_write
RemoteWrite []prometheus_config.RemoteWriteConfig `yaml:"remote_write,omitempty"`
}
func (cfg *Config) RegisterFlagsAndApplyDefaults(prefix string, f *flag.FlagSet) {
cfg.Wal = agentDefaultOptions()
cfg.RemoteWriteFlushDeadline = time.Minute
}
// agentOptions is a copy of agent.Options but with yaml struct tags. Refer to agent.Options for
// documentation.
type agentOptions struct {
WALSegmentSize int `yaml:"wal_segment_size"`
WALCompression bool `yaml:"wal_compression"`
StripeSize int `yaml:"stripe_size"`
TruncateFrequency time.Duration `yaml:"truncate_frequency"`
MinWALTime int64 `yaml:"min_wal_time"`
MaxWALTime int64 `yaml:"max_wal_time"`
NoLockfile bool `yaml:"no_lockfile"`
}
func agentDefaultOptions() agentOptions {
defaultOptions := agent.DefaultOptions()
return agentOptions{
WALSegmentSize: defaultOptions.WALSegmentSize,
WALCompression: defaultOptions.WALCompression,
StripeSize: defaultOptions.StripeSize,
TruncateFrequency: defaultOptions.TruncateFrequency,
MinWALTime: defaultOptions.MinWALTime,
MaxWALTime: defaultOptions.MaxWALTime,
NoLockfile: defaultOptions.NoLockfile,
}
}
func (a *agentOptions) toPrometheusAgentOptions() *agent.Options {
return &agent.Options{
WALSegmentSize: a.WALSegmentSize,
WALCompression: a.WALCompression,
StripeSize: a.StripeSize,
TruncateFrequency: a.TruncateFrequency,
MinWALTime: a.MinWALTime,
MaxWALTime: a.MaxWALTime,
NoLockfile: a.NoLockfile,
}
}