-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
stats.go
83 lines (65 loc) · 2.1 KB
/
stats.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
// 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 autodiscovery
import (
"sync"
)
// loaderErrorStats holds the error objects
type acErrorStats struct {
config map[string]string // config file name -> error
resolve map[string][]string // config file name -> errors
m sync.RWMutex
}
// newAcErrorStats returns an instance holding autoconfig errors stats
func newAcErrorStats() *acErrorStats {
return &acErrorStats{
config: make(map[string]string),
resolve: make(map[string][]string),
}
}
// setConfigError will safely set the error for a check configuration file
func (es *acErrorStats) setConfigError(checkName string, err string) {
es.m.Lock()
defer es.m.Unlock()
es.config[checkName] = err
}
// removeConfigErrors removes the errors for a check config file
func (es *acErrorStats) removeConfigError(checkName string) {
es.m.Lock()
defer es.m.Unlock()
delete(es.config, checkName)
}
// getConfigErrors will safely get the errors a check config file
func (es *acErrorStats) getConfigErrors() map[string]string {
es.m.RLock()
defer es.m.RUnlock()
configCopy := make(map[string]string)
for k, v := range es.config {
configCopy[k] = v
}
return configCopy
}
// setResolveWarning will safely set the error for a check configuration file
func (es *acErrorStats) setResolveWarning(checkName string, err string) {
es.m.Lock()
defer es.m.Unlock()
es.resolve[checkName] = append(es.resolve[checkName], err)
}
// removeResolveWarnings removes the errors for a check config file
func (es *acErrorStats) removeResolveWarnings(checkName string) {
es.m.Lock()
defer es.m.Unlock()
delete(es.resolve, checkName)
}
// getResolveWarnings will safely get the errors a check config file
func (es *acErrorStats) getResolveWarnings() map[string][]string {
es.m.RLock()
defer es.m.RUnlock()
resolveCopy := make(map[string][]string)
for k, v := range es.resolve {
resolveCopy[k] = v
}
return resolveCopy
}