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

Cherry-pick #24817 to 7.x: [Elastic Agent] Fix Docker container to allow state to properly be handled #24879

Merged
merged 1 commit into from
Mar 31, 2021

Conversation

blakerouse
Copy link
Contributor

@blakerouse blakerouse commented Mar 31, 2021

Cherry-pick of PR #24817 to 7.x branch. Original message:

What does this PR do?

This fixes the Elastic Agent Docker image to allow a proper state to be stored for the image. Previously this was not possible for the state to be placed into a volume which prevent restarts of the container to maintain its previous state.

This changes the Elastic Agent to not version its directory when running under Docker. This is key to allowing the state to be storable and being that an Elastic Agent container cannot be self-upgraded it is acceptable that it is not versioned.

Because of how the Elastic Agent ships with the builds in the download directory the state could not mount over that directory of Elastic Agent would need to re-download those files. This changes the container sub-command to rsync the builds download directory into the state directory before actually running. This allows new downloads to stay in the state directory and allows the running Elastic Agent to use the binaries that shipped with the image.

By default the state of the Docker container goes to /usr/share/elastic-agent/state. This can changed with STATE_PATH environment. Elastic Agent logs now default to output stderr so they can be collected by the container runtime. In the case that LOGS_PATH variable is set then the Elastic Agent will log to $LOGS_PATH/elastic-agent.log instead of stderr.

Other fixes include using the $STATE_PATH/data/tmp instead of /tmp for the unix sockets as the container cannot write to /tmp.

Why is it important?

Critical to allow the state of the Elastic Agent to persist restarts of the Elastic Agent Docker image.

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

  • State is stored in /usr/share/elastic-agent/state.
  • State path can be changed with STATE_PATH.

How to test this PR locally

$ # Build the docker container in dev-mode
$ cd x-pack/elastic-agent
$ PLATFORMS="+all linux/amd64" mage dev:package
$ # Run the docker container
$ docker run -it -e KIBANA_FLEET_SETUP=1 -e ELASTICSEARCH_HOST=http://host.docker.internal:9200 -e KIBANA_HOST=http://host.docker.internal:5601 -e FLEET_ENROLL=1 -e FLEET_URL=http://host.docker.internal:8220 -e FLEET_INSECURE=1 docker.elastic.co/beats/elastic-agent:8.0.0

Related issues

…ndled (elastic#24817)

* Adjust paths to allow setting data path when running in container mode.

* Fix ability for elastic-agent to have proper state in Docker.

* Add changelog entry.

* Fix lint.

* Fix issue with bootstrapping with Fleet Server.

* Fix lint.

* additional fixes

* unify ENV for home, logs, config, data
* add CONFIG_PATH
* set paths and copy downloads before extracting APM Server
* restrict path config to ENV

* Cleanup some issues with cloud mode.

* Fix issue with CONFIG_PATH when empty. Improve sub-process agent in enroll to exit when Elastic Agent crashes.

* Cleanup the paths to be correct.

* Update changelog.

* Fix unit tests.

Co-authored-by: simitt <[email protected]>
(cherry picked from commit 1f1fae5)
@elasticmachine
Copy link
Collaborator

Pinging @elastic/agent (Team:Agent)

@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 Mar 31, 2021
@elasticmachine
Copy link
Collaborator

💚 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

Expand to view the summary

Build stats

  • Build Cause: Pull request #24879 opened

  • Start Time: 2021-03-31T20:14:24.474+0000

  • Duration: 57 min 26 sec

  • Commit: ea7ef3c

Test stats 🧪

Test Results
Failed 0
Passed 6532
Skipped 24
Total 6556

Trends 🧪

Image of Build Times

Image of Tests

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 6532
Skipped 24
Total 6556

@blakerouse blakerouse merged commit 99640fd into elastic:7.x Mar 31, 2021
@blakerouse blakerouse deleted the backport_24817_7.x branch March 31, 2021 21:12
@zube zube bot removed the [zube]: Done label Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants