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

[add_cloud_metadata] Remove logger for AWS/EC2 #36829

Merged
merged 5 commits into from
Nov 20, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions libbeat/processors/add_cloud_metadata/provider_aws_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/aws/aws-sdk-go-v2/service/ec2"
"github.com/aws/aws-sdk-go-v2/service/ec2/types"

"github.com/elastic/elastic-agent-libs/logp"
"github.com/elastic/elastic-agent-libs/mapstr"

conf "github.com/elastic/elastic-agent-libs/config"
Expand Down Expand Up @@ -75,20 +74,16 @@ func fetchRawProviderMetadata(
client http.Client,
result *result,
) {
logger := logp.NewLogger("add_cloud_metadata")

// LoadDefaultConfig loads the EC2 role credentials
awsConfig, err := awscfg.LoadDefaultConfig(context.TODO(), awscfg.WithHTTPClient(&client))
if err != nil {
logger.Warnf("error loading AWS default configuration: %s.", err)
constanca-m marked this conversation as resolved.
Show resolved Hide resolved
result.err = fmt.Errorf("failed loading AWS default configuration: %w", err)
return
}
awsClient := NewIMDSClient(awsConfig)

instanceIdentity, err := awsClient.GetInstanceIdentityDocument(context.TODO(), &imds.GetInstanceIdentityDocumentInput{})
if err != nil {
logger.Warnf("error fetching EC2 Identity Document: %s.", err)
result.err = fmt.Errorf("failed fetching EC2 Identity Document: %w", err)
return
}
Expand All @@ -97,10 +92,7 @@ func fetchRawProviderMetadata(
awsRegion := instanceIdentity.InstanceIdentityDocument.Region
awsConfig.Region = awsRegion

clusterName, err := fetchEC2ClusterNameTag(awsConfig, instanceIdentity.InstanceIdentityDocument.InstanceID)
if err != nil {
logger.Warnf("error fetching cluster name metadata: %s.", err)
constanca-m marked this conversation as resolved.
Show resolved Hide resolved
}
clusterName, _ := fetchEC2ClusterNameTag(awsConfig, instanceIdentity.InstanceIdentityDocument.InstanceID)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably should not ignore the error here. When we do collect tags from an ec2 instance, this error should be surfaced. For example user might not have DescribeTags permission configured properly.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should keep this warning here. Also for the original log, since we removed the logger.Warnf("error fetching EC2 Identity Document: %s.", err) line and it has a return there at line 88, this warning should not matter when EC2 is not the proper cloud metadata source.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right @kaiyan-sheng , I added the log message again to this one


accountID := instanceIdentity.InstanceIdentityDocument.AccountID

Expand Down
Loading