MCPcopy
hub / github.com/prometheus/prometheus / prepareTestEncodedCounter

Function prepareTestEncodedCounter

scrape/manager_test.go:994–1024  ·  view source on GitHub ↗
(t *testing.T, format config.ScrapeProtocol, mName string, v float64, ts, st time.Time)

Source from the content-addressed store, hash-verified

992}
993
994func 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
1026func findSamplesForMetric(floats []sample, metricName string) (ret []sample) {
1027 for _, f := range floats {

Callers 1

Calls 7

FromTimeFunction · 0.92
protoMarshalDelimitedFunction · 0.85
LogMethod · 0.80
StringMethod · 0.65
EncodeMethod · 0.65
BytesMethod · 0.65
IsZeroMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…