-
Notifications
You must be signed in to change notification settings - Fork 2k
/
response.go
66 lines (54 loc) · 2.36 KB
/
response.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
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.
package queryfrontend
import (
"unsafe"
"github.com/thanos-io/thanos/internal/cortex/querier/queryrange"
)
// ThanosResponseExtractor helps to extract specific info from Query Response.
type ThanosResponseExtractor struct{}
// Extract extracts response for specific a range from a response.
// This interface is not used for labels and series responses.
func (ThanosResponseExtractor) Extract(_, _ int64, resp queryrange.Response) queryrange.Response {
return resp
}
// ResponseWithoutHeaders returns the response without HTTP headers.
func (ThanosResponseExtractor) ResponseWithoutHeaders(resp queryrange.Response) queryrange.Response {
switch tr := resp.(type) {
case *ThanosLabelsResponse:
return &ThanosLabelsResponse{Status: queryrange.StatusSuccess, Data: tr.Data}
case *ThanosSeriesResponse:
return &ThanosSeriesResponse{Status: queryrange.StatusSuccess, Data: tr.Data}
}
return resp
}
func (ThanosResponseExtractor) ResponseWithoutStats(resp queryrange.Response) queryrange.Response {
switch tr := resp.(type) {
case *ThanosLabelsResponse:
return &ThanosLabelsResponse{Status: queryrange.StatusSuccess, Data: tr.Data}
case *ThanosSeriesResponse:
return &ThanosSeriesResponse{Status: queryrange.StatusSuccess, Data: tr.Data}
}
return resp
}
// headersToQueryRangeHeaders convert slice of ResponseHeader to Cortex queryrange.PrometheusResponseHeader in an
// unsafe manner. It reuses the same memory.
func headersToQueryRangeHeaders(headers []*ResponseHeader) []*queryrange.PrometheusResponseHeader {
return *(*[]*queryrange.PrometheusResponseHeader)(unsafe.Pointer(&headers))
}
// GetHeaders returns the HTTP headers in the response.
func (m *ThanosLabelsResponse) GetHeaders() []*queryrange.PrometheusResponseHeader {
return headersToQueryRangeHeaders(m.Headers)
}
// GetHeaders returns the HTTP headers in the response.
func (m *ThanosSeriesResponse) GetHeaders() []*queryrange.PrometheusResponseHeader {
return headersToQueryRangeHeaders(m.Headers)
}
// GetStats returns response stats. Unimplemented for ThanosLabelsResponse.
func (m *ThanosLabelsResponse) GetStats() *queryrange.PrometheusResponseStats {
return nil
}
// GetStats returns response stats. Unimplemented for ThanosSeriesResponse.
func (m *ThanosSeriesResponse) GetStats() *queryrange.PrometheusResponseStats {
return nil
}