Skip to content

Commit

Permalink
remove lru, only add prefix if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeGoldsmith committed Nov 28, 2023
1 parent c116ed8 commit e3cc49e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 21 deletions.
22 changes: 4 additions & 18 deletions beeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import (
"github.com/honeycombio/beeline-go/sample"
"github.com/honeycombio/beeline-go/trace"
libhoney "github.com/honeycombio/libhoney-go"

lru "github.com/hashicorp/golang-lru/v2"
)

const (
Expand Down Expand Up @@ -102,11 +100,6 @@ type Config struct {
PprofTagging bool
}

var (
// fieldNameCache is a LRU cache of namespaced keys to avoid allocating new strings
fieldNameCache *lru.Cache[string, string]
)

func IsClassicKey(config Config) bool {
// classic key has 32 characters
return len(config.WriteKey) == 32
Expand Down Expand Up @@ -362,17 +355,10 @@ func readResponses(responses chan transmission.Response) {
}
}

// getNamespacedKey returns a namespaced key for the given key. It will return
// the cached value if it exists, otherwise it will create a new one and cache
// it for future use.
// getNamespacedKey returns the key with the app. prefix if it doesn't already have one
func getNamespacedKey(key string) string {
if fieldNameCache == nil {
fieldNameCache, _ = lru.New[string, string](1000)
}
if val, ok := fieldNameCache.Get(key); ok {
return val
if !strings.HasPrefix(key, "app.") {
key = "app." + key
}
val := "app." + key
fieldNameCache.Add(key, val)
return val
return key
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/gobuffalo/pop/v6 v6.1.1
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/honeycombio/libhoney-go v1.20.0
github.com/jmoiron/sqlx v1.3.5
github.com/julienschmidt/httprouter v1.3.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,6 @@ github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k=
github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM=
github.com/honeycombio/libhoney-go v1.20.0 h1:PL54R0P9vxIyb28H3twbLb+DCqQlJdMQM55VZg1abKA=
github.com/honeycombio/libhoney-go v1.20.0/go.mod h1:RIaurCpfg5NDWSEV8t3QLcda9dUAiVNyWeHRAaSpN90=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
Expand Down

0 comments on commit e3cc49e

Please sign in to comment.