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

Fix hetzner and openstack tests by adding AWS_EC2_METADATA_DISABLED=true in ec2 #37907

Merged
merged 14 commits into from
Feb 14, 2024

Conversation

kaiyan-sheng
Copy link
Contributor

@kaiyan-sheng kaiyan-sheng commented Feb 7, 2024

Proposed commit message

This PR is to add AWS_EC2_METADATA_DISABLED=true to disable IMDS when the real AWS SDK IMDS client is used. With this parameter, the non-EC2 provider tests should pass when running within an EC2 VM.

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.

Author's Checklist

@kaiyan-sheng kaiyan-sheng self-assigned this Feb 7, 2024
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Feb 7, 2024
Copy link
Contributor

mergify bot commented Feb 7, 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-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@elasticmachine
Copy link
Collaborator

elasticmachine commented Feb 7, 2024

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Duration: 132 min 58 sec

❕ Flaky test report

No test was executed to be analysed.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@axw
Copy link
Member

axw commented Feb 8, 2024

Perhaps we should also disable the IMDS client by default in the tests, by adding an init function to the top of provider_aws_ec2_test.go, like:

func init() {
        // Disable IMDS when the real AWS SDK IMDS client is used,
        // so tests are isolated from the environment. Otherwise,
        // tests for non-EC2 providers may fail when the tests are
        // run within an EC2 VM.
        os.Setenv("AWS_EC2_METADATA_DISABLED", "true")
}

WDYT?

@@ -60,6 +69,7 @@ func TestRetrieveHetznerMetadata(t *testing.T) {
defer server.Close()

config, err := conf.NewConfigFrom(map[string]interface{}{
// "providers": []string{"hetzner"},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@axw Thanks for pointing out the config os.Setenv("AWS_EC2_METADATA_DISABLED", "true")! Without specifying the providers to be hetzner, the test passes too now,. Should I still give a providers just to be sure? 😂

Copy link
Member

Choose a reason for hiding this comment

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

I think it may be better to leave it out, to try and avoid issues like #13816 as much as possible.

@@ -60,6 +69,7 @@ func TestRetrieveHetznerMetadata(t *testing.T) {
defer server.Close()

config, err := conf.NewConfigFrom(map[string]interface{}{
// "providers": []string{"hetzner"},
Copy link
Member

Choose a reason for hiding this comment

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

I think it may be better to leave it out, to try and avoid issues like #13816 as much as possible.

@kaiyan-sheng kaiyan-sheng marked this pull request as ready for review February 13, 2024 01:54
@kaiyan-sheng kaiyan-sheng requested a review from a team as a code owner February 13, 2024 01:54
@kaiyan-sheng kaiyan-sheng changed the title Specify provider name in hetzner and openstack tests Fix hetzner and openstack tests by adding AWS_EC2_METADATA_DISABLED=true in ec2 Feb 13, 2024
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @kaiyan-sheng

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @kaiyan-sheng

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @kaiyan-sheng

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @kaiyan-sheng

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @kaiyan-sheng

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @kaiyan-sheng

@zmoog zmoog added the Team:Cloud-Monitoring Label for the Cloud Monitoring team label Feb 14, 2024
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Feb 14, 2024
@zmoog zmoog added the bug label Feb 14, 2024
@kaiyan-sheng kaiyan-sheng added backport-7.17 Automated backport to the 7.17 branch with mergify backport-v8.12.0 Automated backport with mergify backport-v8.13.0 Automated backport with mergify labels Feb 14, 2024
@kaiyan-sheng kaiyan-sheng merged commit 38e7d6f into elastic:main Feb 14, 2024
107 checks passed
@kaiyan-sheng kaiyan-sheng deleted the add_cloud_metadata_tests branch February 14, 2024 16:06
mergify bot pushed a commit that referenced this pull request Feb 14, 2024
…rue in ec2 (#37907)

(cherry picked from commit 38e7d6f)

# Conflicts:
#	libbeat/processors/add_cloud_metadata/provider_aws_ec2_test.go
#	libbeat/processors/add_cloud_metadata/provider_hetzner_cloud_test.go
mergify bot pushed a commit that referenced this pull request Feb 14, 2024
kaiyan-sheng added a commit that referenced this pull request Feb 14, 2024
…rue in ec2 (#37907) (#38016)

(cherry picked from commit 38e7d6f)

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-7.17 Automated backport to the 7.17 branch with mergify backport-v8.12.0 Automated backport with mergify backport-v8.13.0 Automated backport with mergify bug Team:Cloud-Monitoring Label for the Cloud Monitoring team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants