This repository has been archived by the owner on Aug 23, 2023. It is now read-only.
/
expression_not_equal.go
87 lines (70 loc) · 1.84 KB
/
expression_not_equal.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
package tagquery
import (
"io"
"strings"
"github.com/grafana/metrictank/schema"
)
type expressionNotEqual struct {
expressionCommon
}
func (e *expressionNotEqual) Equals(other Expression) bool {
return e.key == other.GetKey() && e.GetOperator() == other.GetOperator() && e.value == other.GetValue()
}
func (e *expressionNotEqual) GetDefaultDecision() FilterDecision {
return Pass
}
func (e *expressionNotEqual) GetOperator() ExpressionOperator {
return NOT_EQUAL
}
func (e *expressionNotEqual) GetOperatorCost() uint32 {
return 2
}
func (e *expressionNotEqual) RequiresNonEmptyValue() bool {
return false
}
func (e *expressionNotEqual) ResultIsSmallerWhenInverted() bool {
return true
}
func (e *expressionNotEqual) Matches(value string) bool {
return value != e.value
}
func (e *expressionNotEqual) GetMetricDefinitionFilter(lookup IdTagLookup) MetricDefinitionFilter {
if e.key == "name" {
if e.value == "" {
return func(_ schema.MKey, _ string, _ []string) FilterDecision { return Pass }
}
return func(_ schema.MKey, name string, _ []string) FilterDecision {
if schema.SanitizeNameAsTagValue(name) == e.value {
return Fail
}
return Pass
}
}
if !MetaTagSupport {
return func(id schema.MKey, _ string, _ []string) FilterDecision {
if lookup(id, e.key, e.value) {
return Fail
}
return Pass
}
}
prefix := e.key + "="
return func(id schema.MKey, _ string, tags []string) FilterDecision {
if lookup(id, e.key, e.value) {
return Fail
}
for _, tag := range tags {
// the tag is set, but it has a different value,
// no need to keep looking at other indexes
if strings.HasPrefix(tag, prefix) {
return Pass
}
}
return None
}
}
func (e *expressionNotEqual) StringIntoWriter(writer io.Writer) {
writer.Write([]byte(e.key))
writer.Write([]byte("!="))
writer.Write([]byte(e.value))
}