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

Function TestOpenMetricsDecoder

expfmt/decode_test.go:711–774  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

709}
710
711func TestOpenMetricsDecoder(t *testing.T) {
712 var (
713 ts = model.Now()
714 in = `# TYPE mf2 counter
715mf2_total 3
716mf2_total 4
717mf1{label="value1"} -3.14 123.456
718mf1{label="value2"} 42
719# EOF
720`
721 out = model.Vector{
722 &model.Sample{
723 Metric: model.Metric{
724 model.MetricNameLabel: "mf1",
725 "label": "value1",
726 },
727 Value: -3.14,
728 Timestamp: 123456,
729 },
730 &model.Sample{
731 Metric: model.Metric{
732 model.MetricNameLabel: "mf1",
733 "label": "value2",
734 },
735 Value: 42,
736 Timestamp: ts,
737 },
738 &model.Sample{
739 Metric: model.Metric{
740 model.MetricNameLabel: "mf2_total",
741 },
742 Value: 3,
743 Timestamp: ts,
744 },
745 &model.Sample{
746 Metric: model.Metric{
747 model.MetricNameLabel: "mf2_total",
748 },
749 Value: 4,
750 Timestamp: ts,
751 },
752 }
753 )
754
755 dec := &SampleDecoder{
756 Dec: NewDecoder(strings.NewReader(in), FmtOpenMetrics_1_0_0),
757 Opts: &DecodeOptions{
758 Timestamp: ts,
759 },
760 }
761 var all model.Vector
762 for {
763 var smpls model.Vector
764 err := dec.Decode(&smpls)
765 if errors.Is(err, io.EOF) {
766 break
767 }
768 require.NoError(t, err)

Callers

nothing calls this directly

Calls 4

DecodeMethod · 0.95
NowFunction · 0.92
NewDecoderFunction · 0.85
EqualMethod · 0.45

Tested by

no test coverage detected