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

[Beats] Build darwin/arm64 and universal binary #29585

Merged
merged 2 commits into from
Mar 23, 2022
Merged

Conversation

AndersonQ
Copy link
Member

@AndersonQ AndersonQ commented Dec 22, 2021

What does this PR do?

It enables the Elastic-Agent and Beats to be built for darwin/arm64 and generates a universal binary (darwin/universal).

The universal binary is the merge of the darwin/arm64 with darwin/amd64. Therefore it requires to first build the darwin/arm64 and darwin/amd64 and them "merge" them together into the darwin/universal. Also darwin/universal isn't a valid platform or OS/ARCH pair, therefore it isn't recognised by the Go compiler. Given that, the choice was to add darwin/arm64 as a new platform for the Elastic-Agent and when ever both platforms (darwin/arm64 and darwin/amd64) are built, also generate and package the universal binary.
Even though it's quite an implicit behaviour, the alternative would also require a lot of changes and exceptions to have our build process recognising darwin/universal, but compiling darwin/arm64 and darwin/amd64 and merging them. Also the current process makes available all three of them, allowing the user to choose which fits better their needs. The drawback of the universal binary is its size, the double of the single binaries.

A new target, BuildDarwinUniversal was added on the x-packs magefiles required by the Elastic-Agent.

Also fixes some small typos, redundant information on the help command and remove the use of some deprecated functions.

Why is it important?

We need to support Mac with M1 chips

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

  • build darwin/arm64 binary
  • build universal 2 binary
  • use mage to automatically build the universal binary

How to test this PR locally

  1. Build the elastic-agent for the new platforms:

    • darwin/arm64: PLATFORMS="darwin/arm64" PACKAGES="tar.gz" mage package
    • darwin/universal: PLATFORMS="darwin/arm64,darwin/amd64" PACKAGES="tar.gz" mage package
  2. Run the elastic-agent

####Watch out:
The elastic-agent tries to download any binary it might need to comply with the assigned policy. However none of the new binaries from this PR are present on the artifact API and other applications (e.g. fleet-server and elastic-endpoint) also aren't publishing darwin/arm64 versions. Therefore if the elastic-agent tries to download them, it'll fail. This is the expected behavior and this PR does not address it, see Out of Scope.

Out of scope:

  • Handle downloading binaries that does not publish darwin-universal artifacts on the artifact API
  • Handle upgrading a darwin/amd64 agent running under Rosetta2 on a Mac with M1 chip. This will be addressed on another PR.

Related issues

@AndersonQ AndersonQ self-assigned this Dec 22, 2021
@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Dec 22, 2021
@mergify
Copy link
Contributor

mergify bot commented Dec 22, 2021

This pull request does not have a backport label. Could you fix it @AndersonQ? 🙏
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 7./d branch. /d is the digit

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

@mergify mergify bot added the backport-skip Skip notification from the automated backport with mergify label Dec 22, 2021
@AndersonQ AndersonQ changed the title {Elastic Agent] build darwin/arm62 and universal 2 binary [Elastic Agent] build darwin/arm62 and universal 2 binary Dec 22, 2021
@AndersonQ AndersonQ changed the title [Elastic Agent] build darwin/arm62 and universal 2 binary [Elastic Agent] build darwin/arm64 and universal 2 binary Dec 23, 2021
@elasticmachine
Copy link
Collaborator

elasticmachine commented Dec 23, 2021

💚 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

  • Start Time: 2022-03-21T18:06:52.389+0000

  • Duration: 89 min 48 sec

Test stats 🧪

Test Results
Failed 0
Passed 22523
Skipped 1940
Total 24463

💚 Flaky test report

Tests succeeded.

🤖 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!)

@AndersonQ AndersonQ force-pushed the 26683-agent-arm64 branch 2 times, most recently from e00ff3c to 3453f2c Compare January 14, 2022 11:07
@AndersonQ AndersonQ marked this pull request as ready for review January 14, 2022 14:58
@AndersonQ AndersonQ requested a review from a team as a code owner January 14, 2022 14:58
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

@AndersonQ AndersonQ changed the title [Elastic Agent] build darwin/arm64 and universal 2 binary [Elastic Agent] build darwin/arm64 and universal binary Jan 14, 2022
@AndersonQ AndersonQ changed the title [Elastic Agent] build darwin/arm64 and universal binary [Elastic Agent] Build darwin/arm64 and universal binary Jan 14, 2022
@AndersonQ AndersonQ requested a review from a team January 14, 2022 15:06
@v1v
Copy link
Member

v1v commented Jan 18, 2022

This feature will be enabled no just in ElasticAgent but in all the other Beats, is that correct?

@ph
Copy link
Contributor

ph commented Jan 19, 2022

@AndersonQ I've tried to build all the artifacts with make release in the top level directory and it fails on my side

>> Building using: cmd='build/mage-linux-amd64 buildDarwinUniversal', env=[CC=oa64-clang, CXX=oa64-clang++, GOARCH=arm64, GOARM=, GOOS=darwin, PLATFORM_ID=darwin-arm64]
Unknown target specified: "buildDarwinUniversal"
Error: failed building for darwin/arm64: exit status 2
failed building for darwin/arm64: exit status 2
package ran for 14m30.180628207s
Error: failed merging darwin/amd64 and darwin/arm64 into darwin/universal target=buildDarwinUniversal for platform=darwin/arm64: running "docker run --env EXEC_UID=501 --env EXEC_GID=20 -v /Users/ph/go/pkg/mod:/go/pkg/mod:ro --rm --env GOFLAGS=-mod=readonly --env MAGEFILE_VERBOSE= --env MAGEFILE_TIMEOUT= --env SNAPSHOT=false --env DEV=false -v /Users/ph/src/beats:/go/src/github.com/elastic/beats -w /go/src/github.com/elastic/beats/auditbeat docker.elastic.co/beats-dev/golang-crossbuild:1.17.5-darwin-arm64-debian10 --build-cmd build/mage-linux-amd64 buildDarwinUniversal -p darwin/arm64" failed with exit code 1
failed merging darwin/amd64 and darwin/arm64 into darwin/universal target=buildDarwinUniversal for platform=darwin/arm64: running "docker run --env EXEC_UID=501 --env EXEC_GID=20 -v /Users/ph/go/pkg/mod:/go/pkg/mod:ro --rm --env GOFLAGS=-mod=readonly --env MAGEFILE_VERBOSE= --env MAGEFILE_TIMEOUT= --env SNAPSHOT=false --env DEV=false -v /Users/ph/src/beats:/go/src/github.com/elastic/beats -w /go/src/github.com/elastic/beats/auditbeat docker.elastic.co/beats-dev/golang-crossbuild:1.17.5-darwin-arm64-debian10 --build-cmd build/mage-linux-amd64 buildDarwinUniversal -p darwin/arm64" failed with exit code 1
make[1]: *** [release] Error 1
make: *** [release] Error 1

I also try to use the mage buildDarwinUniversal in the x-pack/elastic-agent without luck?
Am I missing something ?

Copy link
Contributor

@ph ph left a comment

Choose a reason for hiding this comment

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

Should have used request changes before for my last comment.

@AndersonQ
Copy link
Member Author

@v1v

This feature will be enabled no just in ElasticAgent but in all the other Beats, is that correct?

Perhaps, I'll double check with the data plane

@AndersonQ
Copy link
Member Author

AndersonQ commented Jan 20, 2022

@ph

@AndersonQ I've tried to build all the artifacts with make release in the top level directory and it fails on my side

That's probably because not all beats have the buildDarwinUniversal target. I'll check and add the missing ones

I also try to use the mage buildDarwinUniversal in the x-pack/elastic-agent without luck? Am I missing something ?

Probably, that's the catch of the approach I took. buildDarwinUniversal assumes that the darwin/amd64 and darwin/arm64 were built as this rule only merges them 2 into the universal binary. Perhaps another name instead of build... would be better.
I'm open to suggestions...

  • createDarwinUniversal,
  • mergeDarwinUniversal (I don't like merge, seems that DarwinUniversal will be merged into something),
  • assembleDarwinUniversal (I think this is the best so far...)

@ph
Copy link
Contributor

ph commented Jan 20, 2022

I think assemble is also more appropriate, I was using make release because this is what the release manager will do, and Agent and his subprocess Filebeat, metricbeat, etc need to be compiled as universal.

@mergify
Copy link
Contributor

mergify bot commented Jan 20, 2022

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 26683-agent-arm64 upstream/26683-agent-arm64
git merge upstream/master
git push upstream 26683-agent-arm64

@AndersonQ AndersonQ requested a review from a team as a code owner January 24, 2022 09:45
@v1v
Copy link
Member

v1v commented Feb 22, 2022

I've got some questions:

  1. Is this particular universal binary something to be released as part of the Unified Release process?
  2. Is it required to use macosx with `docker?

Then, it's worth to involve the CI System and Release teams as they are the ones who provide:

  • MacOS workers in the CI
  • Configure docker in those workers
  • Run the release process as part of the unified release process.

On the other hand, I tried to solve -> #29585 (comment) in #30505 but I'm now facing issues with the docker-machine not being available at runtime. But before doing anything else, we might need to get some clarity about the above questions. MacOSX workers are not bullet proof

@amolnater-qasource
Copy link

Hi @AndersonQ
There was some issue in copying the logs.

  • We have revalidated adding endpoint security on M1 universal artifact agent.
  • Agent directly goes to unhealthy state when endpoint security is added.

Please find below logs for the same using diagnostics command :
elastic-agent-diagnostics-2022-02-24T04-51-13Z-00.zip

Please let us know if anything else is required from our end.
Thanks

@AndersonQ
Copy link
Member Author

@amolnater-qasource @dikshachauhan-qasource it's ready for another QA round, the new packages are on the same Google drive as before.

@dikshachauhan-qasource
Copy link

Hi @AndersonQ

We have revalidated all the artifacts shared with us on 8.1 kibana build and found that:

  • With only system integration all the agents were shipping data to Kibana and were in healthy state, with filebeat and metricbeat binaries in running state. Test using :
    • .tar artifact on Mac 12
    • universal artifact on Mac 12
    • universal artifact on M1
    • aarch artifact on M1
  • However, when endpoint security is added to agent it goes to unhealthy state.

Screenshot:
image

logs for M1 agent with aarch artifact : elastic-agent-diagnostics-2022-03-10T10-40-48Z-00.zip
error-logsfor M1withUniversal-artifact.txt

Build details:
BUILD: 50485

Thanks
QAS

@ph ph added v8.2.0 and removed v8.1.0 labels Mar 10, 2022
@AndersonQ AndersonQ changed the title [Elastic Agent] Build darwin/arm64 and universal binary [Beats] Build darwin/arm64 and universal binary Mar 14, 2022
@mergify
Copy link
Contributor

mergify bot commented Mar 17, 2022

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 26683-agent-arm64 upstream/26683-agent-arm64
git merge upstream/main
git push upstream 26683-agent-arm64

@jlind23 jlind23 requested a review from ph March 22, 2022 10:17
@jasonrhodes
Copy link
Member

@AndersonQ I see that @elastic/infra-monitoring-ui is added a codeowner reviewer here, but I don't see any files owned by us there. Can you help me understand why that might be the case? (Did it at one point include changes to the kibana, elasticsearch, logstash, or beats modules, for example?)

@jasonrhodes jasonrhodes removed the request for review from a team March 22, 2022 12:18
@AndersonQ
Copy link
Member Author

Hi @jasonrhodes, you're correct, there is nothing you folks would need to review. I don't know why you were asked to review.

Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

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

LGTM, but I have a couple of questions.

Comment on lines +214 to +215
// TODO(AndersonQ): comment in after the tests pass
// 'darwin/arm64'
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the plan here? Comment it in once CI is green and merge or do it in another PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up testing it on the elastic-agent repo, didn't do what I needed. Besides in order to unblock the release team, better to merge it now and adjust the CI later. But good catch anyway :)

Comment on lines +78 to +80
// AssembleDarwinUniversal merges the darwin/amd64 and darwin/arm64 into a single
// universal binary using `lipo`. It assumes the darwin/amd64 and darwin/arm64
// were built and only performs the merge.
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use mage dependencies to ensure the binaries are built instead of failing?

Copy link
Member Author

Choose a reason for hiding this comment

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

Mage dependencies will ensure a function was called, here I need more than just that. I need the build to have been invoked with the right environment variables, it has happened 2 times (once for each architecture). Thus it isn't really a solution here.

Copy link
Contributor

@ph ph left a comment

Choose a reason for hiding this comment

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

I think @belimawr comment is good concerning the mage dependencies to ensure it work.
Other than that, I've tested this the associated beats branch and I was able to get the artifacts built. Correctly

@AndersonQ AndersonQ merged commit f2ed3ab into main Mar 23, 2022
@AndersonQ AndersonQ deleted the 26683-agent-arm64 branch March 23, 2022 08:33
AndersonQ added a commit that referenced this pull request Mar 24, 2022
kush-elastic pushed a commit to kush-elastic/beats that referenced this pull request May 2, 2022
* build and packages beats for darwin/arm64. The tar.gz package is called darwin-aarch64

* Osquerybeat: Add darwin/arm64 packaging support (elastic#30935)

Co-authored-by: Aleksandr Maus <[email protected]>
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* build and packages beats for darwin/arm64. The tar.gz package is called darwin-aarch64

* Osquerybeat: Add darwin/arm64 packaging support (#30935)

Co-authored-by: Aleksandr Maus <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Skip notification from the automated backport with mergify enhancement Team:Automation Label for the Observability productivity team Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Beats to compile natively on a Mac M1 machine