diff --git a/connector/spanmetricsconnector/go.mod b/connector/spanmetricsconnector/go.mod index 0b7a013b1136..a42b3ba0bf0d 100644 --- a/connector/spanmetricsconnector/go.mod +++ b/connector/spanmetricsconnector/go.mod @@ -3,7 +3,6 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanm go 1.22.0 require ( - github.com/hashicorp/golang-lru v1.0.2 github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/jonboulle/clockwork v0.4.0 github.com/lightstep/go-expohisto v1.0.0 diff --git a/connector/spanmetricsconnector/go.sum b/connector/spanmetricsconnector/go.sum index b138d0515666..3900a7be0797 100644 --- a/connector/spanmetricsconnector/go.sum +++ b/connector/spanmetricsconnector/go.sum @@ -19,8 +19,6 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= -github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= 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/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4= diff --git a/connector/spanmetricsconnector/internal/cache/cache.go b/connector/spanmetricsconnector/internal/cache/cache.go index 2559d42eadf7..c59eadd3ebcc 100644 --- a/connector/spanmetricsconnector/internal/cache/cache.go +++ b/connector/spanmetricsconnector/internal/cache/cache.go @@ -4,7 +4,7 @@ package cache // import "github.com/open-telemetry/opentelemetry-collector-contrib/connector/spanmetricsconnector/internal/cache" import ( - "github.com/hashicorp/golang-lru/simplelru" + "github.com/hashicorp/golang-lru/v2/simplelru" ) // Cache consists of an LRU cache and the evicted items from the LRU cache. @@ -15,15 +15,15 @@ import ( // // Important: This implementation is non-thread safe. type Cache[K comparable, V any] struct { - lru simplelru.LRUCache + lru *simplelru.LRU[K, V] evictedItems map[K]V } // NewCache creates a Cache. func NewCache[K comparable, V any](size int) (*Cache[K, V], error) { evictedItems := make(map[K]V) - lruCache, err := simplelru.NewLRU(size, func(key any, value any) { - evictedItems[key.(K)] = value.(V) + lruCache, err := simplelru.NewLRU(size, func(key K, value V) { + evictedItems[key] = value }) if err != nil { return nil, err @@ -51,7 +51,7 @@ func (c *Cache[K, V]) Add(key K, value V) bool { // Get an item from the LRU cache or evicted items. func (c *Cache[K, V]) Get(key K) (V, bool) { if val, ok := c.lru.Get(key); ok { - return val.(V), ok + return val, ok } val, ok := c.evictedItems[key] @@ -85,7 +85,7 @@ func (c *Cache[K, V]) ForEach(fn func(k K, v V)) { for _, k := range c.lru.Keys() { v, ok := c.lru.Get(k) if ok { - fn(k.(K), v.(V)) + fn(k, v) } } diff --git a/extension/observer/ecsobserver/fetcher.go b/extension/observer/ecsobserver/fetcher.go index cf21efafcb4d..4276ddfacf6f 100644 --- a/extension/observer/ecsobserver/fetcher.go +++ b/extension/observer/ecsobserver/fetcher.go @@ -14,7 +14,7 @@ import ( "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ecs" - "github.com/hashicorp/golang-lru/simplelru" + "github.com/hashicorp/golang-lru/v2/simplelru" "go.uber.org/zap" ) @@ -50,8 +50,8 @@ type taskFetcher struct { ecs ecsClient ec2 ec2Client cluster string - taskDefCache simplelru.LRUCache - ec2Cache simplelru.LRUCache + taskDefCache *simplelru.LRU[string, *ecs.TaskDefinition] + ec2Cache *simplelru.LRU[string, *ec2.Instance] serviceNameFilter serviceNameFilter } @@ -81,11 +81,11 @@ func newTaskFetcherFromConfig(cfg Config, logger *zap.Logger) (*taskFetcher, err func newTaskFetcher(opts taskFetcherOptions) (*taskFetcher, error) { // Init cache - taskDefCache, err := simplelru.NewLRU(taskDefCacheSize, nil) + taskDefCache, err := simplelru.NewLRU[string, *ecs.TaskDefinition](taskDefCacheSize, nil) if err != nil { return nil, err } - ec2Cache, err := simplelru.NewLRU(ec2CacheSize, nil) + ec2Cache, err := simplelru.NewLRU[string, *ec2.Instance](ec2CacheSize, nil) if err != nil { return nil, err } @@ -205,7 +205,7 @@ func (f *taskFetcher) attachTaskDefinition(ctx context.Context, tasks []*ecs.Tas } var def *ecs.TaskDefinition if cached, ok := f.taskDefCache.Get(arn); ok { - def = cached.(*ecs.TaskDefinition) + def = cached } else { res, err := svc.DescribeTaskDefinitionWithContext(ctx, &ecs.DescribeTaskDefinitionInput{ TaskDefinition: aws.String(arn), @@ -251,7 +251,7 @@ func (f *taskFetcher) attachContainerInstance(ctx context.Context, tasks []*task for instanceArn := range ciToEC2 { cached, ok := f.ec2Cache.Get(instanceArn) if ok { - ciToEC2[instanceArn] = cached.(*ec2.Instance) // use value from cache + ciToEC2[instanceArn] = cached // use value from cache } else { instanceList = append(instanceList, aws.String(instanceArn)) } diff --git a/extension/observer/ecsobserver/go.mod b/extension/observer/ecsobserver/go.mod index c5539879449f..3866d9b43261 100644 --- a/extension/observer/ecsobserver/go.mod +++ b/extension/observer/ecsobserver/go.mod @@ -4,7 +4,7 @@ go 1.22.0 require ( github.com/aws/aws-sdk-go v1.55.5 - github.com/hashicorp/golang-lru v1.0.2 + github.com/hashicorp/golang-lru/v2 v2.0.7 github.com/stretchr/testify v1.9.0 go.opentelemetry.io/collector/component v0.111.1-0.20241008154146-ea48c09c31ae go.opentelemetry.io/collector/component/componentstatus v0.111.1-0.20241008154146-ea48c09c31ae diff --git a/extension/observer/ecsobserver/go.sum b/extension/observer/ecsobserver/go.sum index 08c9eae60fb9..c5c61a6b49a6 100644 --- a/extension/observer/ecsobserver/go.sum +++ b/extension/observer/ecsobserver/go.sum @@ -16,8 +16,8 @@ github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= -github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +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/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8=