This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
expression_has_tag.go
67 lines (52 loc) · 1.36 KB
/
expression_has_tag.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
package tagquery
import (
"io"
"strings"
"github.com/grafana/metrictank/schema"
)
type expressionHasTag struct {
expressionCommon
}
func (e *expressionHasTag) Equals(other Expression) bool {
return e.key == other.GetKey() && e.GetOperator() == other.GetOperator() && e.value == other.GetValue()
}
func (e *expressionHasTag) GetDefaultDecision() FilterDecision {
return Fail
}
func (e *expressionHasTag) GetOperator() ExpressionOperator {
return HAS_TAG
}
func (e *expressionHasTag) GetOperatorCost() uint32 {
return 10
}
func (e *expressionHasTag) OperatesOnTag() bool {
return true
}
func (e *expressionHasTag) Matches(value string) bool {
return value == e.key
}
func (e *expressionHasTag) MatchesExactly() bool {
return true
}
func (e *expressionHasTag) GetMetricDefinitionFilter(_ IdTagLookup) MetricDefinitionFilter {
if e.key == "name" {
return func(_ schema.MKey, _ string, _ []string) FilterDecision { return Pass }
}
resultIfTagIsAbsent := None
if !MetaTagSupport {
resultIfTagIsAbsent = Fail
}
matchPrefix := e.key + "="
return func(_ schema.MKey, _ string, tags []string) FilterDecision {
for _, tag := range tags {
if strings.HasPrefix(tag, matchPrefix) {
return Pass
}
}
return resultIfTagIsAbsent
}
}
func (e *expressionHasTag) StringIntoWriter(writer io.Writer) {
writer.Write([]byte(e.key))
writer.Write([]byte("!="))
}