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] fix the orchestrator metadata for the aws cloud provider #37651

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ https://github.com/elastic/beats/compare/v8.11.1\...v8.11.2[View commits]
- Enhance Azure Metrics metricset with refined grouping logic and resolved duplication issues for TSDB compatibility. {pull}36823[36823]
- Fix unintended skip in metric collection on Azure Monitor. {issue}37204[37204] {pull}37203[37203]
- Fix the "api-version query parameter (?api-version=) is required for all requests" error in Azure Billing. {pull}37158[37158]
- add_cloud_metadata: fix the `orchestrator` metadata for the aws cloud provider

*Winlogbeat*

Expand Down
24 changes: 15 additions & 9 deletions libbeat/processors/add_cloud_metadata/provider_aws_ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,16 @@ var ec2MetadataFetcher = provider{

Create: func(_ string, config *conf.C) (metadataFetcher, error) {
ec2Schema := func(m map[string]interface{}) mapstr.M {
m["service"] = mapstr.M{
"name": "EC2",
meta := mapstr.M{
"cloud": mapstr.M{
"service": mapstr.M{
"name": "EC2",
},
},
}
return mapstr.M{"cloud": m}

meta.DeepUpdate(m)
return meta
}

fetcher, err := newGenericMetadataFetcher(config, "aws", ec2Schema, fetchRawProviderMetadata)
Expand Down Expand Up @@ -109,12 +115,12 @@ func fetchRawProviderMetadata(
_, _ = result.metadata.Put("orchestrator.cluster.name", clusterName)
}

_, _ = result.metadata.Put("instance.id", instanceIdentity.InstanceIdentityDocument.InstanceID)
_, _ = result.metadata.Put("machine.type", instanceIdentity.InstanceIdentityDocument.InstanceType)
_, _ = result.metadata.Put("region", awsRegion)
_, _ = result.metadata.Put("availability_zone", instanceIdentity.InstanceIdentityDocument.AvailabilityZone)
_, _ = result.metadata.Put("account.id", accountID)
_, _ = result.metadata.Put("image.id", instanceIdentity.InstanceIdentityDocument.ImageID)
_, _ = result.metadata.Put("cloud.instance.id", instanceIdentity.InstanceIdentityDocument.InstanceID)
_, _ = result.metadata.Put("cloud.machine.type", instanceIdentity.InstanceIdentityDocument.InstanceType)
_, _ = result.metadata.Put("cloud.region", awsRegion)
_, _ = result.metadata.Put("cloud.availability_zone", instanceIdentity.InstanceIdentityDocument.AvailabilityZone)
_, _ = result.metadata.Put("cloud.account.id", accountID)
_, _ = result.metadata.Put("cloud.image.id", instanceIdentity.InstanceIdentityDocument.ImageID)

}

Expand Down
26 changes: 16 additions & 10 deletions libbeat/processors/add_cloud_metadata/provider_aws_ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ func TestRetrieveAWSMetadataEC2(t *testing.T) {
"region": regionDoc1,
"availability_zone": availabilityZoneDoc1,
"service": mapstr.M{"name": "EC2"},
"orchestrator": mapstr.M{
"cluster": mapstr.M{
"name": clusterNameValue,
"id": fmt.Sprintf("arn:aws:eks:%s:%s:cluster/%s", regionDoc1, accountIDDoc1, clusterNameValue),
},
},
"orchestrator": mapstr.M{
"cluster": mapstr.M{
"name": clusterNameValue,
"id": fmt.Sprintf("arn:aws:eks:%s:%s:cluster/%s", regionDoc1, accountIDDoc1, clusterNameValue),
},
},
},
Expand Down Expand Up @@ -198,6 +198,12 @@ func TestRetrieveAWSMetadataEC2(t *testing.T) {
"cloud": mapstr.M{
"instance": mapstr.M{"id": instanceIDDoc2},
},
"orchestrator": mapstr.M{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure about this test here

based on documentation:

The third optional configuration setting is `overwrite`. When overwrite is true, add_cloud_metadata overwrites existing `cloud.*` fields (false by default).

now when the orchestrator is not part of the cloud object, this will not be overwritten.
Any thought?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry for delaying to test this Tania. I think that this page strictly speaking does not refer to orchestrator at all.

I think we can leave it for now or of you want to add a note in the doc

"cluster": mapstr.M{
"name": clusterNameValue,
"id": fmt.Sprintf("arn:aws:eks:%s:%s:cluster/%s", regionDoc1, accountIDDoc1, clusterNameValue),
},
},
},
},
{
Expand Down Expand Up @@ -244,11 +250,11 @@ func TestRetrieveAWSMetadataEC2(t *testing.T) {
"region": regionDoc1,
"availability_zone": availabilityZoneDoc1,
"service": mapstr.M{"name": "EC2"},
"orchestrator": mapstr.M{
"cluster": mapstr.M{
"name": clusterNameValue,
"id": fmt.Sprintf("arn:aws:eks:%s:%s:cluster/%s", regionDoc1, accountIDDoc1, clusterNameValue),
},
},
"orchestrator": mapstr.M{
"cluster": mapstr.M{
"name": clusterNameValue,
"id": fmt.Sprintf("arn:aws:eks:%s:%s:cluster/%s", regionDoc1, accountIDDoc1, clusterNameValue),
},
},
},
Expand Down
Loading