/
request.go
247 lines (200 loc) · 8.38 KB
/
request.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
package queryfrontend
import (
"time"
"github.com/cortexproject/cortex/pkg/querier/queryrange"
"github.com/opentracing/opentracing-go"
otlog "github.com/opentracing/opentracing-go/log"
"github.com/prometheus/prometheus/model/labels"
"github.com/prometheus/prometheus/model/timestamp"
)
// TODO(yeya24): add partial result when needed.
// ThanosRequest is a common interface defined for specific thanos requests.
type ThanosRequest interface {
GetStoreMatchers() [][]*labels.Matcher
}
type RequestHeader struct {
Name string
Values []string
}
type ThanosQueryRangeRequest struct {
Path string
Start int64
End int64
Step int64
Timeout time.Duration
Query string
Dedup bool
PartialResponse bool
AutoDownsampling bool
MaxSourceResolution int64
ReplicaLabels []string
StoreMatchers [][]*labels.Matcher
CachingOptions queryrange.CachingOptions
Headers []*RequestHeader
}
// GetStart returns the start timestamp of the request in milliseconds.
func (r *ThanosQueryRangeRequest) GetStart() int64 { return r.Start }
// GetEnd returns the end timestamp of the request in milliseconds.
func (r *ThanosQueryRangeRequest) GetEnd() int64 { return r.End }
// GetStep returns the step of the request in milliseconds.
func (r *ThanosQueryRangeRequest) GetStep() int64 { return r.Step }
// GetQuery returns the query of the request.
func (r *ThanosQueryRangeRequest) GetQuery() string { return r.Query }
func (r *ThanosQueryRangeRequest) GetCachingOptions() queryrange.CachingOptions {
return r.CachingOptions
}
// WithStartEnd clone the current request with different start and end timestamp.
func (r *ThanosQueryRangeRequest) WithStartEnd(start, end int64) queryrange.Request {
q := *r
q.Start = start
q.End = end
return &q
}
// WithQuery clone the current request with a different query.
func (r *ThanosQueryRangeRequest) WithQuery(query string) queryrange.Request {
q := *r
q.Query = query
return &q
}
// LogToSpan writes information about this request to an OpenTracing span.
func (r *ThanosQueryRangeRequest) LogToSpan(sp opentracing.Span) {
fields := []otlog.Field{
otlog.String("query", r.GetQuery()),
otlog.String("start", timestamp.Time(r.GetStart()).String()),
otlog.String("end", timestamp.Time(r.GetEnd()).String()),
otlog.Int64("step (ms)", r.GetStep()),
otlog.Bool("dedup", r.Dedup),
otlog.Bool("partial_response", r.PartialResponse),
otlog.Object("replicaLabels", r.ReplicaLabels),
otlog.Object("storeMatchers", r.StoreMatchers),
otlog.Bool("auto-downsampling", r.AutoDownsampling),
otlog.Int64("max_source_resolution (ms)", r.MaxSourceResolution),
}
sp.LogFields(fields...)
}
// Reset implements proto.Message interface required by queryrange.Request,
// which is not used in thanos.
func (r *ThanosQueryRangeRequest) Reset() {}
// String implements proto.Message interface required by queryrange.Request,
// which is not used in thanos.
func (r *ThanosQueryRangeRequest) String() string { return "" }
// ProtoMessage implements proto.Message interface required by queryrange.Request,
// which is not used in thanos.
func (r *ThanosQueryRangeRequest) ProtoMessage() {}
func (r *ThanosQueryRangeRequest) GetStoreMatchers() [][]*labels.Matcher { return r.StoreMatchers }
type ThanosLabelsRequest struct {
Start int64
End int64
Label string
Path string
Matchers [][]*labels.Matcher
StoreMatchers [][]*labels.Matcher
PartialResponse bool
CachingOptions queryrange.CachingOptions
Headers []*RequestHeader
}
// GetStart returns the start timestamp of the request in milliseconds.
func (r *ThanosLabelsRequest) GetStart() int64 { return r.Start }
// GetEnd returns the end timestamp of the request in milliseconds.
func (r *ThanosLabelsRequest) GetEnd() int64 { return r.End }
// GetStep returns the step of the request in milliseconds. Returns 1 is a trick to avoid panic in
// https://github.com/cortexproject/cortex/blob/master/pkg/querier/queryrange/results_cache.go#L447.
func (r *ThanosLabelsRequest) GetStep() int64 { return 1 }
// GetQuery returns the query of the request.
func (r *ThanosLabelsRequest) GetQuery() string { return "" }
func (r *ThanosLabelsRequest) GetCachingOptions() queryrange.CachingOptions { return r.CachingOptions }
// WithStartEnd clone the current request with different start and end timestamp.
func (r *ThanosLabelsRequest) WithStartEnd(start, end int64) queryrange.Request {
q := *r
q.Start = start
q.End = end
return &q
}
// WithQuery clone the current request with a different query.
func (r *ThanosLabelsRequest) WithQuery(_ string) queryrange.Request {
q := *r
return &q
}
// LogToSpan writes information about this request to an OpenTracing span.
func (r *ThanosLabelsRequest) LogToSpan(sp opentracing.Span) {
fields := []otlog.Field{
otlog.String("start", timestamp.Time(r.GetStart()).String()),
otlog.String("end", timestamp.Time(r.GetEnd()).String()),
otlog.Bool("partial_response", r.PartialResponse),
otlog.Object("matchers", r.Matchers),
otlog.Object("storeMatchers", r.StoreMatchers),
}
if r.Label != "" {
fields = append(fields, otlog.Object("label", r.Label))
}
sp.LogFields(fields...)
}
// Reset implements proto.Message interface required by queryrange.Request,
// which is not used in thanos.
func (r *ThanosLabelsRequest) Reset() {}
// String implements proto.Message interface required by queryrange.Request,
// which is not used in thanos.
func (r *ThanosLabelsRequest) String() string { return "" }
// ProtoMessage implements proto.Message interface required by queryrange.Request,
// which is not used in thanos.
func (r *ThanosLabelsRequest) ProtoMessage() {}
func (r *ThanosLabelsRequest) GetStoreMatchers() [][]*labels.Matcher { return r.StoreMatchers }
type ThanosSeriesRequest struct {
Path string
Start int64
End int64
Dedup bool
PartialResponse bool
ReplicaLabels []string
Matchers [][]*labels.Matcher
StoreMatchers [][]*labels.Matcher
CachingOptions queryrange.CachingOptions
Headers []*RequestHeader
}
// GetStart returns the start timestamp of the request in milliseconds.
func (r *ThanosSeriesRequest) GetStart() int64 { return r.Start }
// GetEnd returns the end timestamp of the request in milliseconds.
func (r *ThanosSeriesRequest) GetEnd() int64 { return r.End }
// GetStep returns the step of the request in milliseconds. Returns 1 is a trick to avoid panic in
// https://github.com/cortexproject/cortex/blob/master/pkg/querier/queryrange/results_cache.go#L447.
func (r *ThanosSeriesRequest) GetStep() int64 { return 1 }
// GetQuery returns the query of the request.
func (r *ThanosSeriesRequest) GetQuery() string { return "" }
func (r *ThanosSeriesRequest) GetCachingOptions() queryrange.CachingOptions { return r.CachingOptions }
// WithStartEnd clone the current request with different start and end timestamp.
func (r *ThanosSeriesRequest) WithStartEnd(start, end int64) queryrange.Request {
q := *r
q.Start = start
q.End = end
return &q
}
// WithQuery clone the current request with a different query.
func (r *ThanosSeriesRequest) WithQuery(_ string) queryrange.Request {
q := *r
return &q
}
// LogToSpan writes information about this request to an OpenTracing span.
func (r *ThanosSeriesRequest) LogToSpan(sp opentracing.Span) {
fields := []otlog.Field{
otlog.String("start", timestamp.Time(r.GetStart()).String()),
otlog.String("end", timestamp.Time(r.GetEnd()).String()),
otlog.Bool("dedup", r.Dedup),
otlog.Bool("partial_response", r.PartialResponse),
otlog.Object("replicaLabels", r.ReplicaLabels),
otlog.Object("matchers", r.Matchers),
otlog.Object("storeMatchers", r.StoreMatchers),
}
sp.LogFields(fields...)
}
// Reset implements proto.Message interface required by queryrange.Request,
// which is not used in thanos.
func (r *ThanosSeriesRequest) Reset() {}
// String implements proto.Message interface required by queryrange.Request,
// which is not used in thanos.
func (r *ThanosSeriesRequest) String() string { return "" }
// ProtoMessage implements proto.Message interface required by queryrange.Request,
// which is not used in thanos.
func (r *ThanosSeriesRequest) ProtoMessage() {}
func (r *ThanosSeriesRequest) GetStoreMatchers() [][]*labels.Matcher { return r.StoreMatchers }