Add method to merge a LabelSet into a Metric with collision avoidance.
Colliding labels can happen e.g. when an exporter job is scraped and already includes "job" labels for its samples in /metrics. In this case, a collisionPrefix of "exporter_" is added to the colliding target labels, but the specifics (the collision prefix) are managed by Prometheus, not the client library.
This commit is contained in:
parent
88e73cf99c
commit
9b9a115f95
|
@ -63,3 +63,18 @@ func (m Metric) String() string {
|
||||||
return fmt.Sprintf("%s{%s}", metricName, strings.Join(labelStrings, ", "))
|
return fmt.Sprintf("%s{%s}", metricName, strings.Join(labelStrings, ", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Metric) MergeFromLabelSet(labels LabelSet, collisionPrefix LabelName) {
|
||||||
|
for k, v := range labels {
|
||||||
|
if collisionPrefix != "" {
|
||||||
|
for {
|
||||||
|
if _, exists := m[k]; !exists {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
k = collisionPrefix + k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
m[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue