@@ -10,10 +10,10 @@ import (
10
10
"os"
11
11
"strings"
12
12
13
- "github.com/aws/aws-sdk-go/aws "
14
- "github.com/aws/aws-sdk-go/aws/ec2metadata "
15
- "github.com/aws/aws-sdk-go/aws/session "
16
- "github.com/aws/aws-sdk-go/service/ec2"
13
+ "github.com/aws/aws-sdk-go-v2/config "
14
+ "github.com/aws/aws-sdk-go-v2/feature/ec2/imds "
15
+ "github.com/aws/aws-sdk-go-v2/service/ec2 "
16
+ "github.com/aws/aws-sdk-go-v2 /service/ec2/types "
17
17
"go.opentelemetry.io/collector/pdata/pcommon"
18
18
"go.opentelemetry.io/collector/processor"
19
19
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
@@ -43,7 +43,7 @@ const (
43
43
type detectorUtils interface {
44
44
getConfigMap (ctx context.Context , namespace string , name string ) (map [string ]string , error )
45
45
getClusterName (ctx context.Context , logger * zap.Logger ) string
46
- getClusterNameTagFromReservations ([]* ec2 .Reservation ) string
46
+ getClusterNameTagFromReservations ([]types .Reservation ) string
47
47
getCloudAccountID (ctx context.Context , logger * zap.Logger ) string
48
48
}
49
49
@@ -142,29 +142,31 @@ func (e eksDetectorUtils) getConfigMap(ctx context.Context, namespace string, na
142
142
143
143
func (e eksDetectorUtils ) getClusterName (ctx context.Context , logger * zap.Logger ) string {
144
144
defaultErrorMessage := "Unable to get EKS cluster name"
145
- sess , err := session . NewSession ( )
145
+ cfg , err := config . LoadDefaultConfig ( ctx )
146
146
if err != nil {
147
147
logger .Warn (defaultErrorMessage , zap .Error (err ))
148
148
return ""
149
149
}
150
150
151
- ec2Svc := ec2metadata . New ( sess )
152
- region , err := ec2Svc . Region ( )
151
+ imdsClient := imds . NewFromConfig ( cfg )
152
+ resp , err := imdsClient . GetRegion ( ctx , & imds. GetRegionInput {} )
153
153
if err != nil {
154
154
logger .Warn (defaultErrorMessage , zap .Error (err ))
155
155
return ""
156
156
}
157
157
158
- svc := ec2 .New (sess , aws .NewConfig ().WithRegion (region ))
159
- instanceIdentityDocument , err := ec2Svc .GetInstanceIdentityDocumentWithContext (ctx )
158
+ cfg .Region = resp .Region
159
+ ec2Client := ec2 .NewFromConfig (cfg )
160
+
161
+ instanceIdentityDocument , err := imdsClient .GetInstanceIdentityDocument (ctx , & imds.GetInstanceIdentityDocumentInput {})
160
162
if err != nil {
161
163
logger .Warn (defaultErrorMessage , zap .Error (err ))
162
164
return ""
163
165
}
164
166
165
- instances , err := svc .DescribeInstances (& ec2.DescribeInstancesInput {
166
- InstanceIds : []* string {
167
- aws . String ( instanceIdentityDocument .InstanceID ) ,
167
+ instances , err := ec2Client .DescribeInstances (ctx , & ec2.DescribeInstancesInput {
168
+ InstanceIds : []string {
169
+ instanceIdentityDocument .InstanceID ,
168
170
},
169
171
})
170
172
if err != nil {
@@ -181,7 +183,7 @@ func (e eksDetectorUtils) getClusterName(ctx context.Context, logger *zap.Logger
181
183
return clusterName
182
184
}
183
185
184
- func (e eksDetectorUtils ) getClusterNameTagFromReservations (reservations []* ec2 .Reservation ) string {
186
+ func (e eksDetectorUtils ) getClusterNameTagFromReservations (reservations []types .Reservation ) string {
185
187
for _ , reservation := range reservations {
186
188
for _ , instance := range reservation .Instances {
187
189
for _ , tag := range instance .Tags {
@@ -203,14 +205,14 @@ func (e eksDetectorUtils) getClusterNameTagFromReservations(reservations []*ec2.
203
205
204
206
func (e eksDetectorUtils ) getCloudAccountID (ctx context.Context , logger * zap.Logger ) string {
205
207
defaultErrorMessage := "Unable to get EKS cluster account ID"
206
- sess , err := session . NewSession ( )
208
+ cfg , err := config . LoadDefaultConfig ( ctx )
207
209
if err != nil {
208
210
logger .Warn (defaultErrorMessage , zap .Error (err ))
209
211
return ""
210
212
}
211
213
212
- ec2Svc := ec2metadata . New ( sess )
213
- instanceIdentityDocument , err := ec2Svc . GetInstanceIdentityDocumentWithContext (ctx )
214
+ imdsClient := imds . NewFromConfig ( cfg )
215
+ instanceIdentityDocument , err := imdsClient . GetInstanceIdentityDocument (ctx , & imds. GetInstanceIdentityDocumentInput {} )
214
216
if err != nil {
215
217
logger .Warn (defaultErrorMessage , zap .Error (err ))
216
218
return ""
0 commit comments