mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Merge pull request #13669 from aiwhj/optimization
[ENHANCEMENT] Relabeling: small speed-up of hashmod Code optimization: The relabel operation is used very frequently, and strconv.FormatInt() with better performance should be used.
This commit is contained in:
commit
dc926527ae
|
@ -17,6 +17,7 @@ import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/grafana/regexp"
|
"github.com/grafana/regexp"
|
||||||
|
@ -290,7 +291,7 @@ func relabel(cfg *Config, lb *labels.Builder) (keep bool) {
|
||||||
hash := md5.Sum([]byte(val))
|
hash := md5.Sum([]byte(val))
|
||||||
// Use only the last 8 bytes of the hash to give the same result as earlier versions of this code.
|
// Use only the last 8 bytes of the hash to give the same result as earlier versions of this code.
|
||||||
mod := binary.BigEndian.Uint64(hash[8:]) % cfg.Modulus
|
mod := binary.BigEndian.Uint64(hash[8:]) % cfg.Modulus
|
||||||
lb.Set(cfg.TargetLabel, fmt.Sprintf("%d", mod))
|
lb.Set(cfg.TargetLabel, strconv.FormatUint(mod, 10))
|
||||||
case LabelMap:
|
case LabelMap:
|
||||||
lb.Range(func(l labels.Label) {
|
lb.Range(func(l labels.Label) {
|
||||||
if cfg.Regex.MatchString(l.Name) {
|
if cfg.Regex.MatchString(l.Name) {
|
||||||
|
|
Loading…
Reference in a new issue