Skip to content

Commit

Permalink
Replace murmur3 with xxhash for hashing
Browse files Browse the repository at this point in the history
Signed-off-by: Remy Chantenay <[email protected]>
  • Loading branch information
remychantenay committed Oct 18, 2023
1 parent 5ed79cb commit 9f67c9f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 15 deletions.
2 changes: 1 addition & 1 deletion filters/accesslog/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func NewMaskAccessLogQuery() filters.Spec {
func (*maskAccessLogQuery) Name() string { return filters.MaskAccessLogQueryName }

func (al *maskAccessLogQuery) CreateFilter(args []interface{}) (filters.Filter, error) {
if len(args) <= 0 {
if len(args) == 0 {
return nil, filters.ErrInvalidFilterParameters
}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ require (
github.com/sarslanhan/cronmask v0.0.0-20230801193303-54e29300a091
github.com/sirupsen/logrus v1.9.3
github.com/sony/gobreaker v0.5.0
github.com/spaolacci/murmur3 v1.1.0
github.com/stretchr/testify v1.8.4
github.com/szuecs/rate-limit-buffer v0.9.0
github.com/testcontainers/testcontainers-go v0.25.0
Expand Down
19 changes: 6 additions & 13 deletions logging/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ import (
"fmt"
"net"
"net/http"
"strconv"
"strings"
"time"

"github.com/cespare/xxhash/v2"
"github.com/sirupsen/logrus"
"github.com/spaolacci/murmur3"

flowidFilter "github.com/zalando/skipper/filters/flowid"
logFilter "github.com/zalando/skipper/filters/log"
Expand All @@ -22,9 +23,6 @@ const (
combinedLogFormat = commonLogFormat + ` "%s" "%s"`
// We add the duration in ms, a requested host and a flow id and audit log
accessLogFormat = combinedLogFormat + " %d %s %s %s\n"

// seedQueryParamMaskingHash represents the seed used to hash masked query parameters in access log.
seedQueryParamMaskingHash = 42
)

type accessLogFormatter struct {
Expand Down Expand Up @@ -113,14 +111,8 @@ func stripQueryString(u string) string {
}
}

// seedQueryParamMaskingHash hashes a provided query parameter value and returns the hashed value.
// Uses the murmur3 algorithm and a 32-bit hasher set.
func hashQueryParamValue(val string) string {
h32 := murmur3.New32WithSeed(seedQueryParamMaskingHash)
h32.Write([]byte(val))
hashedVal := h32.Sum32()

return fmt.Sprint(hashedVal)
func hash(val string) uint64 {
return xxhash.Sum64String(val)
}

// Logs an access event in Apache combined log format (with a minor customization with the duration).
Expand Down Expand Up @@ -168,7 +160,8 @@ func LogAccess(entry *AccessEntry, additional map[string]interface{}, maskedQuer
continue
}

params.Set(maskedQueryParams[i], hashQueryParamValue(val))
hashed := hash(val)
params.Set(maskedQueryParams[i], strconv.Itoa(int(hashed)))
}

uri = fmt.Sprintf("%s?%s", strippedURI, params.Encode())
Expand Down

0 comments on commit 9f67c9f

Please sign in to comment.