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

[Ind Agent] Update packaging to properly package from manifest if given #4885

Merged
merged 37 commits into from
Jul 2, 2024

Conversation

dwhyrock
Copy link
Collaborator

@dwhyrock dwhyrock commented Jun 7, 2024

What does this PR do?

This PR updates the packaging code to operate differently when packaging from a local build vs packaging from a manifest.

The manifest packaging relies on the items in the manifest, while the local one uses globbing to find all packages/directories that match the expected version string.

Why is it important?

For the Independent Agent Release, a manifest is created that includes opted-in projects that have a patch version one higher than the rest of the opted-out/previously-released projects. The file globbing expecting one single version is what skips the opted-in projects.

Previously, we had been packaging the incorrect opted-in projects, which is why we had verified those projects were properly packaged. But when that bug was fixed, we did not properly verify that everything was still there since the packaging still succeeded.

Checklist

  • packaging dependencies with a manifest for an Independent Agent build

  • packaging dependencies with a manifest for a Unified Release / Stack build

  • packaging dependencies pulling the latest unified release version

  • packaging dependencies pulling from a DROP_PATH

  • packaging by building beats dependencies located side by side with the agent code

  • 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

Disruptive User Impact

How to test this PR locally

Related issues

Questions to ask yourself

  • How are we going to support this in production?
  • How are we going to measure its adoption?
  • How are we going to debug this?
  • What are the metrics I should take care of?
  • ...

Copy link
Contributor

mergify bot commented Jun 7, 2024

This pull request does not have a backport label. Could you fix it @dwhyrock? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

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

NOTE: backport-skip has been added to this pull request.

@mergify mergify bot added the backport-skip label Jun 7, 2024
@dwhyrock dwhyrock added backport-v8.14.0 Automated backport with mergify and removed backport-skip labels Jun 7, 2024
@dwhyrock
Copy link
Collaborator Author

I've added in some code here so that the packaging code looks for the expected version (e.g., 8.14.0) as well as the bumped Independent Agent version for opted-in projects (e.g., 8.14.1).

However, it's starting to get a little complex. The latest error I'm seeing is this:

Error: failed copying spec file "specs/endpoint-security-8.14.1-darwin-x86_64.spec.yml" to "build/elastic-agent-drop/darwin-x86_64.tar.gz/endpoint-security-8.14.1-darwin-x86_64.spec.yml": copy failed: cannot stat source file specs/endpoint-security-8.14.1-darwin-x86_64.spec.yml: stat specs/endpoint-security-8.14.1-darwin-x86_64.spec.yml: no such file or directory

It appears as if it's not copying the proper endpoint-security spec file to the right location with the bumped version number.

I'm thinking that for elastic-agent-package pipeline builds kicked off by the Independent Agent workflow, we should maybe pass in an env var that includes a comma-separated list of opted-in projects. Maybe something like:

INDEPENDENT_AGENT_OPTIN_PROJECTS="endpoint-dev,another-project"

Then we could use that var as kind of a gate around the logic I have put in here already that includes a bumped version, and for the copying of the spec files to the proper versions for the proper projects.

Thoughts? @gogochan @cmacknz @pchila @pierrehilbert

@gogochan
Copy link
Collaborator

IMO, having optional INDEPENDENT_AGENT_OPTIN_PROJECTS environment variable to control what to package makes sense. If it is not specified, the pipeline can always fall back to the default logic. I do not have in-depth understanding of this pipeline to foresee any issues with this approach though.

@dwhyrock dwhyrock changed the title [DRAFE] [Ind Agent] Update packaging to properly include next patch version for opted-in projects [DRAFT] [Ind Agent] Update packaging to properly include next patch version for opted-in projects Jun 10, 2024
// For Independent Agent Releases, any opted-in projects will have a version that is
// one Patch version ahead since we are using the new bumped DRA artifacts for those projects.
// This is acceptable since it is being released only as bundled with Elastic Agent.
patchPlusOneString := fmt.Sprintf("%d.%d.%d", parsedManifestVersion.Major(), parsedManifestVersion.Minor(), parsedManifestVersion.Patch()+1)
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason why the input manifest can't specify the patch+1 version? That would keep the logic for this in the release jobs, with the agent package target just doing what the manifest tells it to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that may be a decent way to go.

I think the way it works is that it uses the version value in the header, which is something like 8.13.4+build202406101001. And then we strip off the metadata to get the base 3-number version for the previously-released (opted-out) projects.

We could probably somewhat easily add something like an optin_version in the header, but that doesn't tell us exactly which projects should use that version.

As it is now, we'd probably have to go through and parse all of the packages in each of the projects and find any that have a filename that includes the patch+1 version in it.

Perhaps we could also include just a list of opted_in_projects at the top level?

We probably need to ask @DaveSys911 whether adding fields to the Ind Agent manifest would be a big issue or not.

@cmacknz
Copy link
Member

cmacknz commented Jun 10, 2024

IMO, having optional INDEPENDENT_AGENT_OPTIN_PROJECTS environment variable to control what to package makes sense.

Instead of an environment variable, can we have the manifest specify the mixed set of versions? Alternatively, could this variable just be in the manifest? That way the manifest would define the contract for what agent should do.

@cmacknz
Copy link
Member

cmacknz commented Jun 10, 2024

CC @pchila for opinions since I think he implemented the packaging target that is used here.

@pchila
Copy link
Member

pchila commented Jun 10, 2024

@cmacknz @dwhyrock
The DownloadComponentsFromManifest target should only take care of downloading files into the drop folder of agent based on the manifest contents that is passed in. As such whatever version is pushed in the manifest with its own URLs for download should be used.

The main problem for including dependencies with different versions resides in collectPackageDependencies (which calls DownloadComponentsFromManifest) and flattenDependencies as these make assumptions on the version of the dependencies (the code existed before the independent release and is shared with "normal" packaging of elastic agent) as these will use the version in a glob pattern to pull in the dependencies to package.

I think the best solution to support all the flows below:

  • packaging dependencies with a manifest
  • packaging dependencies pulling the latest unified release version
  • packaging dependencies pulling from a DROP_PATH
  • packaging by building beats dependencies located side by side with the agent code
    is:
  1. Change the DownloadManifest target to ONLY download what is in the manifest and place it in the DROP_PATH
  2. Pass along a nullable manifest into collectDependencies and flattenDependencies (we can reuse the same env var MANIFEST_URL we already specify) so that those functions know which dependencies and version to pick and package for all platforms

This is obviously a bigger undertaking that trying patch +-1 but it should ensure stability and correctness.

As you can see in the list of ways to package an agent above we have quite a lot of legacy package processes to support and I feel that adding an optional manifest is the least disruptive (will require quite a bit of refactoring though)

@dwhyrock
Copy link
Collaborator Author

Thanks for the great response, @pchila !

I agree that a more robust solution is probably better for the long and should make it more reliable by relying on the manifest.

I'll work on changes based on your recommendation. When closer to completion, I may need help verifying that it works in all of those cases as I'm not fully fluent in how they are executed.

@pierrehilbert pierrehilbert requested a review from cmacknz June 21, 2024 07:41
"prefix": "",
"projects": {
"apm-server": {
"branch": "main",
Copy link
Member

Choose a reason for hiding this comment

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

Not part of this PR, but seeing this as main is a bit weird since it should be `8.14.

@cmacknz
Copy link
Member

cmacknz commented Jun 26, 2024

Tried the following and they both work:

MANIFEST_URL=https://snapshots.elastic.co/8.15.0-875a6caa/manifest-8.15.0-SNAPSHOT.json AGENT_DROP_PATH=./build/drop PLATFORMS=darwin/arm64 PACKAGES=targz mage -v downloadManifest packageUsingDRA
MANIFEST_URL=https://staging.elastic.co/independent-agent/8.14.0+build202406261002/manifest-8.14.0+build202406261002.json AGENT_DROP_PATH=./build/drop PLATFORMS=darwin/arm64 PACKAGES=targz mage -v downloadManifest packageUsingDRA

The only oddity was the 8.14.0 manifest created a elastic-agent-8.14.0-darwin-aarch64.tar.gz but this is probably because I didn't set the agent package version properly. Possibly a nice enhancement someday would be to pick up the agent version based on the manifest version.

magefile.go Outdated Show resolved Hide resolved
Copy link

Copy link
Contributor

@blakerouse blakerouse left a comment

Choose a reason for hiding this comment

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

Looks good. Like that it has tests for dev-tools code, always nice to have.

@cmacknz cmacknz merged commit 0e7a211 into main Jul 2, 2024
13 checks passed
@cmacknz cmacknz deleted the ind-agent-fix-package-endpoint-next-version branch July 2, 2024 17:15
mergify bot pushed a commit that referenced this pull request Jul 2, 2024
…en (#4885)

* Download from manifest if version has +1 patch

* Try modified globExpr

* use version package

* catch err

* use panic

* Add the filepath

* better package finding

* more intermediate work

* more progress

* it seems to maybe work

* fixed bug

* Copying spec files as well

* temp test value

* fixing linting errors

* Clean up manifest code

* Cleaning up

* Cleanup 2

* removing test variable

* addressing PR comments and cleanup

* Adding manifest tests

* Update magefile.go

Co-authored-by: Craig MacKenzie <[email protected]>

* Switch to go:embed for tests.

* Build component specs from external binaries.

* Convert component to project in var names

* Return error when package not found.

Add contexts where necessary

* Filter unsupported platforms.

* Fix darwin/arm64 build.

* Several renames for consistency.

* A few more renames.

* Move code out of magefile

* mage fmt

* Fix log message.

* Fix lint warnings.

* Rename test.

* Refactor to share download from manifest logic.

---------

Co-authored-by: Craig MacKenzie <[email protected]>
Co-authored-by: Pierre HILBERT <[email protected]>
(cherry picked from commit 0e7a211)
pierrehilbert pushed a commit that referenced this pull request Jul 5, 2024
…en (#4885) (#5039)

* Download from manifest if version has +1 patch

* Try modified globExpr

* use version package

* catch err

* use panic

* Add the filepath

* better package finding

* more intermediate work

* more progress

* it seems to maybe work

* fixed bug

* Copying spec files as well

* temp test value

* fixing linting errors

* Clean up manifest code

* Cleaning up

* Cleanup 2

* removing test variable

* addressing PR comments and cleanup

* Adding manifest tests

* Update magefile.go

Co-authored-by: Craig MacKenzie <[email protected]>

* Switch to go:embed for tests.

* Build component specs from external binaries.

* Convert component to project in var names

* Return error when package not found.

Add contexts where necessary

* Filter unsupported platforms.

* Fix darwin/arm64 build.

* Several renames for consistency.

* A few more renames.

* Move code out of magefile

* mage fmt

* Fix log message.

* Fix lint warnings.

* Rename test.

* Refactor to share download from manifest logic.

---------

Co-authored-by: Craig MacKenzie <[email protected]>
Co-authored-by: Pierre HILBERT <[email protected]>
(cherry picked from commit 0e7a211)

Co-authored-by: Doug W <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.14.0 Automated backport 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.

7 participants