Skip to content

Commit 4a86b7c

Browse files
authored
Merge pull request #816 from drawks/deepsource
Replace MD5 hashing in favor of xxh3
2 parents be9addf + b97976d commit 4a86b7c

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

carbonserver/render.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package carbonserver
33
import (
44
"bytes"
55
"context"
6-
"crypto/md5"
7-
"encoding/hex"
86
"fmt"
97
"io"
108
"math"
@@ -25,6 +23,7 @@ import (
2523
"go.uber.org/zap"
2624

2725
"github.com/go-graphite/carbonzipper/zipper/httpHeaders"
26+
"github.com/go-graphite/go-carbon/helper"
2827
"github.com/go-graphite/go-whisper"
2928
grpcv2 "github.com/go-graphite/protocol/carbonapi_v2_grpc"
3029
protov2 "github.com/go-graphite/protocol/carbonapi_v2_pb"
@@ -52,11 +51,6 @@ type timeRange struct {
5251
until int32
5352
}
5453

55-
func getMD5HashString(text string) string {
56-
hash := md5.Sum([]byte(text))
57-
return hex.EncodeToString(hash[:])
58-
}
59-
6054
func getTargetNames(targets map[timeRange][]target) []string {
6155
c := 0
6256
for _, v := range targets {
@@ -295,8 +289,7 @@ func (listener *CarbonserverListener) getRenderCacheKeyAndSize(targets map[timeR
295289
for tr, ts := range targets {
296290
names := make([]string, 0, len(ts))
297291
for _, t := range ts {
298-
pathExpressionMD5 := getMD5HashString(t.PathExpression)
299-
names = append(names, t.Name+"&"+pathExpressionMD5)
292+
names = append(names, t.Name+"&"+strconv.FormatUint(helper.HashString(t.PathExpression), 16))
300293
}
301294
targetKeys = append(targetKeys, fmt.Sprintf("%s&%d&%d", strings.Join(names, "&"), tr.from, tr.until))
302295
}

carbonserver/trie.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package carbonserver
22

33
import (
4-
"crypto/md5" // skipcq: GSC-G501
54
"errors"
65
"fmt"
76
"io"
@@ -2296,8 +2295,7 @@ func (*trieIndex) metricName(node *trieNode, name string) string {
22962295
// WHY: on linux, the maximum filename length is 255, keeping 5 here for
22972296
// file extension.
22982297
if len(name) >= 250 {
2299-
// skipcq: GSC-G401, GO-S1023
2300-
name = fmt.Sprintf("%s-%x", name[:(250-md5.Size*2-1)], md5.Sum([]byte(name)))
2298+
name = fmt.Sprintf("%.233s-%.16x", name, helper.HashString(name))
23012299
}
23022300
return prefix + name
23032301
}

0 commit comments

Comments
 (0)