-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Changes from all commits
0b5b5b3
dbb9ce3
bc104de
f30c810
582cc3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,10 +22,12 @@ import ( | |
"sync" | ||
|
||
"github.com/elastic/beats/v7/libbeat/common/fleetmode" | ||
"github.com/elastic/beats/v7/libbeat/logp" | ||
"github.com/elastic/beats/v7/metricbeat/mb" | ||
) | ||
|
||
var ( | ||
// TODO: remove this flag in 8.0 since it should be replaced by system.hostfs configuration option (config.HostFS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
// HostFS is an alternate mountpoint for the filesytem root, for when metricbeat is running inside a container. | ||
HostFS = flag.String("system.hostfs", "", "mountpoint of the host's filesystem for use in monitoring a host from within a container") | ||
) | ||
|
@@ -39,6 +41,11 @@ func init() { | |
} | ||
} | ||
|
||
// Config for the system module. | ||
type Config struct { | ||
HostFS string `config:"system.hostfs"` // Specifies the mount point of the host’s filesystem for use in monitoring a host from within a container. | ||
} | ||
|
||
// Module represents the system module | ||
type Module struct { | ||
mb.BaseModule | ||
|
@@ -48,10 +55,25 @@ type Module struct { | |
|
||
// NewModule instatiates the system module | ||
func NewModule(base mb.BaseModule) (mb.Module, error) { | ||
|
||
config := Config{ | ||
HostFS: "", | ||
} | ||
err := base.UnpackConfig(&config) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if *HostFS != "" { | ||
if config.HostFS != "" { | ||
logp.Warn("-system.hostfs flag is set and will override configuration setting") | ||
} | ||
config.HostFS = *HostFS | ||
} | ||
|
||
// This only needs to be configured once for all system modules. | ||
once.Do(func() { | ||
initModule() | ||
initModule(config) | ||
}) | ||
|
||
return &Module{BaseModule: base, HostFS: *HostFS, IsAgent: fleetmode.Enabled()}, nil | ||
return &Module{BaseModule: base, HostFS: config.HostFS, IsAgent: fleetmode.Enabled()}, nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,6 @@ | |
|
||
package system | ||
|
||
func initModule() { | ||
func initModule(config Config) { | ||
// Stub method for non-linux. | ||
} |
There was a problem hiding this comment.
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 globalgosigar.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.
There was a problem hiding this comment.
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?