98
func (*Handler) Stop(log.Logger) {}
99
101
>
rec := httptest.NewRecorder()
102
>
req := httptest.NewRequest("GET", "/metrics", nil)
103
>
handler := http.NewServeMux()
104
>
handler.HandleFunc("/metrics", promhttp.HandlerFor(h.reg, promhttp.HandlerOpts{Registry: h.reg}).ServeHTTP)
105
>
handler.ServeHTTP(rec, req)
106
>
107
>
var tp expfmt.TextParser
108
>
families, err := tp.TextToMetricFamilies(rec.Body)
109
>
if err != nil {
110
return Snapshot{}, err
111
}
113
>
histogramSamples := map[string]histogramSample{}
114
>
for name, family := range families {
115
>
for _, m := range family.GetMetric() {
116
>
collectSamples(name, family, m, samples, histogramSamples)
117
>
}
118
}
120
>
samples: samples,
121
>
histogramSamples: histogramSamples,
122
>
}, nil
123
}
124
125
>
func collectSamples(name string, family *dto.MetricFamily, m *dto.Metric, samples map[string]sample, histogramSamples map[string]histogramSample) {
metricstest.go
126
>
labelvalues := map[string]string{}
127
>
for _, lp := range m.GetLabel() {
128
>
labelvalues[lp.GetName()] = lp.GetValue()
129
>
}
130
// This only records the last sample if there
131
// are multiple samples recorded.
133
default:
134
// Not yet supporting summary, untyped.