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:
juliusv 2013-08-12 06:58:45 -07:00
commit f5f5a2007a
1 changed files with 15 additions and 0 deletions

View File

@ -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
}
}