MCPcopy Index your code
hub / github.com/cortexproject/cortex / Decode

Method Decode

pkg/ruler/frontend_decoder.go:95–126  ·  view source on GitHub ↗
(body []byte)

Source from the content-addressed store, hash-verified

93}
94
95func (p ProtobufDecoder) Decode(body []byte) (promql.Vector, Warnings, error) {
96 resp := tripperware.PrometheusResponse{}
97 if err := resp.Unmarshal(body); err != nil {
98 return nil, nil, err
99 }
100
101 if resp.Status == statusError {
102 return nil, resp.Warnings, fmt.Errorf("failed to execute query with error: %s", resp.Error)
103 }
104
105 switch resp.Data.ResultType {
106 case "scalar":
107 data := struct {
108 Type model.ValueType `json:"resultType"`
109 Result json.RawMessage `json:"result"`
110 }{}
111
112 if err := json.Unmarshal(resp.Data.Result.GetRawBytes(), &data); err != nil {
113 return nil, nil, err
114 }
115
116 var s model.Scalar
117 if err := json.Unmarshal(data.Result, &s); err != nil {
118 return nil, nil, err
119 }
120 return scalarToPromQLVector(s), resp.Warnings, nil
121 case "vector":
122 return p.vectorToPromQLVector(resp.Data.Result.GetVector()), resp.Warnings, nil
123 default:
124 return nil, resp.Warnings, errors.New("rule result is not a vector or scalar")
125 }
126}
127
128func (p ProtobufDecoder) vectorToPromQLVector(vector *tripperware.Vector) promql.Vector {
129 v := make([]promql.Sample, 0, len(vector.Samples))

Callers

nothing calls this directly

Calls 6

UnmarshalMethod · 0.95
vectorToPromQLVectorMethod · 0.95
scalarToPromQLVectorFunction · 0.85
GetRawBytesMethod · 0.80
GetVectorMethod · 0.80
UnmarshalMethod · 0.45

Tested by

no test coverage detected