MCPcopy
hub / github.com/prometheus/client_golang / testHandler

Function testHandler

prometheus/registry_test.go:55–744  ·  view source on GitHub ↗
(t testing.TB)

Source from the content-addressed store, hash-verified

53}
54
55func testHandler(t testing.TB) {
56 // TODO(beorn7): This test is a bit too "end-to-end". It tests quite a
57 // few moving parts that are not strongly coupled. They could/should be
58 // tested separately. However, the changes planned for v2 will
59 // require a major rework of this test anyway, at which time I will
60 // structure it in a better way.
61
62 metricVec := prometheus.NewCounterVec(
63 prometheus.CounterOpts{
64 Name: "name",
65 Help: "docstring",
66 ConstLabels: prometheus.Labels{"constname": "constvalue"},
67 },
68 []string{"labelname"},
69 )
70
71 metricVec.WithLabelValues("val1").Inc()
72 metricVec.WithLabelValues("val2").Inc()
73
74 externalMetricFamily := &dto.MetricFamily{
75 Name: proto.String("externalname"),
76 Help: proto.String("externaldocstring"),
77 Type: dto.MetricType_COUNTER.Enum(),
78 Metric: []*dto.Metric{
79 {
80 Label: []*dto.LabelPair{
81 {
82 Name: proto.String("externalconstname"),
83 Value: proto.String("externalconstvalue"),
84 },
85 {
86 Name: proto.String("externallabelname"),
87 Value: proto.String("externalval1"),
88 },
89 },
90 Counter: &dto.Counter{
91 Value: proto.Float64(1),
92 },
93 },
94 },
95 }
96 externalBuf := &bytes.Buffer{}
97 enc := expfmt.NewEncoder(externalBuf, expfmt.NewFormat(expfmt.TypeProtoDelim))
98 if err := enc.Encode(externalMetricFamily); err != nil {
99 t.Fatal(err)
100 }
101 externalMetricFamilyAsBytes := externalBuf.Bytes()
102 externalMetricFamilyAsText := []byte(`# HELP externalname externaldocstring
103# TYPE externalname counter
104externalname{externalconstname="externalconstvalue",externallabelname="externalval1"} 1
105`)
106 externalMetricFamilyAsProtoText := []byte(`name: "externalname"
107help: "externaldocstring"
108type: COUNTER
109metric: <
110 label: <
111 name: "externalconstname"
112 value: "externalconstvalue"

Callers 2

TestHandlerFunction · 0.85
BenchmarkHandlerFunction · 0.85

Calls 15

WithLabelValuesMethod · 0.95
NewCounterVecFunction · 0.92
NewSummaryFunction · 0.92
NewHistogramFunction · 0.92
NewPedanticRegistryFunction · 0.92
GathererInterface · 0.92
GathererFuncFuncType · 0.92
HandlerForFunction · 0.92
IncMethod · 0.65
MustRegisterMethod · 0.65
AddMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected