-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
75 lines (71 loc) · 1.95 KB
/
Copy pathconfig.go
File metadata and controls
75 lines (71 loc) · 1.95 KB
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
package pulse
import "time"
const (
defaultCollectInterval = 10 * time.Second
defaultExportInterval = 10 * time.Second
defaultExportTimeout = 3 * time.Second
defaultExportMaxRetries = 5
defaultExportBackoffInitial = 500 * time.Millisecond
defaultExportBackoffMax = 30 * time.Second
defaultExportBackoffJitter = 0.20
defaultBufferSize = 10_000
defaultShutdownTimeout = 5 * time.Second
)
// Config controls agent behavior.
type Config struct {
CollectInterval time.Duration
ExportInterval time.Duration
ExportTimeout time.Duration
ExportMaxRetries int
ExportBackoffInitial time.Duration
ExportBackoffMax time.Duration
ExportBackoffJitter float64
BufferSize int
DisableHardware bool
ShutdownTimeout time.Duration
Exporters []Exporter
WAL *WALConfig
}
func (c Config) withDefaults() Config {
cfg := c
if cfg.CollectInterval <= 0 {
cfg.CollectInterval = defaultCollectInterval
}
if cfg.ExportInterval <= 0 {
cfg.ExportInterval = defaultExportInterval
}
if cfg.ExportTimeout <= 0 {
cfg.ExportTimeout = defaultExportTimeout
}
if cfg.ExportMaxRetries < 0 {
cfg.ExportMaxRetries = 0
}
if cfg.ExportMaxRetries == 0 {
cfg.ExportMaxRetries = defaultExportMaxRetries
}
if cfg.ExportBackoffInitial <= 0 {
cfg.ExportBackoffInitial = defaultExportBackoffInitial
}
if cfg.ExportBackoffMax <= 0 {
cfg.ExportBackoffMax = defaultExportBackoffMax
}
if cfg.ExportBackoffMax < cfg.ExportBackoffInitial {
cfg.ExportBackoffMax = cfg.ExportBackoffInitial
}
if cfg.ExportBackoffJitter < 0 {
cfg.ExportBackoffJitter = 0
}
if cfg.ExportBackoffJitter > 1 {
cfg.ExportBackoffJitter = 1
}
if cfg.ExportBackoffJitter == 0 {
cfg.ExportBackoffJitter = defaultExportBackoffJitter
}
if cfg.BufferSize <= 0 {
cfg.BufferSize = defaultBufferSize
}
if cfg.ShutdownTimeout <= 0 {
cfg.ShutdownTimeout = defaultShutdownTimeout
}
return cfg
}