forked from gojue/ebpfmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
selectors.go
142 lines (126 loc) · 4.47 KB
/
selectors.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package manager
import (
"fmt"
"strings"
)
// OneOf - This selector is used to ensure that at least of a list of probe selectors is valid. In other words, this
// can be used to ensure that at least one of a list of optional probes is activated.
type OneOf struct {
Selectors []ProbesSelector
}
// GetProbesIdentificationPairList - Returns the list of probes that this selector activates
func (oo *OneOf) GetProbesIdentificationPairList() []ProbeIdentificationPair {
var l []ProbeIdentificationPair
for _, selector := range oo.Selectors {
l = append(l, selector.GetProbesIdentificationPairList()...)
}
return l
}
// RunValidator - Ensures that the probes that were successfully activated follow the selector goal.
// For example, see OneOf.
func (oo *OneOf) RunValidator(manager *Manager) error {
var errs []string
for _, selector := range oo.Selectors {
if err := selector.RunValidator(manager); err != nil {
errs = append(errs, err.Error())
}
}
if len(errs) == len(oo.Selectors) {
return fmt.Errorf(
"OneOf requirement failed, none of the following probes are running [%s]",
strings.Join(errs, " | "))
}
// at least one selector was successful
return nil
}
func (oo *OneOf) String() string {
var strs []string
for _, id := range oo.GetProbesIdentificationPairList() {
str := fmt.Sprintf("%s", id)
strs = append(strs, str)
}
return strings.Join(strs, ", ")
}
// EditProbeIdentificationPair - Changes all the selectors looking for the old ProbeIdentificationPair so that they
// now select the new one
func (oo *OneOf) EditProbeIdentificationPair(old ProbeIdentificationPair, new ProbeIdentificationPair) {
for _, selector := range oo.Selectors {
selector.EditProbeIdentificationPair(old, new)
}
}
// AllOf - This selector is used to ensure that all the proves in the provided list are running.
type AllOf struct {
Selectors []ProbesSelector
}
// GetProbesIdentificationPairList - Returns the list of probes that this selector activates
func (ao *AllOf) GetProbesIdentificationPairList() []ProbeIdentificationPair {
var l []ProbeIdentificationPair
for _, selector := range ao.Selectors {
l = append(l, selector.GetProbesIdentificationPairList()...)
}
return l
}
// RunValidator - Ensures that the probes that were successfully activated follow the selector goal.
// For example, see OneOf.
func (ao *AllOf) RunValidator(manager *Manager) error {
var errMsg []string
for _, selector := range ao.Selectors {
if err := selector.RunValidator(manager); err != nil {
errMsg = append(errMsg, err.Error())
}
}
if len(errMsg) > 0 {
return fmt.Errorf(
"AllOf requirement failed, the following probes are not running [%s]",
strings.Join(errMsg, " | "))
}
// no error means that all the selectors were successful
return nil
}
func (ao *AllOf) String() string {
var strs []string
for _, id := range ao.GetProbesIdentificationPairList() {
str := fmt.Sprintf("%s", id)
strs = append(strs, str)
}
return strings.Join(strs, ", ")
}
// EditProbeIdentificationPair - Changes all the selectors looking for the old ProbeIdentificationPair so that they
// now select the new one
func (ao *AllOf) EditProbeIdentificationPair(old ProbeIdentificationPair, new ProbeIdentificationPair) {
for _, selector := range ao.Selectors {
selector.EditProbeIdentificationPair(old, new)
}
}
// BestEffort - This selector is used to load probes in best effort mode
type BestEffort struct {
Selectors []ProbesSelector
}
// GetProbesIdentificationPairList - Returns the list of probes that this selector activates
func (be *BestEffort) GetProbesIdentificationPairList() []ProbeIdentificationPair {
var l []ProbeIdentificationPair
for _, selector := range be.Selectors {
l = append(l, selector.GetProbesIdentificationPairList()...)
}
return l
}
// RunValidator - Ensures that the probes that were successfully activated follow the selector goal.
// For example, see OneOf.
func (be *BestEffort) RunValidator(manager *Manager) error {
return nil
}
func (be *BestEffort) String() string {
var strs []string
for _, id := range be.GetProbesIdentificationPairList() {
str := fmt.Sprintf("%s", id)
strs = append(strs, str)
}
return strings.Join(strs, ", ")
}
// EditProbeIdentificationPair - Changes all the selectors looking for the old ProbeIdentificationPair so that they
// now select the new one
func (be *BestEffort) EditProbeIdentificationPair(old ProbeIdentificationPair, new ProbeIdentificationPair) {
for _, selector := range be.Selectors {
selector.EditProbeIdentificationPair(old, new)
}
}