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

Method UnmarshalJSON

model/value.go:102–133  ·  view source on GitHub ↗

UnmarshalJSON implements json.Unmarshaler.

(b []byte)

Source from the content-addressed store, hash-verified

100
101// UnmarshalJSON implements json.Unmarshaler.
102func (s *Sample) UnmarshalJSON(b []byte) error {
103 v := struct {
104 Metric Metric `json:"metric"`
105 Value SamplePair `json:"value"`
106 Histogram SampleHistogramPair `json:"histogram"`
107 }{
108 Metric: s.Metric,
109 Value: SamplePair{
110 Timestamp: s.Timestamp,
111 Value: s.Value,
112 },
113 Histogram: SampleHistogramPair{
114 Timestamp: s.Timestamp,
115 Histogram: s.Histogram,
116 },
117 }
118
119 if err := json.Unmarshal(b, &v); err != nil {
120 return err
121 }
122
123 s.Metric = v.Metric
124 if v.Histogram.Histogram != nil {
125 s.Timestamp = v.Histogram.Timestamp
126 s.Histogram = v.Histogram.Histogram
127 } else {
128 s.Timestamp = v.Value.Timestamp
129 s.Value = v.Value.Value
130 }
131
132 return nil
133}
134
135// Samples is a sortable Sample slice. It implements sort.Interface.
136type Samples []*Sample

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected