Skip to content

Commit

Permalink
[add_cloud_metadata] fix the orchestrator metadata for the aws cloud …
Browse files Browse the repository at this point in the history
…provider (#37651) (#37976)

* add_cloud_metadata: fix the orchestrator metadata for the aws cloud provider

Signed-off-by: Tetiana Kravchenko <[email protected]>

* rename the map name: cloud -> meta; fix tests

Signed-off-by: Tetiana Kravchenko <[email protected]>

---------

Signed-off-by: Tetiana Kravchenko <[email protected]>
(cherry picked from commit 435e729)

Co-authored-by: Tetiana Kravchenko <[email protected]>
  • Loading branch information
mergify[bot] and tetianakravchenko authored Feb 14, 2024
1 parent ebebb4e commit d32dda4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,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{
"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

0 comments on commit d32dda4

Please sign in to comment.