github.com/thanos-io/thanos@v0.32.5/pkg/queryfrontend/response.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package queryfrontend 5 6 import ( 7 "unsafe" 8 9 "github.com/thanos-io/thanos/internal/cortex/querier/queryrange" 10 ) 11 12 // ThanosResponseExtractor helps to extract specific info from Query Response. 13 type ThanosResponseExtractor struct{} 14 15 // Extract extracts response for specific a range from a response. 16 // This interface is not used for labels and series responses. 17 func (ThanosResponseExtractor) Extract(_, _ int64, resp queryrange.Response) queryrange.Response { 18 return resp 19 } 20 21 // ResponseWithoutHeaders returns the response without HTTP headers. 22 func (ThanosResponseExtractor) ResponseWithoutHeaders(resp queryrange.Response) queryrange.Response { 23 switch tr := resp.(type) { 24 case *ThanosLabelsResponse: 25 return &ThanosLabelsResponse{Status: queryrange.StatusSuccess, Data: tr.Data} 26 case *ThanosSeriesResponse: 27 return &ThanosSeriesResponse{Status: queryrange.StatusSuccess, Data: tr.Data} 28 } 29 return resp 30 } 31 32 func (ThanosResponseExtractor) ResponseWithoutStats(resp queryrange.Response) queryrange.Response { 33 switch tr := resp.(type) { 34 case *ThanosLabelsResponse: 35 return &ThanosLabelsResponse{Status: queryrange.StatusSuccess, Data: tr.Data} 36 case *ThanosSeriesResponse: 37 return &ThanosSeriesResponse{Status: queryrange.StatusSuccess, Data: tr.Data} 38 } 39 return resp 40 } 41 42 // headersToQueryRangeHeaders convert slice of ResponseHeader to Cortex queryrange.PrometheusResponseHeader in an 43 // unsafe manner. It reuses the same memory. 44 func headersToQueryRangeHeaders(headers []*ResponseHeader) []*queryrange.PrometheusResponseHeader { 45 return *(*[]*queryrange.PrometheusResponseHeader)(unsafe.Pointer(&headers)) 46 } 47 48 // GetHeaders returns the HTTP headers in the response. 49 func (m *ThanosLabelsResponse) GetHeaders() []*queryrange.PrometheusResponseHeader { 50 return headersToQueryRangeHeaders(m.Headers) 51 } 52 53 // GetHeaders returns the HTTP headers in the response. 54 func (m *ThanosSeriesResponse) GetHeaders() []*queryrange.PrometheusResponseHeader { 55 return headersToQueryRangeHeaders(m.Headers) 56 } 57 58 // GetStats returns response stats. Unimplemented for ThanosLabelsResponse. 59 func (m *ThanosLabelsResponse) GetStats() *queryrange.PrometheusResponseStats { 60 return nil 61 } 62 63 // GetStats returns response stats. Unimplemented for ThanosSeriesResponse. 64 func (m *ThanosSeriesResponse) GetStats() *queryrange.PrometheusResponseStats { 65 return nil 66 }