Skip to content

Commit

Permalink
Merge pull request #13669 from aiwhj/optimization
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
bboreham committed May 14, 2024
2 parents 67326d8 + 7e8f036 commit dc92652
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion model/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"crypto/md5"
"encoding/binary"
"fmt"
"strconv"
"strings"

"github.com/grafana/regexp"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit dc92652

Please sign in to comment.