-
Notifications
You must be signed in to change notification settings - Fork 450
/
types.go
177 lines (151 loc) · 5.41 KB
/
types.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright (c) 2018 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package models
import (
"regexp"
)
// Separators for tags.
const (
graphiteSep = byte('.')
sep = byte(',')
finish = byte('!')
eq = byte('=')
leftBracket = byte('{')
rightBracket = byte('}')
)
// IDSchemeType determines the scheme for generating
// series IDs based on their tags.
type IDSchemeType uint16
const (
// TypeDefault is an invalid scheme that indicates that the default scheme
// for the tag options version option should be used.
TypeDefault IDSchemeType = iota
// TypeLegacy describes a scheme where IDs are generated by appending
// tag name/value pairs with = and , separators. Note that an additional , is
// added to the end of the ID.
//
// NB: this should not be used, and exists here as a deprecated legacy
// ID generation scheme, as it may cause collisions in situations where
// incoming tags contain the following characters: << =," >>, for example:
// {t1:v1},{t2:v2} -> t1=v1,t2=v2,
// {t1:v1,t2:v2} -> t1=v1,t2=v2,
TypeLegacy
// TypeQuoted describes a scheme where IDs are generated by appending
// tag names with explicitly quoted and escaped tag values. Tag names are
// also escaped if they contain invalid characters. This is equivalent to
// the Prometheus ID style.
// {t1:v1},{t2:v2} -> {t1="v1",t2="v2"}
// {t1:v1,t2:v2} -> {t1="v1,t2:v2"}
// {"t1":"v1"} -> {\"t1\""="\"v1\""}
TypeQuoted
// TypePrependMeta describes a scheme where IDs are generated by prepending
// the length of each tag at the start of the ID
// {t1:v1},{t2:v2} -> 2,2,2,2!t1v1t2v2
// {t1:v1,t2:v2} -> 2,8!t1v1,t2:v2
// {"t1":"v1"} -> 4,4!"t1""v1"
TypePrependMeta
// TypeGraphite describes a scheme where IDs are generated to match graphite
// representation of the tags. This scheme should only be used on the graphite
// ingestion path, as it ignores tag names and is very prone to collisions if
// used on non-graphite data.
// {__g0__:v1},{__g1__:v2} -> v1.v2
//
// NB: when TypeGraphite is specified, tags are ordered numerically rather
// than lexically.
//
// NB 2: while the graphite scheme is valid, it is not available to choose as
// a general ID scheme; instead, it is set on any metric coming through the
// graphite ingestion path.
TypeGraphite
)
// TagOptions describes additional options for tags.
type TagOptions interface {
// Validate validates these tag options.
Validate() error
// SetMetricName sets the name for the `metric name` tag.
SetMetricName(value []byte) TagOptions
// MetricName gets the name for the `metric name` tag.
MetricName() []byte
// SetBucketName sets the name for the `bucket label` tag.
SetBucketName(value []byte) TagOptions
// BucketName gets the name for the `bucket label` tag.
BucketName() []byte
// SetIDSchemeType sets the ID generation scheme type.
SetIDSchemeType(value IDSchemeType) TagOptions
// IDSchemeType gets the ID generation scheme type.
IDSchemeType() IDSchemeType
// SetFilters sets tag filters.
SetFilters(value Filters) TagOptions
// Filters gets the tag filters.
Filters() Filters
// Equals determines if two tag options are equivalent.
Equals(other TagOptions) bool
}
// Tags represents a set of tags with options.
type Tags struct {
Opts TagOptions
Tags []Tag
hashedID uint64
id []byte
}
// Tag is a key/value metric tag pair.
type Tag struct {
Name []byte
Value []byte
}
// MatchType is an enum for label matching types.
type MatchType int
// Possible MatchTypes.
const (
MatchEqual MatchType = iota
MatchNotEqual
MatchRegexp
MatchNotRegexp
MatchField
MatchNotField
MatchAll
)
// Matcher models the matching of a label.
// NB: when serialized to JSON, name and value will be in base64.
type Matcher struct {
Type MatchType `json:"type"`
Name []byte `json:"name"`
Value []byte `json:"value"`
re *regexp.Regexp
}
// Matchers is a list of individual matchers.
type Matchers []Matcher
// Metric is the individual metric that gets returned from the search endpoint.
type Metric struct {
ID []byte
Tags Tags
}
// Metrics is a list of individual metrics.
type Metrics []Metric
// Filters is a set of tag filters.
type Filters []Filter
// Filter is a regex tag filter.
type Filter struct {
// Name is the name of the series.
Name []byte
// Values are a set of filter values. If this is unset, all series containing
// the tag name are filtered.
Values [][]byte
}