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 a test framework for monitoring the host system from inside a container #140

Merged
merged 19 commits into from
Apr 18, 2024

Conversation

fearful-symmetry
Copy link
Contributor

@fearful-symmetry fearful-symmetry commented Apr 11, 2024

What does this PR do?

Closes elastic/beats#38241

This adds a lightweight test framework that runs a set of system tests under a container with the goal of monitoring the host system. The goal with these tests is to catch the numerous edge cases that happen when the system metrics function from a /hostfs path inside a container.

The tests have a fairly large matrix of configurations, as we need to test both a wide variety of container permission settings, as well as differences in how linux distros will configure cgroups.

The framework here was designed with the goal of being relatively idiomatic; you can just run the framework with go test as you would normally.

You can run the tests yourself with go test -v ./tests

As you may have noticed, there's a non-zero amount of TODO statements here, since these tests were built to aggravate a bunch of existing bugs, so certain parts of the tests will remain un-implemented until those bugs are fixed.

Why is it important?

See elastic/beats#38241, we really need test for this particular case.

List of bugs that are responsible for TODO statements in the tests:

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.md

@fearful-symmetry fearful-symmetry added the Team:Elastic-Agent Label for the Agent team label Apr 11, 2024
@fearful-symmetry fearful-symmetry self-assigned this Apr 11, 2024
@fearful-symmetry fearful-symmetry requested a review from a team as a code owner April 11, 2024 15:54
@fearful-symmetry fearful-symmetry requested review from ycombinator and belimawr and removed request for a team April 11, 2024 15:54
@fearful-symmetry fearful-symmetry changed the title Add a test framework for testing system code monitoring the host system from inside docker Add a test framework for monitoring the host system from inside a container Apr 11, 2024
Comment on lines +9 to +14
# install docker

# DOCKER_VERSION="25.0"

# curl -fsSL https://get.docker.com -o get-docker.sh
# sudo sh ./get-docker.sh --version $DOCKER_VERSION
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to keep those here?

Was it left over from development or is it likely to be needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Depending on how creative I get with the buildkite images later, I might need it, so I'm leaving it in

dev-tools/systemtests/container.go Outdated Show resolved Hide resolved
dev-tools/systemtests/container.go Outdated Show resolved Hide resolved
dev-tools/systemtests/container.go Outdated Show resolved Hide resolved
metric/system/process/process.go Outdated Show resolved Hide resolved
Copy link
Contributor

@faec faec 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!

@fearful-symmetry fearful-symmetry merged commit 8fa575b into elastic:main Apr 18, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team:Elastic-Agent Label for the Agent team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

We need tests to cover host metric monitoring on docker
4 participants