Adapted from https://github.com/prometheus/client_golang/blob/4b158abea9470f75b6f07460cdc2189b91914562/api/prometheus/v1/api.go#L84.
(ptr unsafe.Pointer, iter *jsoniter.Iterator)
| 589 | |
| 590 | // Adapted from https://github.com/prometheus/client_golang/blob/4b158abea9470f75b6f07460cdc2189b91914562/api/prometheus/v1/api.go#L84. |
| 591 | func UnmarshalSampleHistogramPairJSON(ptr unsafe.Pointer, iter *jsoniter.Iterator) { |
| 592 | p := (*SampleHistogramPair)(ptr) |
| 593 | if !iter.ReadArray() { |
| 594 | iter.ReportError("unmarshal SampleHistogramPair", "SampleHistogramPair must be [timestamp, {histogram}]") |
| 595 | return |
| 596 | } |
| 597 | p.TimestampMs = int64(model.Time(iter.ReadFloat64() * float64(time.Second/time.Millisecond))) |
| 598 | |
| 599 | if !iter.ReadArray() { |
| 600 | iter.ReportError("unmarshal SampleHistogramPair", "SamplePair missing histogram") |
| 601 | return |
| 602 | } |
| 603 | for key := iter.ReadObject(); key != ""; key = iter.ReadObject() { |
| 604 | switch key { |
| 605 | case "count": |
| 606 | f, err := strconv.ParseFloat(iter.ReadString(), 64) |
| 607 | if err != nil { |
| 608 | iter.ReportError("unmarshal SampleHistogramPair", "count of histogram is not a float") |
| 609 | return |
| 610 | } |
| 611 | p.Histogram.Count = f |
| 612 | case "sum": |
| 613 | f, err := strconv.ParseFloat(iter.ReadString(), 64) |
| 614 | if err != nil { |
| 615 | iter.ReportError("unmarshal SampleHistogramPair", "sum of histogram is not a float") |
| 616 | return |
| 617 | } |
| 618 | p.Histogram.Sum = f |
| 619 | case "buckets": |
| 620 | for iter.ReadArray() { |
| 621 | b, err := unmarshalHistogramBucket(iter) |
| 622 | if err != nil { |
| 623 | iter.ReportError("unmarshal HistogramBucket", err.Error()) |
| 624 | return |
| 625 | } |
| 626 | p.Histogram.Buckets = append(p.Histogram.Buckets, b) |
| 627 | } |
| 628 | default: |
| 629 | iter.ReportError("unmarshal SampleHistogramPair", fmt.Sprint("unexpected key in histogram:", key)) |
| 630 | return |
| 631 | } |
| 632 | } |
| 633 | if iter.ReadArray() { |
| 634 | iter.ReportError("unmarshal SampleHistogramPair", "SampleHistogramPair has too many values, must be [timestamp, {histogram}]") |
| 635 | return |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | // Adapted from https://github.com/prometheus/client_golang/blob/4b158abea9470f75b6f07460cdc2189b91914562/api/prometheus/v1/api.go#L252. |
| 640 | func unmarshalHistogramBucket(iter *jsoniter.Iterator) (*HistogramBucket, error) { |
no test coverage detected