/
warnings.go
80 lines (63 loc) · 2.26 KB
/
warnings.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
// 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 http
import (
"sync"
"github.com/DataDog/datadog-agent/pkg/util/log"
)
var (
// noProxyIgnoredWarningMap map containing URL's who will ignore the proxy in the future
noProxyIgnoredWarningMap = make(map[string]bool)
// noProxyUsedInFuture map containing URL's that will use a proxy in the future
noProxyUsedInFuture = make(map[string]bool)
// noProxyChanged map containing URL's whose proxy behavior will change in the future
noProxyChanged = make(map[string]bool)
// noProxyMapMutex Lock for all no proxy maps
noProxyMapMutex = sync.Mutex{}
)
// GetNumberOfWarnings returns the total number of warnings
func GetNumberOfWarnings() int {
noProxyMapMutex.Lock()
defer noProxyMapMutex.Unlock()
return len(noProxyIgnoredWarningMap) + len(noProxyUsedInFuture) + len(noProxyChanged)
}
// GetProxyIgnoredWarnings returns the list of URL which will ignore the proxy in the future
func GetProxyIgnoredWarnings() []string {
noProxyMapMutex.Lock()
defer noProxyMapMutex.Unlock()
ignoredWarnings := []string{}
for warn := range noProxyIgnoredWarningMap {
ignoredWarnings = append(ignoredWarnings, warn)
}
return ignoredWarnings
}
// GetProxyUsedInFutureWarnings returns the list of URL which will use a proxy in the future
func GetProxyUsedInFutureWarnings() []string {
noProxyMapMutex.Lock()
defer noProxyMapMutex.Unlock()
usedInFuture := []string{}
for warn := range noProxyUsedInFuture {
usedInFuture = append(usedInFuture, warn)
}
return usedInFuture
}
// GetProxyChangedWarnings returns the list of URL whose proxy behavior will change in the future
func GetProxyChangedWarnings() []string {
noProxyMapMutex.Lock()
defer noProxyMapMutex.Unlock()
proxyChanged := []string{}
for warn := range noProxyChanged {
proxyChanged = append(proxyChanged, warn)
}
return proxyChanged
}
func warnOnce(warnMap map[string]bool, key string, format string, params ...interface{}) {
noProxyMapMutex.Lock()
defer noProxyMapMutex.Unlock()
if _, ok := warnMap[key]; !ok {
warnMap[key] = true
log.Warnf(format, params...)
}
}