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

Method GetMetricWith

prometheus/vec.go:238–248  ·  view source on GitHub ↗

GetMetricWith returns the Metric for the given Labels map (the label names must match those of the variable labels in Desc). If that label map is accessed for the first time, a new Metric is created. Implications of creating a Metric without using it and keeping the Metric for later use are the same

(labels Labels)

Source from the content-addressed store, hash-verified

236// around MetricVec, implementing a vector for a specific Metric implementation,
237// for example GaugeVec.
238func (m *MetricVec) GetMetricWith(labels Labels) (Metric, error) {
239 labels, closer := constrainLabels(m.desc, labels)
240 defer closer()
241
242 h, err := m.hashLabels(labels)
243 if err != nil {
244 return nil, err
245 }
246
247 return m.getOrCreateMetricWithLabels(h, labels, m.curry), nil
248}
249
250func (m *MetricVec) hashLabelValues(vals []string) (uint64, error) {
251 if err := validateLabelValues(vals, len(m.desc.variableLabels.names)-len(m.curry)); err != nil {

Callers

nothing calls this directly

Calls 3

hashLabelsMethod · 0.95
constrainLabelsFunction · 0.85

Tested by

no test coverage detected