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

[aws] Set region in config from GetBucketLocation API call #41572

Merged
merged 3 commits into from
Nov 11, 2024

Conversation

kaiyan-sheng
Copy link
Contributor

@kaiyan-sheng kaiyan-sheng commented Nov 8, 2024

Proposed commit message

This PR sets the region of the S3 bucket as the region in AWS config to make API calls.

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.

How to test this PR locally

Without this change, run Filebeat aws-s3 input with this config and you will see error:

s3 GetObject failed: operation error S3: GetObject, https response error StatusCode: 301, RequestID: 01H7T2XWRZ6N44MW, HostID: WqYAZM+diCdCnBwj2i1tAzchSXBZql8SdIfQ0ZUCKHoR4YbMiBGD10duVYqIQ97pCg/j8MmJTgo=, api error PermanentRedirect: The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

config:

filebeat.inputs:
- type: aws-s3
  enabled: true
  credential_profile_name: elastic-observability
  number_of_workers: 5
  bucket_arn: 'arn:aws:s3:::tkravchenko-test1'

The workaround is to add default_region: us-east-2 in the config.

With this change, Filebeat is able to get the bucket location/region from API call and assign it to the region config.

@kaiyan-sheng kaiyan-sheng requested a review from a team as a code owner November 8, 2024 20:24
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 8, 2024
Copy link
Contributor

mergify bot commented Nov 8, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @kaiyan-sheng? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit

Copy link
Contributor

mergify bot commented Nov 8, 2024

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label and remove the backport-8.x label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Nov 8, 2024
@kaiyan-sheng kaiyan-sheng added backport-8.15 Automated backport to the 8.15 branch with mergify backport-8.16 Automated backport with mergify Team:obs-ds-hosted-services Label for the Observability Hosted Services team labels Nov 8, 2024
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Nov 8, 2024
@elasticmachine
Copy link
Collaborator

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

Copy link
Contributor

mergify bot commented Nov 8, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b aws_region_s3 upstream/aws_region_s3
git merge upstream/main
git push upstream aws_region_s3

s3Client = s3.NewFromConfig(awsConfig, config.s3ConfigModifier)
if regionName != in.awsConfig.Region {
in.awsConfig.Region = regionName
s3Client = s3.NewFromConfig(in.awsConfig, in.config.s3ConfigModifier)
Copy link
Contributor

Choose a reason for hiding this comment

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

➕ for using pointers. From first look, old code should have worked without any issue. But seems, there's some buggy optimization from Go, making the call at 28 to have same aws config copy as used in line 20 😁

Good work catching this and fixing 🙌

Copy link
Contributor

@tetianakravchenko tetianakravchenko left a comment

Choose a reason for hiding this comment

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

Thank you for a quick fix!
I've tested filebeat and it works!

@kaiyan-sheng kaiyan-sheng merged commit 076ea50 into elastic:main Nov 11, 2024
22 checks passed
@kaiyan-sheng kaiyan-sheng deleted the aws_region_s3 branch November 11, 2024 16:54
mergify bot pushed a commit that referenced this pull request Nov 11, 2024
This PR sets the region of the S3 bucket as the region in AWS config to make API calls.

(cherry picked from commit 076ea50)
mergify bot pushed a commit that referenced this pull request Nov 11, 2024
This PR sets the region of the S3 bucket as the region in AWS config to make API calls.

(cherry picked from commit 076ea50)
mergify bot pushed a commit that referenced this pull request Nov 11, 2024
This PR sets the region of the S3 bucket as the region in AWS config to make API calls.

(cherry picked from commit 076ea50)
kaiyan-sheng added a commit that referenced this pull request Nov 11, 2024
…41590)

This PR sets the region of the S3 bucket as the region in AWS config to make API calls.

(cherry picked from commit 076ea50)

Co-authored-by: kaiyan-sheng <[email protected]>
kaiyan-sheng added a commit that referenced this pull request Nov 11, 2024
kaiyan-sheng added a commit that referenced this pull request Nov 11, 2024
…tion API call (#41589)

* [aws] Set region in config from GetBucketLocation API call (#41572)

This PR sets the region of the S3 bucket as the region in AWS config to make API calls.

(cherry picked from commit 076ea50)

* Update CHANGELOG.next.asciidoc

---------

Co-authored-by: kaiyan-sheng <[email protected]>
kaiyan-sheng added a commit that referenced this pull request Nov 11, 2024
…tion API call (#41588)

* [aws] Set region in config from GetBucketLocation API call (#41572)

This PR sets the region of the S3 bucket as the region in AWS config to make API calls.

(cherry picked from commit 076ea50)

* Update CHANGELOG.next.asciidoc

---------

Co-authored-by: kaiyan-sheng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify backport-8.15 Automated backport to the 8.15 branch with mergify backport-8.16 Automated backport with mergify Team:obs-ds-hosted-services Label for the Observability Hosted Services team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants