-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
utils.go
86 lines (75 loc) · 2.78 KB
/
utils.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
// 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 providers
import (
"path"
"strconv"
"time"
"github.com/DataDog/datadog-agent/pkg/config"
)
const (
//nolint needed as these constants are defined in a file without a build tag,
// but only used in multiple files with different build tags, none of which
// are used in the IoT Agent.
//nolint:unused,deadcode
instancePath string = "instances"
//nolint:unused,deadcode
checkNamePath string = "check_names"
//nolint:unused,deadcode
initConfigPath string = "init_configs"
)
func buildStoreKey(key ...string) string {
parts := []string{config.Datadog.GetString("autoconf_template_dir")}
parts = append(parts, key...)
return path.Join(parts...)
}
// GetPollInterval computes the poll interval from the config
func GetPollInterval(cp config.ConfigurationProviders) time.Duration {
if cp.PollInterval != "" {
customInterval, err := time.ParseDuration(cp.PollInterval)
if err == nil {
return customInterval
}
}
return config.Datadog.GetDuration("ad_config_poll_interval") * time.Second
}
// providerCache supports monitoring a service for changes either to the number
// of things being monitored, or to one of those things being modified. This
// can be used to determine IsUpToDate() and avoid full Collect() calls when
// nothing has changed.
// nolint needed as this type is defined in a file without a build tag,
// but only used in multiple files with different build tags, none of which
// are used in the IoT Agent.
//
//nolint:unused
type providerCache struct {
// mostRecentMod is the most recent modification timestamp of a
// monitored thing
mostRecentMod float64
// count is the number of monitored things
count int
}
// ErrorMsgSet contains a list of unique configuration errors for a provider
type ErrorMsgSet map[string]struct{}
// newProviderCache instantiate a ProviderCache.
// nolint needed as this function is defined in a file without a build tag,
// but only used in multiple files with different build tags, none of which
// are used in the IoT Agent.
//
//nolint:deadcode,unused
func newProviderCache() *providerCache {
return &providerCache{
mostRecentMod: 0,
count: 0,
}
}
// ignoreADTagsFromAnnotations returns of the `ad.datadoghq.com/{endpoints,service}.ignore_autodiscovery_tags` annotation
// TODO(CINT)(Agent 7.53+) Remove support for hybrid scenarios
//
//nolint:deadcode,unused
func ignoreADTagsFromAnnotations(annotations map[string]string, prefix string) bool {
ignoreAdForHybridScenariosTags, _ := strconv.ParseBool(annotations[prefix+"ignore_autodiscovery_tags"])
return ignoreAdForHybridScenariosTags
}