forked from mirror/client_golang
Merge pull request #27 from prometheus/refactor/metric-label-merging
Add method to merge a LabelSet into a Metric with collision avoidance.
This commit is contained in:
commit
f5f5a2007a
|
@ -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