2013-04-03 20:33:32 +04:00
|
|
|
// Copyright (c) 2013, Prometheus Team
|
2013-01-19 17:48:30 +04:00
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2013-04-03 20:33:32 +04:00
|
|
|
package prometheus
|
2013-01-19 17:48:30 +04:00
|
|
|
|
|
|
|
import (
|
2013-06-27 20:46:16 +04:00
|
|
|
"fmt"
|
|
|
|
"hash/fnv"
|
2013-01-19 17:48:30 +04:00
|
|
|
"sort"
|
|
|
|
|
2013-06-27 20:46:16 +04:00
|
|
|
"github.com/prometheus/client_golang/model"
|
2013-01-19 17:48:30 +04:00
|
|
|
)
|
|
|
|
|
|
|
|
// LabelsToSignature provides a way of building a unique signature
|
|
|
|
// (i.e., fingerprint) for a given label set sequence.
|
2013-06-27 20:46:16 +04:00
|
|
|
func labelsToSignature(labels map[string]string) uint64 {
|
|
|
|
names := make(model.LabelNames, 0, len(labels))
|
|
|
|
for name := range labels {
|
|
|
|
names = append(names, model.LabelName(name))
|
2013-01-19 17:48:30 +04:00
|
|
|
}
|
|
|
|
|
2013-06-27 20:46:16 +04:00
|
|
|
sort.Sort(names)
|
2013-01-19 17:48:30 +04:00
|
|
|
|
2013-06-27 20:46:16 +04:00
|
|
|
hasher := fnv.New64a()
|
2013-01-19 17:48:30 +04:00
|
|
|
|
2013-06-27 20:46:16 +04:00
|
|
|
for _, name := range names {
|
|
|
|
fmt.Fprintf(hasher, string(name), labels[string(name)])
|
2013-01-19 17:48:30 +04:00
|
|
|
}
|
|
|
|
|
2013-06-27 20:46:16 +04:00
|
|
|
return hasher.Sum64()
|
2013-01-19 17:48:30 +04:00
|
|
|
}
|