MCPcopy Create free account
hub / github.com/prometheus/common / MarshalJSON

Method MarshalJSON

model/value.go:193–225  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

191}
192
193func (ss SampleStream) MarshalJSON() ([]byte, error) {
194 switch {
195 case len(ss.Histograms) > 0 && len(ss.Values) > 0:
196 v := struct {
197 Metric Metric `json:"metric"`
198 Values []SamplePair `json:"values"`
199 Histograms []SampleHistogramPair `json:"histograms"`
200 }{
201 Metric: ss.Metric,
202 Values: ss.Values,
203 Histograms: ss.Histograms,
204 }
205 return json.Marshal(&v)
206 case len(ss.Histograms) > 0:
207 v := struct {
208 Metric Metric `json:"metric"`
209 Histograms []SampleHistogramPair `json:"histograms"`
210 }{
211 Metric: ss.Metric,
212 Histograms: ss.Histograms,
213 }
214 return json.Marshal(&v)
215 default:
216 v := struct {
217 Metric Metric `json:"metric"`
218 Values []SamplePair `json:"values"`
219 }{
220 Metric: ss.Metric,
221 Values: ss.Values,
222 }
223 return json.Marshal(&v)
224 }
225}
226
227// Scalar is a scalar value evaluated at the set timestamp.
228type Scalar struct {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected