@@ -25,6 +25,7 @@ import (
25
25
"github.com/prometheus/prometheus/util/jsonutil"
26
26
"github.com/weaveworks/common/httpgrpc"
27
27
28
+ _ "github.com/cortexproject/cortex/pkg/chunk" // Register jsoniter type: labels.Labels.
28
29
"github.com/cortexproject/cortex/pkg/cortexpb"
29
30
"github.com/cortexproject/cortex/pkg/util/limiter"
30
31
"github.com/cortexproject/cortex/pkg/util/runutil"
@@ -113,12 +114,8 @@ func decodeSampleStream(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
113
114
for field := iter .ReadObject (); field != "" ; field = iter .ReadObject () {
114
115
switch field {
115
116
case "metric" :
116
- metricString := iter .ReadAny ().ToString ()
117
117
lbls := labels.Labels {}
118
- if err := json .UnmarshalFromString (metricString , & lbls ); err != nil {
119
- iter .ReportError ("unmarshal SampleStream" , err .Error ())
120
- return
121
- }
118
+ iter .ReadVal (& lbls )
122
119
ss .Labels = cortexpb .FromLabelsToLabelAdapters (lbls )
123
120
case "values" :
124
121
for iter .ReadArray () {
@@ -302,12 +299,7 @@ func encodeSampleStream(ptr unsafe.Pointer, stream *jsoniter.Stream) {
302
299
stream .WriteObjectStart ()
303
300
304
301
stream .WriteObjectField (`metric` )
305
- lbls , err := cortexpb .FromLabelAdaptersToLabels (ss .Labels ).MarshalJSON ()
306
- if err != nil {
307
- stream .Error = err
308
- return
309
- }
310
- stream .SetBuffer (append (stream .Buffer (), lbls ... ))
302
+ stream .WriteVal (cortexpb .FromLabelAdaptersToLabels (ss .Labels ))
311
303
312
304
if len (ss .Samples ) > 0 {
313
305
stream .WriteMore ()
@@ -343,12 +335,8 @@ func decodeSample(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
343
335
for field := iter .ReadObject (); field != "" ; field = iter .ReadObject () {
344
336
switch field {
345
337
case "metric" :
346
- metricString := iter .ReadAny ().ToString ()
347
338
lbls := labels.Labels {}
348
- if err := json .UnmarshalFromString (metricString , & lbls ); err != nil {
349
- iter .ReportError ("unmarshal Sample" , err .Error ())
350
- return
351
- }
339
+ iter .ReadVal (& lbls )
352
340
ss .Labels = cortexpb .FromLabelsToLabelAdapters (lbls )
353
341
case "value" :
354
342
ss .Sample = & cortexpb.Sample {}
@@ -368,12 +356,7 @@ func encodeSample(ptr unsafe.Pointer, stream *jsoniter.Stream) {
368
356
stream .WriteObjectStart ()
369
357
370
358
stream .WriteObjectField (`metric` )
371
- lbls , err := cortexpb .FromLabelAdaptersToLabels (ss .Labels ).MarshalJSON ()
372
- if err != nil {
373
- stream .Error = err
374
- return
375
- }
376
- stream .SetBuffer (append (stream .Buffer (), lbls ... ))
359
+ stream .WriteVal (cortexpb .FromLabelAdaptersToLabels (ss .Labels ))
377
360
378
361
if ss .Sample != nil {
379
362
stream .WriteMore ()
0 commit comments