MCPcopy Create free account
hub / github.com/cortexproject/cortex / MarshalJSON

Method MarshalJSON

pkg/querier/tripperware/query.go:561–588  ·  view source on GitHub ↗

MarshalJSON implements json.Marshaler.

()

Source from the content-addressed store, hash-verified

559
560// MarshalJSON implements json.Marshaler.
561func (s *PrometheusData) MarshalJSON() ([]byte, error) {
562 switch s.ResultType {
563 case model.ValVector.String():
564 res := struct {
565 ResultType string `json:"resultType"`
566 Data []Sample `json:"result"`
567 Stats *PrometheusResponseStats `json:"stats,omitempty"`
568 }{
569 ResultType: s.ResultType,
570 Data: s.Result.GetVector().Samples,
571 Stats: s.Stats,
572 }
573 return json.Marshal(res)
574 case model.ValMatrix.String():
575 res := struct {
576 ResultType string `json:"resultType"`
577 Data []SampleStream `json:"result"`
578 Stats *PrometheusResponseStats `json:"stats,omitempty"`
579 }{
580 ResultType: s.ResultType,
581 Data: s.Result.GetMatrix().SampleStreams,
582 Stats: s.Stats,
583 }
584 return json.Marshal(res)
585 default:
586 return s.Result.GetRawBytes(), nil
587 }
588}
589
590// Adapted from https://github.com/prometheus/client_golang/blob/4b158abea9470f75b6f07460cdc2189b91914562/api/prometheus/v1/api.go#L84.
591func UnmarshalSampleHistogramPairJSON(ptr unsafe.Pointer, iter *jsoniter.Iterator) {

Callers

nothing calls this directly

Calls 5

GetVectorMethod · 0.80
GetMatrixMethod · 0.80
GetRawBytesMethod · 0.80
StringMethod · 0.65
MarshalMethod · 0.45

Tested by

no test coverage detected