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 ability to generate buildkite pipelines from integration testing framework #5391

Merged
merged 32 commits into from
Sep 30, 2024

Conversation

blakerouse
Copy link
Contributor

@blakerouse blakerouse commented Aug 30, 2024

What does this PR do?

Adds the ability to generate the integration testing workload as buildkite pipelines.

This doesn't actually complete the enablement. This just provides a great starting point for generating the buildkite steps. More work is still to be done to actually perform the work in the steps.

Why is it important?

Ensures that all testing logic is still defined in golang test files, but allows the work to be performed by buildkite runners. This removes the need for the integration tests to spin up GCP instances, but doesn't stop that from happening when developers need to run the tests locally.

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/fragments using the changelog tool
  • [ ] I have added an integration test or an E2E test

@blakerouse blakerouse self-assigned this Aug 30, 2024
Copy link
Contributor

mergify bot commented Sep 2, 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 integration-buildkite upstream/integration-buildkite
git merge upstream/main
git push upstream integration-buildkite

Copy link
Contributor

mergify bot commented Sep 10, 2024

backport-v8.x has been added to help with the transition to the new branch 8.x.

Copy link
Contributor

mergify bot commented Sep 11, 2024

backport-v8.x has been added to help with the transition to the new branch 8.x.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Sep 11, 2024
@v1v v1v removed the backport-v8.x label Sep 11, 2024
@pazone pazone force-pushed the integration-buildkite branch from 50878e6 to 9ccdb9b Compare September 17, 2024 09:37
Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

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

I'm a little worried seeing more code making its way into magefile.go and the pkg/testing package.
The reason that the code has been added there is that there is already part of the functionality in magefile and this is pulling in more code, code that we cannot easily test/refactor.

There's nothing technically wrong with the PR, but having the source code tightly coupled with elastic-agent CI tool in pkg/testing looks like a dependency in the wrong direction.

magefile.go Outdated
return fmt.Errorf("failed to create runner: %w", err)
}

steps, err := r.Buildkite()
Copy link
Member

@pchila pchila Sep 20, 2024

Choose a reason for hiding this comment

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

Why is Buildkite() a method of a runner ?
I understand that there's some convenient code already there but is generating buildkite steps a responsibility of a runner ?
Should an integration test runner know about Buildkite and its step definition?

This looks like a code smell as the runner is probably doing too much
Perhaps the runner logic should be broken up in smaller independent pieces ?

Edit:
What about extracting the batching functionality and dumping the batches in a structured manner so that the buildkite steps can be built from that ?
That should be something that enables the dynamic creation of buildkite steps without introducing tight coupling between integration test runners and buildkite

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 prefer it this way otherwise I would have to expose more internals of the runner for the buildkite runner. Generating buildkite is a unique way of running the testing runner, but either way its still the runner performing the work its just being done through buildkite.

My overall goal of this PR was just to show that it can be done and not something that needed to be hard coded in YAML. The actually work of making this work will be done by @pazone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pazone Okay, I just went ahead and refactored the runner to allow me to pull it out and not create the runner as you requested. Should be good now.

Copy link
Contributor

mergify bot commented Sep 20, 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 integration-buildkite upstream/integration-buildkite
git merge upstream/main
git push upstream integration-buildkite

@blakerouse blakerouse force-pushed the integration-buildkite branch from 74235c1 to 73f921a Compare September 20, 2024 18:14
@blakerouse
Copy link
Contributor Author

buildkite test this

@swiatekm swiatekm removed their request for review September 23, 2024 08:08
Copy link
Member

@pchila pchila left a comment

Choose a reason for hiding this comment

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

Thanks @blakerouse , I appreciate the effort of breaking up runner into smaller pieces even if it is mostly moving structs and interfaces to other packages.
It looks better than the previous iteration, I am still a bit dismayed that, while some functions have relocated to magefile.go, structs and tests specific to buildkite live under pkg/testing/buildkite.

What I meant in my previous review when talking about breaking up some of the runner functionality was:

  • expose batching as a free function of some kind
  • have it return a structured output (not buildkite-specific, just generic grouping of tests on different platforms) for the batches that need to run
  • envelope the operation in a mage target and have buildkite figure out what steps to run in the pipeline based on that output.

Would that be feasible in this or in a follow-up PR?

@blakerouse
Copy link
Contributor Author

Thanks @blakerouse , I appreciate the effort of breaking up runner into smaller pieces even if it is mostly moving structs and interfaces to other packages. It looks better than the previous iteration, I am still a bit dismayed that, while some functions have relocated to magefile.go, structs and tests specific to buildkite live under pkg/testing/buildkite.

What I meant in my previous review when talking about breaking up some of the runner functionality was:

  • expose batching as a free function of some kind

Done in this PR as requested: https://github.com/elastic/elastic-agent/pull/5391/files#diff-a19232eca67fe3c99e1ee41e39cece7dcf26dc8ba648cc6784b4bbdd14aa2e16R15

  • have it return a structured output (not buildkite-specific, just generic grouping of tests on different platforms) for the batches that need to run

Done in this PR: https://github.com/elastic/elastic-agent/pull/5391/files#diff-a19232eca67fe3c99e1ee41e39cece7dcf26dc8ba648cc6784b4bbdd14aa2e16R34

This is not buildkite specific in anyway.

  • envelope the operation in a mage target and have buildkite figure out what steps to run in the pipeline based on that output.

Done here in its own module (adding less to the magefile which is already too large): https://github.com/elastic/elastic-agent/pull/5391/files#diff-76ca66738b839b0b344d18df21e58cdc31fd9a9cd9c77365e3e57193cf1483a7R204

Would that be feasible in this or in a follow-up PR?

I did everything requested in your previous comment and I have everything already in this PR you are requesting again.

@blakerouse
Copy link
Contributor Author

buildkite test this

1 similar comment
@blakerouse
Copy link
Contributor Author

buildkite test this

@blakerouse blakerouse enabled auto-merge (squash) September 26, 2024 20:48
@blakerouse blakerouse disabled auto-merge September 26, 2024 20:48
@blakerouse blakerouse enabled auto-merge (squash) September 26, 2024 20:48
@pazone
Copy link
Contributor

pazone commented Sep 27, 2024

QQ: can we use build tags like go test -tags integration, group:fleet, stack:true, sudo:false ? Would it solve the tests filtering problem?

@pazone pazone self-requested a review September 27, 2024 13:54
@pazone
Copy link
Contributor

pazone commented Sep 30, 2024

I am concerned by the complexity of the YAML generation process. It's good that it generates the steps but it's hard to troubleshoot and modify that.
Wouldn't it be better if we try a combined approach: The steps will stay declarative but the list of the tests can be defined by a mage target. For example:

steps: 
- name: "Integration tests (sudo) - Ubuntu 22.04 AMD64"
   command: |
     export TEST_DEFINE_TESTS=$(mage integration:what_to_run "sudo" "ubuntu_22_04_AMD" "9.0.0")
     mage integration:testOnRemote
     ...

Copy link

@blakerouse blakerouse merged commit c645a5a into elastic:main Sep 30, 2024
14 checks passed
mergify bot pushed a commit that referenced this pull request Sep 30, 2024
…framework (#5391)

Adds the ability to generate the integration testing workload as buildkite pipelines.

This doesn't actually complete the enablement. This just provides a great starting point for generating the buildkite steps. More work is still to be done to actually perform the work in the steps.

(cherry picked from commit c645a5a)
blakerouse added a commit that referenced this pull request Oct 1, 2024
…framework (#5391) (#5630)

Adds the ability to generate the integration testing workload as buildkite pipelines.

This doesn't actually complete the enablement. This just provides a great starting point for generating the buildkite steps. More work is still to be done to actually perform the work in the steps.

(cherry picked from commit c645a5a)

Co-authored-by: Blake Rouse <blake.rouse@elastic.co>
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 skip-changelog Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants