Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vendor: bump golang-lru to v2 (requires Go >= 1.18 support for generics) #22644

Merged
merged 1 commit into from
Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ require (
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/hashicorp/consul/api v1.17.0
github.com/hashicorp/go-immutable-radix v1.3.1
github.com/hashicorp/golang-lru v0.5.4
github.com/hashicorp/golang-lru/v2 v2.0.1
github.com/jeremywohl/flatten v1.0.1
github.com/kevinburke/ssh_config v1.2.0
github.com/kr/pretty v0.3.1
Expand Down Expand Up @@ -175,6 +175,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.2.0 // indirect
github.com/hashicorp/go-rootcerts v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/serf v0.10.1 // indirect
github.com/imdario/mergo v0.3.12 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 7 additions & 15 deletions pkg/hubble/parser/seven/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sort"
"time"

lru "github.com/hashicorp/golang-lru"
lru "github.com/hashicorp/golang-lru/v2"
"github.com/sirupsen/logrus"
"google.golang.org/protobuf/types/known/timestamppb"
"google.golang.org/protobuf/types/known/wrapperspb"
Expand All @@ -27,8 +27,8 @@ import (
// Parser is a parser for L7 payloads
type Parser struct {
log logrus.FieldLogger
timestampCache *lru.Cache
traceContextCache *lru.Cache
timestampCache *lru.Cache[string, time.Time]
traceContextCache *lru.Cache[string, *flowpb.TraceContext]
dnsGetter getters.DNSGetter
ipGetter getters.IPGetter
serviceGetter getters.ServiceGetter
Expand All @@ -52,12 +52,12 @@ func New(
opt(args)
}

timestampCache, err := lru.New(args.CacheSize)
timestampCache, err := lru.New[string, time.Time](args.CacheSize)
if err != nil {
return nil, fmt.Errorf("failed to initialize cache: %v", err)
}

traceIDCache, err := lru.New(args.CacheSize)
traceIDCache, err := lru.New[string, *flowpb.TraceContext](args.CacheSize)
if err != nil {
return nil, fmt.Errorf("failed to initialize cache: %v", err)
}
Expand Down Expand Up @@ -172,15 +172,11 @@ func (p *Parser) getTraceContext(r *accesslog.LogRecord) *flowpb.TraceContext {
if requestID == "" {
return nil
}
value, ok := p.traceContextCache.Get(requestID)
traceContext, ok := p.traceContextCache.Get(requestID)
if !ok {
break
}
p.traceContextCache.Remove(requestID)
traceContext, ok := value.(*flowpb.TraceContext)
if !ok {
break
}
return traceContext
}
return nil
Expand All @@ -195,15 +191,11 @@ func (p *Parser) computeResponseTime(r *accesslog.LogRecord, timestamp time.Time
case accesslog.TypeRequest:
p.timestampCache.Add(requestID, timestamp)
case accesslog.TypeResponse:
value, ok := p.timestampCache.Get(requestID)
requestTimestamp, ok := p.timestampCache.Get(requestID)
if !ok {
return 0
}
p.timestampCache.Remove(requestID)
requestTimestamp, ok := value.(time.Time)
if !ok {
return 0
}
latency := timestamp.Sub(requestTimestamp).Nanoseconds()
if latency < 0 {
return 0
Expand Down
150 changes: 0 additions & 150 deletions vendor/github.com/hashicorp/golang-lru/lru.go

This file was deleted.

30 changes: 30 additions & 0 deletions vendor/github.com/hashicorp/golang-lru/v2/.golangci.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.