-
Notifications
You must be signed in to change notification settings - Fork 482
/
config.go
61 lines (51 loc) · 2.17 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
package wal
import (
"time"
)
const (
DefaultMaxSegmentAge = time.Hour
)
// DefaultWatchConfig is the opinionated defaults for operating the Watcher.
var DefaultWatchConfig = WatchConfig{
MinReadFrequency: time.Millisecond * 250,
MaxReadFrequency: time.Second,
}
// Config contains all WAL-related settings.
type Config struct {
// Whether WAL-support should be enabled.
//
// WAL support is a WIP. Do not enable in production setups until https://github.com/grafana/loki/issues/8197
// is finished.
Enabled bool
// Path where the WAL is written to.
Dir string
// MaxSegmentAge is threshold at which a WAL segment is considered old enough to be cleaned up. Default: 1h.
//
// Note that this functionality will likely be deprecated in favour of a programmatic cleanup mechanism.
MaxSegmentAge time.Duration
// WatchConfig configures the backoff retry used by a WAL watcher when reading from segments not via
// the notification channel.
WatchConfig WatchConfig
}
// WatchConfig allows the user to configure the Watcher.
//
// For the read frequency settings, the Watcher polls the WAL for new records with two mechanisms: First, it gets
// notified by the Writer when the WAL is written; also, it has a timer that gets fired every so often. This last
// one, implements and exponential back-off strategy to prevent the Watcher from doing read too often, if there's no new
// data.
type WatchConfig struct {
// MinReadFrequency controls the minimum read frequency the Watcher polls the WAL for new records. If the poll is successful,
// the frequency will remain the same. If not, it will be incremented using an exponential backoff.
MinReadFrequency time.Duration
// MaxReadFrequency controls the maximum read frequency the Watcher polls the WAL for new records. As mentioned above
// it caps the polling frequency to a maximum, to prevent to exponential backoff from making it too high.
MaxReadFrequency time.Duration
}
// UnmarshalYAML implement YAML Unmarshaler
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Apply defaults
c.MaxSegmentAge = DefaultMaxSegmentAge
c.WatchConfig = DefaultWatchConfig
type plain Config
return unmarshal((*plain)(c))
}