This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 45
/
registry.go
99 lines (92 loc) · 3.76 KB
/
registry.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
package filters
import "regexp"
const (
equalOperator string = "="
notEqualOperator string = "!="
moreThanOperator string = ">"
lessThanOperator string = "<"
regexpOperator string = "=~"
negativeRegexOperator string = "!~"
)
// this needs to be hand crafted because any of the supported operator chars
// should be considered part of the operator expression
// this is needed to catch errors in operators, for example:
// a===b should yield an error
var matcherRegex = "[=!<>~]+"
// same as matcherRegex but for the filter name part
var filterRegex = "^(@)?[a-zA-Z_][a-zA-Z0-9_]*"
var matcherConfig = map[string]matcherT{
equalOperator: &equalMatcher{abstractMatcher{Operator: equalOperator}},
notEqualOperator: ¬EqualMatcher{abstractMatcher{Operator: notEqualOperator}},
moreThanOperator: &moreThanMatcher{abstractMatcher{Operator: moreThanOperator}},
lessThanOperator: &lessThanMatcher{abstractMatcher{Operator: lessThanOperator}},
regexpOperator: ®expMatcher{abstractMatcher{Operator: regexpOperator}},
negativeRegexOperator: &negativeRegexMatcher{abstractMatcher{Operator: negativeRegexOperator}},
}
type filterConfig struct {
Label string
LabelRe *regexp.Regexp
SupportedOperators []string
Factory newFilterFactory
Autocomplete autocompleteFactory
}
// AllFilters contains the mapping of all filters along with operators they
// support
var AllFilters = []filterConfig{
filterConfig{
Label: "@alertmanager",
LabelRe: regexp.MustCompile("^@alertmanager$"),
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
Factory: newAlertmanagerInstanceFilter,
Autocomplete: alertmanagerInstanceAutocomplete,
},
filterConfig{
Label: "@state",
LabelRe: regexp.MustCompile("^@state$"),
SupportedOperators: []string{equalOperator, notEqualOperator},
Factory: newStateFilter,
Autocomplete: stateAutocomplete,
},
filterConfig{
Label: "@receiver",
LabelRe: regexp.MustCompile("^@receiver$"),
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
Factory: newreceiverFilter,
Autocomplete: receiverAutocomplete,
},
filterConfig{
Label: "@age",
LabelRe: regexp.MustCompile("^@age$"),
SupportedOperators: []string{lessThanOperator, moreThanOperator},
Factory: newAgeFilter,
Autocomplete: ageAutocomplete,
},
filterConfig{
Label: "@silence_jira",
LabelRe: regexp.MustCompile("^@silence_jira$"),
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
Factory: newSilenceJiraFilter,
Autocomplete: sinceJiraIDAutocomplete,
},
filterConfig{
Label: "@silence_author",
LabelRe: regexp.MustCompile("^@silence_author$"),
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator},
Factory: newSilenceAuthorFilter,
Autocomplete: sinceAuthorAutocomplete,
},
filterConfig{
Label: "@limit",
LabelRe: regexp.MustCompile("^@limit$"),
SupportedOperators: []string{equalOperator},
Factory: newLimitFilter,
Autocomplete: limitAutocomplete,
},
filterConfig{
Label: "[a-zA-Z_][a-zA-Z0-9_]*",
LabelRe: regexp.MustCompile("^[a-zA-Z_][a-zA-Z0-9_]*$"),
SupportedOperators: []string{regexpOperator, negativeRegexOperator, equalOperator, notEqualOperator, lessThanOperator, moreThanOperator},
Factory: newLabelFilter,
Autocomplete: labelAutocomplete,
},
}