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 system.hostfs configuration option for system module #23831

Merged
merged 5 commits into from
Feb 8, 2021

Conversation

ChrsMark
Copy link
Member

@ChrsMark ChrsMark commented Feb 3, 2021

What does this PR do?

This PR adds system.hostfs configuration option for system module.
It will be used instead of the flag -system.hostfs=/hostfs where adding a flag is not possible ie in Agent. Using the -system.hostfs will still be available until we completely remove it in 8.0

Why is it important?

In some cases setting the proc filesystem using the -system.hostfs is not possible like when running with Agent, see #22915. A configuration option should be used instead.

How to test this PR manually

Note: Testing alongside with elastic/integrations#673 is recommended, means that testing the package directly is required for test-plan phase of this PR.

  1. Build Metricbeat: GOOS=linux GOARCH=amd64 go build
  2. Prepare a configuration file vim system.yml:
- module: system
  period: 10s
  metricsets:
    - process
  # Configure the mount point of the host’s filesystem for use in monitoring a host from within a container
  system.hostfs: "/hostfs"
  1. Use the following Dockerfile.debug to build a custom image locally:
FROM docker.elastic.co/beats/metricbeat:7.10.2
COPY metricbeat.yml /usr/share/metricbeat/metricbeat.yml
COPY metricbeat /usr/share/metricbeat/metricbeat
COPY system.yml /usr/share/metricbeat/modules.d/system.yml
USER root
RUN chown root:metricbeat /usr/share/metricbeat/metricbeat.yml
USER metricbeat
  1. Build the image: docker build -f Dockefile.debug . -t metricbeat-hostfs
  2. Run Metricbeat and verify that process metricset collects data:
docker run --mount type=bind,source=/proc,target=/hostfs/proc,readonly --mount type=bind,source=/sys/fs/cgroup,target=/hostfs/sys/fs/cgroup,readonly --mount type=bind,source=/,target=/hostfs,readonly --net=host metricbeat-hostfs -e -d "*" 
  1. Try to break Metricbeat by adding a random hostpath flag: -system.hostfs=/hostfs45

Related issues

cc: @blakerouse

Signed-off-by: chrismark <chrismarkou92@gmail.com>
@ChrsMark ChrsMark self-assigned this Feb 3, 2021
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Feb 3, 2021
@ChrsMark ChrsMark added the Team:Integrations Label for the Integrations team label Feb 3, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Feb 3, 2021
Signed-off-by: chrismark <chrismarkou92@gmail.com>
@elasticmachine
Copy link
Collaborator

elasticmachine commented Feb 3, 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

Expand to view the summary

Build stats

  • Build Cause: Pull request #23831 updated

    • Start Time: 2021-02-05T14:25:39.215+0000
  • Duration: 35 min 55 sec

  • Commit: 582cc3f

Test stats 🧪

Test Results
Failed 0
Passed 8424
Skipped 2116
Total 10540

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 8424
Skipped 2116
Total 10540

config.HostFS = *HostFS
}

return &Module{BaseModule: base, HostFS: config.HostFS, IsAgent: fleetmode.Enabled()}, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

We're probably gonna have to work a little harder to merge the values from the beat config and the CLI. First of all, system_linux.go will need to be changed to grab its value from somewhere else, presumably the merged config. Secondly, we might want to be a little more clear about what value takes precedence, since one value can override another here. Maybe some logic for if *HostFS != "" && config.HostFS != "" { error() } or something like that? Just worried about one implicitly overriding the other.

@@ -26,6 +26,7 @@ import (
)

var (
// TODO: remove this flag in 8.0 since it should be replaced by system.hostfs configuration option (config.HostFS)
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@@ -177,6 +177,9 @@ metricbeat.modules:
period: 10s
processes: ['.*']

# Configure the mount point of the host’s filesystem for use in monitoring a host from within a container
#system.hostfs: "/hostfs"
Copy link
Member

Choose a reason for hiding this comment

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

Have you considered adding this option to all beats as a global setting?

Apart of the system module, other features can benefit of accessing the host fs, as add_docker_metadata, that actually has another setting for this, or the internal metrics, that rely on the global gosigar.Procd to get the pid of the process. gosigar.Procd is modified in Metricbeat by the system module, what can lead to inconsistent behaviour between Beats (Metricbeat managed by an agent in a container can be monitored from the host pid namespace, but other Beats cannot).

An option can be to have explicit settings for each feature (as there is one for the system module and another one for add_docker_metadata) but I wonder if when wanting to override this setting this is not wanted for all features.

In any case, just food for thought, this could be decided later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for commenting @jsoriano ! Your suggestion sounds reasonable and definitely this configuration option could be revisited/refactored.

For now I would avoid adding more complexity on this since this issue is quite blocking for running system module through Agent in containerized environements.

@fearful-symmetry do you think we should create a follow-up issue to file what Jaime suggested?

Signed-off-by: chrismark <chrismarkou92@gmail.com>
Signed-off-by: chrismark <chrismarkou92@gmail.com>
@ChrsMark
Copy link
Member Author

ChrsMark commented Feb 4, 2021

Thanks @fearful-symmetry for the review! I updated the linux subsystem initialisation so as to take into account the configuration option. As far as the check is concerned I don't think we should add a check like if *HostFS != "" && config.HostFS != "" { error() } since I don't see the reason of someone having both set. My thought initially was:

  1. unpack the config with default value of HostFS to empty string.
  2. check if CLI flag is set by checking if !="" and if so replace the configuration field no matter what it had before.

I see CLI flags as more powerful since anyone adding them should know the reason for this. If there is a case of this won't work I'm happy to change it.

Let me know what you think!

@fearful-symmetry
Copy link
Contributor

Changes look good. As far as merging the configs, I think it's fine if we don't throw an error, but I've seen enough weird and crufty container deployments that I think at least printing a little warning message when the CLI overrides the config might be a good idea. I might be overreacting, but it can't hurt.

As far as a further issue to deal with the gosigar stuff, unless it's an immediate need, I'm not sure it's needed. We're planning to do a fairly deep refactor of the system module sometime soon, and we might render a lot of the conversation obsolete.

Signed-off-by: chrismark <chrismarkou92@gmail.com>
@ChrsMark
Copy link
Member Author

ChrsMark commented Feb 5, 2021

@fearful-symmetry I added the warn message. Feel free to have another look.

Also after we merge this we need the corresponding change in system package definition too so as to make it work with Agent, right?

Copy link
Contributor

@fearful-symmetry fearful-symmetry left a comment

Choose a reason for hiding this comment

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

LGTM @jsoriano you're right, the metadata processors are all over the place when it comes to how we're gathering host data. We might want to consider some kind of holdover until we refactor a lot of the metricbeat code.

@ChrsMark ChrsMark merged commit 345a5ca into elastic:master Feb 8, 2021
ChrsMark added a commit to ChrsMark/beats that referenced this pull request Feb 8, 2021
ChrsMark added a commit that referenced this pull request Feb 8, 2021
@ChrsMark ChrsMark added the test-plan Add this PR to be manual test plan label Feb 9, 2021
@andresrc andresrc added the test-plan-added This PR has been added to the test plan label Feb 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement review Team:Integrations Label for the Integrations team test-plan Add this PR to be manual test plan test-plan-added This PR has been added to the test plan v7.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Metricbeat --system.hostfs equivalent to Elastic Agent
5 participants