Skip to content

Commit

Permalink
fix(deps): update module github.com/hashicorp/golang-lru to v2 (#14979)
Browse files Browse the repository at this point in the history
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Paul Rogers <[email protected]>
Co-authored-by: Paul Rogers <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2024
1 parent f92dde0 commit 3abb3b1
Show file tree
Hide file tree
Showing 16 changed files with 293 additions and 429 deletions.
10 changes: 5 additions & 5 deletions clients/pkg/logentry/stages/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/go-kit/log"
"github.com/go-kit/log/level"
lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/mitchellh/mapstructure"
"github.com/prometheus/common/model"

Expand Down Expand Up @@ -114,9 +114,9 @@ func newTimestampStage(logger log.Logger, config interface{}) (Stage, error) {
return nil, err
}

var lastKnownTimestamps *lru.Cache
var lastKnownTimestamps *lru.Cache[string, time.Time]
if *cfg.ActionOnFailure == TimestampActionOnFailureFudge {
lastKnownTimestamps, err = lru.New(maxLastKnownTimestampsCacheSize)
lastKnownTimestamps, err = lru.New[string, time.Time](maxLastKnownTimestampsCacheSize)
if err != nil {
return nil, err
}
Expand All @@ -138,7 +138,7 @@ type timestampStage struct {

// Stores the last known timestamp for a given "stream id" (guessed, since at this stage
// there's no reliable way to know it).
lastKnownTimestamps *lru.Cache
lastKnownTimestamps *lru.Cache[string, time.Time]
}

// Name implements Stage
Expand Down Expand Up @@ -222,7 +222,7 @@ func (ts *timestampStage) processActionOnFailureFudge(labels model.LabelSet, t *
}

// Fudge the timestamp
*t = lastTimestamp.(time.Time).Add(1 * time.Nanosecond)
*t = lastTimestamp.Add(1 * time.Nanosecond)

// Store the fudged timestamp, so that a subsequent fudged timestamp will be 1ns after it
ts.lastKnownTimestamps.Add(labelsStr, *t)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645
github.com/hashicorp/consul/api v1.30.0
github.com/hashicorp/golang-lru v0.6.0
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/imdario/mergo v0.3.16
github.com/influxdata/telegraf v1.16.3
github.com/jmespath/go-jmespath v0.4.0
Expand Down Expand Up @@ -126,7 +126,6 @@ require (
github.com/gogo/googleapis v1.4.1
github.com/grafana/jsonparser v0.0.0-20241004153430-023329977675
github.com/grafana/loki/pkg/push v0.0.0-20240924133635-758364c7775f
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/heroku/x v0.4.0
github.com/influxdata/tdigest v0.0.2-0.20210216194612-fc98d27c9e8b
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db
Expand Down Expand Up @@ -173,6 +172,7 @@ require (
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gorilla/handlers v1.5.2 // indirect
github.com/hashicorp/golang-lru v0.6.0 // indirect
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/sys/userns v0.1.0 // indirect
Expand Down
9 changes: 4 additions & 5 deletions pkg/distributor/distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/grafana/dskit/services"
"github.com/grafana/dskit/tenant"
"github.com/grafana/dskit/user"
lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -148,7 +148,7 @@ type Distributor struct {
subservicesWatcher *services.FailureWatcher
// Per-user rate limiter.
ingestionRateLimiter *limiter.RateLimiter
labelCache *lru.Cache
labelCache *lru.Cache[string, labelData]

// Push failures rate limiter.
writeFailuresManager *writefailures.Manager
Expand Down Expand Up @@ -217,7 +217,7 @@ func New(
var servs []services.Service

rateLimitStrat := validation.LocalIngestionRateStrategy
labelCache, err := lru.New(maxLabelCacheSize)
labelCache, err := lru.New[string, labelData](maxLabelCacheSize)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -1086,8 +1086,7 @@ type labelData struct {

func (d *Distributor) parseStreamLabels(vContext validationContext, key string, stream logproto.Stream) (labels.Labels, string, uint64, error) {
if val, ok := d.labelCache.Get(key); ok {
labelVal := val.(labelData)
return labelVal.ls, labelVal.ls.String(), labelVal.hash, nil
return val.ls, val.ls.String(), val.hash, nil
}

ls, err := syntax.ParseLabels(key)
Expand Down
8 changes: 4 additions & 4 deletions pkg/kafka/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/twmb/franz-go/pkg/kgo"

lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/prometheus/prometheus/model/labels"

"github.com/grafana/loki/v3/pkg/logproto"
Expand Down Expand Up @@ -126,11 +126,11 @@ func marshalWriteRequestToRecord(partitionID int32, tenantID string, stream logp
// It caches parsed labels for efficiency.
type Decoder struct {
stream *logproto.Stream
cache *lru.Cache
cache *lru.Cache[string, labels.Labels]
}

func NewDecoder() (*Decoder, error) {
cache, err := lru.New(5000) // Set LRU size to 5000, adjust as needed
cache, err := lru.New[string, labels.Labels](5000)
if err != nil {
return nil, fmt.Errorf("failed to create LRU cache: %w", err)
}
Expand All @@ -154,7 +154,7 @@ func (d *Decoder) Decode(data []byte) (logproto.Stream, labels.Labels, error) {

var ls labels.Labels
if cachedLabels, ok := d.cache.Get(d.stream.Labels); ok {
ls = cachedLabels.(labels.Labels)
ls = cachedLabels
} else {
var err error
ls, err = syntax.ParseLabels(d.stream.Labels)
Expand Down
30 changes: 0 additions & 30 deletions vendor/github.com/hashicorp/golang-lru/.golangci.yml

This file was deleted.

25 changes: 0 additions & 25 deletions vendor/github.com/hashicorp/golang-lru/README.md

This file was deleted.

Loading

0 comments on commit 3abb3b1

Please sign in to comment.