-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
interval.go
103 lines (89 loc) · 3.95 KB
/
interval.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package checks
import (
"time"
"github.com/DataDog/datadog-agent/pkg/config"
"github.com/DataDog/datadog-agent/pkg/util/log"
)
const (
//nolint:revive // TODO(PROC) Fix revive linter
ProcessCheckDefaultInterval = 10 * time.Second
//nolint:revive // TODO(PROC) Fix revive linter
RTProcessCheckDefaultInterval = 2 * time.Second
//nolint:revive // TODO(PROC) Fix revive linter
ContainerCheckDefaultInterval = 10 * time.Second
//nolint:revive // TODO(PROC) Fix revive linter
RTContainerCheckDefaultInterval = 2 * time.Second
//nolint:revive // TODO(PROC) Fix revive linter
ConnectionsCheckDefaultInterval = 30 * time.Second
//nolint:revive // TODO(PROC) Fix revive linter
ProcessDiscoveryCheckDefaultInterval = 4 * time.Hour
discoveryMinInterval = 10 * time.Minute
configIntervals = configPrefix + "intervals."
// The interval, in seconds, at which we will run each check. If you want consistent
// behavior between real-time you may set the Container/ProcessRT intervals to 10.
// Defaults to 10s for normal checks and 2s for others.
configProcessInterval = configIntervals + "process"
configRTProcessInterval = configIntervals + "process_realtime"
configContainerInterval = configIntervals + "container"
configRTContainerInterval = configIntervals + "container_realtime"
configConnectionsInterval = configIntervals + "connections"
)
var (
defaultIntervals = map[string]time.Duration{
ProcessCheckName: ProcessCheckDefaultInterval,
RTProcessCheckName: RTProcessCheckDefaultInterval,
ContainerCheckName: ContainerCheckDefaultInterval,
RTContainerCheckName: RTContainerCheckDefaultInterval,
ConnectionsCheckName: ConnectionsCheckDefaultInterval,
DiscoveryCheckName: ProcessDiscoveryCheckDefaultInterval,
ProcessEventsCheckName: config.DefaultProcessEventsCheckInterval,
}
configKeys = map[string]string{
ProcessCheckName: configProcessInterval,
RTProcessCheckName: configRTProcessInterval,
ContainerCheckName: configContainerInterval,
RTContainerCheckName: configRTContainerInterval,
ConnectionsCheckName: configConnectionsInterval,
}
)
// GetDefaultInterval returns the default check interval value
func GetDefaultInterval(checkName string) time.Duration {
return defaultIntervals[checkName]
}
// GetInterval returns the configured check interval value
func GetInterval(cfg config.Reader, checkName string) time.Duration {
switch checkName {
case DiscoveryCheckName:
// We don't need to check if the key exists since we already bound it to a default in InitConfig.
// We use a minimum of 10 minutes for this value.
discoveryInterval := cfg.GetDuration("process_config.process_discovery.interval")
if discoveryInterval < discoveryMinInterval {
discoveryInterval = discoveryMinInterval
_ = log.Warnf("Invalid interval for process discovery (< %s) using minimum value of %[1]s", discoveryMinInterval.String())
}
return discoveryInterval
case ProcessEventsCheckName:
eventsInterval := cfg.GetDuration("process_config.event_collection.interval")
if eventsInterval < config.DefaultProcessEventsMinCheckInterval {
eventsInterval = config.DefaultProcessEventsCheckInterval
_ = log.Warnf("Invalid interval for process_events check (< %s) using default value of %s",
config.DefaultProcessEventsMinCheckInterval.String(), config.DefaultProcessEventsCheckInterval.String())
}
return eventsInterval
default:
defaultInterval := defaultIntervals[checkName]
configKey, ok := configKeys[checkName]
if !ok || !cfg.IsSet(configKey) {
return defaultInterval
}
if seconds := cfg.GetInt(configKey); seconds != 0 {
log.Infof("Overriding %s check interval to %ds", configKey, seconds)
return time.Duration(seconds) * time.Second
}
return defaultInterval
}
}