mirror of
https://github.com/prometheus/prometheus
synced 2025-01-12 09:40:00 +00: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"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/grafana/regexp"
|
||||
@ -290,7 +291,7 @@ func relabel(cfg *Config, lb *labels.Builder) (keep bool) {
|
||||
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.
|
||||
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:
|
||||
lb.Range(func(l labels.Label) {
|
||||
if cfg.Regex.MatchString(l.Name) {
|
||||
|
Loading…
Reference in New Issue
Block a user