(t *testing.T, format config.ScrapeProtocol, mName string, v float64, ts, st time.Time)
| 992 | } |
| 993 | |
| 994 | func prepareTestEncodedCounter(t *testing.T, format config.ScrapeProtocol, mName string, v float64, ts, st time.Time) (encoded []byte) { |
| 995 | t.Helper() |
| 996 | |
| 997 | counter := &dto.Counter{Value: proto.Float64(v)} |
| 998 | if !st.IsZero() { |
| 999 | counter.CreatedTimestamp = timestamppb.New(st) |
| 1000 | } |
| 1001 | ctrType := dto.MetricType_COUNTER |
| 1002 | inputMetric := &dto.MetricFamily{ |
| 1003 | Name: proto.String(mName), |
| 1004 | Type: &ctrType, |
| 1005 | Metric: []*dto.Metric{{ |
| 1006 | TimestampMs: proto.Int64(timestamp.FromTime(ts)), |
| 1007 | Counter: counter, |
| 1008 | }}, |
| 1009 | } |
| 1010 | switch format { |
| 1011 | case config.PrometheusProto: |
| 1012 | return protoMarshalDelimited(t, inputMetric) |
| 1013 | case config.OpenMetricsText1_0_0: |
| 1014 | buf := &bytes.Buffer{} |
| 1015 | require.NoError(t, expfmt.NewEncoder(buf, expfmt.NewFormat(expfmt.TypeOpenMetrics), expfmt.WithCreatedLines()).Encode(inputMetric)) |
| 1016 | _, _ = buf.WriteString("# EOF") |
| 1017 | |
| 1018 | t.Log("produced OM text to expose:", buf.String()) |
| 1019 | return buf.Bytes() |
| 1020 | default: |
| 1021 | t.Fatalf("not implemented format: %v", format) |
| 1022 | return nil |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | func findSamplesForMetric(floats []sample, metricName string) (ret []sample) { |
| 1027 | for _, f := range floats { |
no test coverage detected
searching dependent graphs…