Skip to content

fix: use aws http buildable client for add_cloud_metadata#44189

Merged
Kavindu-Dodan merged 3 commits intoelastic:mainfrom
Kavindu-Dodan:fix/change-aws-client
May 7, 2025
Merged

fix: use aws http buildable client for add_cloud_metadata#44189
Kavindu-Dodan merged 3 commits intoelastic:mainfrom
Kavindu-Dodan:fix/change-aws-client

Conversation

@Kavindu-Dodan
Copy link
Contributor

@Kavindu-Dodan Kavindu-Dodan commented May 2, 2025

Proposed commit message

Use AWS-specific HTTP client awshttp.BuildableClient with overrides matching generic HTTP client of the processor. This allows the use of custom CA bundle loading and avoids failing internal to AWS SDK.

Fix was tested in an EC2 environment with AWS_CA_BUNDLE and it works as expected.

image

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

Related issues

Fixes #44186

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label May 2, 2025
@Kavindu-Dodan Kavindu-Dodan added Team:obs-ds-hosted-services Label for the Observability Hosted Services team backport-8.x Automated backport to the 8.x branch with mergify labels May 2, 2025
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label May 2, 2025
@elastic elastic deleted a comment from mergify bot May 2, 2025
@Kavindu-Dodan Kavindu-Dodan force-pushed the fix/change-aws-client branch 2 times, most recently from 867e446 to a18f8e2 Compare May 5, 2025 17:01
@Kavindu-Dodan Kavindu-Dodan marked this pull request as ready for review May 5, 2025 17:33
@Kavindu-Dodan Kavindu-Dodan requested a review from a team as a code owner May 5, 2025 17:33
@elasticmachine
Copy link
Contributor

Pinging @elastic/obs-ds-hosted-services (Team:obs-ds-hosted-services)

@Kavindu-Dodan Kavindu-Dodan force-pushed the fix/change-aws-client branch from a0d1ca0 to 4f68877 Compare May 5, 2025 17:35
Comment on lines +124 to +132
awsRegion := instanceIdentity.Region
accountID := instanceIdentity.AccountID
instanceID := instanceIdentity.InstanceID

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

Choose a reason for hiding this comment

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

Note - these are lint fixes and not related to core change.

@Kavindu-Dodan Kavindu-Dodan changed the title fix: use aws http client for add_cloud_metadata May 5, 2025
// generate AWS specific client with overriding requirements
var awsHTTPClient awshttp.BuildableClient
awsHTTPClient = *awsHTTPClient.WithTimeout(client.Timeout)
awsHTTPClient = *awsHTTPClient.WithTransportOptions(func(tr *http.Transport) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need both awsHTTPClient.WithTimeout and awsHTTPClient.WithTransportOptions here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I did this here to match the derived client to the client we parsed into this function. And this generic client is derived here [1] and have some overriding options :)

[1] - https://github.com/elastic/beats/blob/main/libbeat/processors/add_cloud_metadata/providers.go#L164-L175

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe something like this then?

	awsHTTPClient := *awshttp.NewBuildableClient().WithTimeout(client.Timeout).WithTransportOptions(func(tr *http.Transport) {
		transport, ok := client.Transport.(*http.Transport)
		if ok {
			tr.TLSClientConfig = transport.TLSClientConfig
		}

		tr.DisableKeepAlives = true
	})
Copy link
Contributor Author

@Kavindu-Dodan Kavindu-Dodan May 5, 2025

Choose a reason for hiding this comment

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

Yeah that's a nice formatting. I have adopted it - 14fb736 :)

tr.TLSClientConfig = transport.TLSClientConfig
}

tr.DisableCompression = true
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we setting tr.DisableCompression = true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh sorry, already updated this :) should have been DisableKeepAlives and matches with generic client. Also related to this discussion #44189 (comment)

@Kavindu-Dodan Kavindu-Dodan force-pushed the fix/change-aws-client branch from 4f68877 to 82aaa3d Compare May 5, 2025 18:21
Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
@Kavindu-Dodan Kavindu-Dodan force-pushed the fix/change-aws-client branch from 14fb736 to ef860c7 Compare May 5, 2025 20:14
Copy link
Contributor

@zmoog zmoog left a comment

Choose a reason for hiding this comment

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

LGTM

@Kavindu-Dodan Kavindu-Dodan merged commit f54c496 into elastic:main May 7, 2025
195 checks passed
@Kavindu-Dodan Kavindu-Dodan added backport-8.17 Automated backport with mergify backport-8.18 Automated backport to the 8.18 branch backport-active-8 Automated backport with mergify to all the active 8.[0-9]+ branches backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches labels May 7, 2025
@Kavindu-Dodan Kavindu-Dodan added bugfix backport backport-8.17 Automated backport with mergify backport-8.18 Automated backport to the 8.18 branch backport-9.0 Automated backport to the 9.0 branch backport-8.19 Automated backport to the 8.19 branch and removed backport-8.x Automated backport to the 8.x branch with mergify backport-8.17 Automated backport with mergify backport-8.18 Automated backport to the 8.18 branch backport labels May 7, 2025
mergify bot pushed a commit that referenced this pull request May 7, 2025
* use aws http client

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* add changelog entry

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review change : use chaining

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(cherry picked from commit f54c496)
mergify bot pushed a commit that referenced this pull request May 7, 2025
* use aws http client

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* add changelog entry

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review change : use chaining

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(cherry picked from commit f54c496)
mergify bot pushed a commit that referenced this pull request May 7, 2025
* use aws http client

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* add changelog entry

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review change : use chaining

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(cherry picked from commit f54c496)
mergify bot pushed a commit that referenced this pull request May 7, 2025
* use aws http client

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* add changelog entry

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

* review change : use chaining

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>

---------

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
(cherry picked from commit f54c496)
@Kavindu-Dodan Kavindu-Dodan removed backport-active-8 Automated backport with mergify to all the active 8.[0-9]+ branches backport-active-9 Automated backport with mergify to all the active 9.[0-9]+ branches labels May 7, 2025
v1v added a commit to v1v/beats that referenced this pull request May 7, 2025
* upstream/main:
  bk: use OIDC to create AWS cloud resources (elastic#44202)
  jenkins: remove references to the Jenkins pipelines and old packaging (elastic#41625)
  fix: use aws http buildable client for add_cloud_metadata (elastic#44189)
  [main](backport elastic#44166) docs: Prepare Changelog for 8.18.1 (elastic#44237)
Kavindu-Dodan added a commit that referenced this pull request May 7, 2025
…44248)

* use aws http client



* add changelog entry



* review change : use chaining



---------


(cherry picked from commit f54c496)

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
Co-authored-by: Kavindu Dodanduwa <Kavindu-Dodan@users.noreply.github.com>
Kavindu-Dodan added a commit that referenced this pull request May 7, 2025
…44249)

* use aws http client



* add changelog entry



* review change : use chaining



---------


(cherry picked from commit f54c496)

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
Co-authored-by: Kavindu Dodanduwa <Kavindu-Dodan@users.noreply.github.com>
Kavindu-Dodan added a commit that referenced this pull request May 7, 2025
…44250)

* use aws http client



* add changelog entry



* review change : use chaining



---------


(cherry picked from commit f54c496)

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
Co-authored-by: Kavindu Dodanduwa <Kavindu-Dodan@users.noreply.github.com>
Kavindu-Dodan added a commit that referenced this pull request May 7, 2025
…44251)

* use aws http client



* add changelog entry



* review change : use chaining



---------


(cherry picked from commit f54c496)

Signed-off-by: Kavindu Dodanduwa <kavindu.dodanduwa@elastic.co>
Co-authored-by: Kavindu Dodanduwa <Kavindu-Dodan@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-8.17 Automated backport with mergify backport-8.18 Automated backport to the 8.18 branch backport-8.19 Automated backport to the 8.19 branch backport-9.0 Automated backport to the 9.0 branch bugfix Team:obs-ds-hosted-services Label for the Observability Hosted Services team

4 participants