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

Function TestCreate

expfmt/text_create_test.go:29–590  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

27)
28
29func TestCreate(t *testing.T) {
30 oldDefaultScheme := model.NameEscapingScheme
31 model.NameEscapingScheme = model.NoEscaping
32 defer func() {
33 model.NameEscapingScheme = oldDefaultScheme
34 }()
35
36 scenarios := []struct {
37 in *dto.MetricFamily
38 out string
39 }{
40 // 0: Counter, NaN as value, timestamp given.
41 {
42 in: &dto.MetricFamily{
43 Name: proto.String("name"),
44 Help: proto.String("two-line\n doc str\\ing"),
45 Type: dto.MetricType_COUNTER.Enum(),
46 Metric: []*dto.Metric{
47 {
48 Label: []*dto.LabelPair{
49 {
50 Name: proto.String("labelname"),
51 Value: proto.String("val1"),
52 },
53 {
54 Name: proto.String("basename"),
55 Value: proto.String("basevalue"),
56 },
57 },
58 Counter: &dto.Counter{
59 Value: proto.Float64(math.NaN()),
60 },
61 },
62 {
63 Label: []*dto.LabelPair{
64 {
65 Name: proto.String("labelname"),
66 Value: proto.String("val2"),
67 },
68 {
69 Name: proto.String("basename"),
70 Value: proto.String("basevalue"),
71 },
72 },
73 Counter: &dto.Counter{
74 Value: proto.Float64(.23),
75 },
76 TimestampMs: proto.Int64(1234567890),
77 },
78 },
79 },
80 out: `# HELP name two-line\n doc str\\ing
81# TYPE name counter
82name{labelname="val1",basename="basevalue"} NaN
83name{labelname="val2",basename="basevalue"} 0.23 1234567890
84`,
85 },
86 // 1: Gauge, some escaping required, +Inf as value, multi-byte characters in label values.

Callers

nothing calls this directly

Calls 2

MetricFamilyToTextFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…