-
Notifications
You must be signed in to change notification settings - Fork 5k
Refactor use of system.hostfs to fix cgroup metrics #24334
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
Changes from all commits
b9d4097
db6c690
73d40bf
8b27483
3926d66
2ec54cd
bb574b2
624848a
b64eccd
e5348af
b9f10fc
aa5d38d
478c696
2a62f92
d3aacd6
fd7d246
c9acdb9
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 |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ import ( | |
| "github.com/elastic/beats/v7/libbeat/cloudid" | ||
| "github.com/elastic/beats/v7/libbeat/cmd/instance/metrics" | ||
| "github.com/elastic/beats/v7/libbeat/common" | ||
| "github.com/elastic/beats/v7/libbeat/common/cfgwarn" | ||
| "github.com/elastic/beats/v7/libbeat/common/file" | ||
| "github.com/elastic/beats/v7/libbeat/common/reload" | ||
| "github.com/elastic/beats/v7/libbeat/common/seccomp" | ||
|
|
@@ -1083,13 +1084,22 @@ func initPaths(cfg *common.Config) error { | |
| // the paths field. After we will unpack the complete configuration and keystore reference | ||
| // will be correctly replaced. | ||
| partialConfig := struct { | ||
| Path paths.Path `config:"path"` | ||
| Path paths.Path `config:"path"` | ||
| Hostfs string `config:"system.hostfs"` | ||
| }{} | ||
|
|
||
| if paths.IsCLISet() { | ||
| cfgwarn.Deprecate("8.0.0", "This flag will be removed in the future and replaced by a config value.") | ||
| } | ||
|
|
||
| if err := cfg.Unpack(&partialConfig); err != nil { | ||
| return fmt.Errorf("error extracting default paths: %+v", err) | ||
| } | ||
|
|
||
| // Read the value for hostfs as `system.hostfs` | ||
| // In the config, there is no `path.hostfs`, as we're merely using the path struct to carry the hostfs variable. | ||
| partialConfig.Path.Hostfs = partialConfig.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. Is this always safe? By introducing
Contributor
Author
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. Maybe I'm missing something, but is that any different from 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. Paths are configured twice I think. Once via Then the config file is read and the path settings from the configuration file are applied again. The The thing I was wondering: What if If the forced overwrite is on purpose a comment explaining the why would be helpful.
Contributor
Author
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. Okay, so, technically speaking, there is no 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. I see. It is still kinda "obscure" and I'm sure someone (me?, future you?) might change the logic on purpose or by accident. Can you please add a code comment about the why? Having the why in the PR review it will be lost.
Contributor
Author
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. Ah, good point. |
||
|
|
||
| if err := paths.InitPaths(&partialConfig.Path); err != nil { | ||
| return fmt.Errorf("error setting default paths: %+v", err) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,3 +106,20 @@ Example: | |
| ------------------------------------------------------------------------------ | ||
| path.logs: /var/log/beats | ||
| ------------------------------------------------------------------------------ | ||
|
|
||
| [float] | ||
| ==== `system.hostfs` | ||
|
|
||
| Specifies the mount point of the host's filesystem for use in monitoring a host. | ||
| This can either be set in the config, or with the `--system.hostfs` CLI flag. This is used for cgroup self-monitoring. | ||
| ifeval::["{beatname_lc}"=="metricbeat"] | ||
|
Comment on lines
+111
to
+115
Member
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. If this setting is used for other beats too, I think we could add it as |
||
| This is also used by the system module to read files from `/proc` and `/sys`. | ||
| endif::[] | ||
|
|
||
|
|
||
| Example: | ||
|
|
||
| [source,yaml] | ||
| ------------------------------------------------------------------------------ | ||
| path.logs: /var/log/beats | ||
| ------------------------------------------------------------------------------ | ||
|
Comment on lines
+119
to
+125
Member
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. @fearful-symmetry Is this the correct example? It seems to be a duplicate of the
Contributor
Author
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. oops! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,8 @@ | |
| // | ||
| // path.config - Configuration files and Elasticsearch template default location | ||
| // | ||
| // system.hostfs - supplies an alternate filesystem root for containerized environments | ||
|
Member
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. Wdyt about calling it
Contributor
Author
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. Yah, it might be worth it to have a second one for backwards compatibility?
Member
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. Yep, we would keep both at least till 8.0. |
||
| // | ||
| // These settings can be set via the configuration file or via command line flags. | ||
| // The CLI flags overwrite the configuration file options. | ||
| // | ||
|
|
@@ -38,27 +40,45 @@ | |
| package paths | ||
|
|
||
| import ( | ||
| "flag" | ||
| "fmt" | ||
| "os" | ||
| "path/filepath" | ||
| ) | ||
|
|
||
| var ( | ||
| // TODO: remove this flag in 8.0 since it should be replaced by system.hostfs configuration option (config.HostFS) | ||
| // HostFS is an alternate mountpoint for the filesytem root, for when metricbeat is running inside a container. | ||
|
fearful-symmetry marked this conversation as resolved.
|
||
| hostFS = flag.String("system.hostfs", "", "Mount point of the host's filesystem for use in monitoring a host from within a container") | ||
| ) | ||
|
|
||
| // Path tracks user-configurable path locations and directories | ||
| type Path struct { | ||
| Home string | ||
| Config string | ||
| Data string | ||
| Logs string | ||
| Hostfs string | ||
| } | ||
|
|
||
| // FileType is an enumeration type representing the file types. | ||
| // Currently existing file types are: Home, Config, Data | ||
| type FileType string | ||
|
|
||
| const ( | ||
| Home FileType = "home" | ||
| // Home is the "root" directory for the running beats instance | ||
| Home FileType = "home" | ||
| // Config is the path to the beat config | ||
| Config FileType = "config" | ||
| Data FileType = "data" | ||
| Logs FileType = "logs" | ||
| // Data is the path to the beat data directory | ||
| Data FileType = "data" | ||
| // Logs is the path to the beats logs directory | ||
| Logs FileType = "logs" | ||
| // Hostfs is an alternate path to the filesystem root, | ||
| // used for system metrics that interact with procfs and sysfs. | ||
| // Unlike the other values here, this corrisponds to `system.hostfs` | ||
| // and not `path.hostfs`. | ||
| Hostfs FileType = "hostfs" | ||
| ) | ||
|
|
||
| // Paths is the Path singleton on which the top level functions from this | ||
|
|
@@ -115,15 +135,31 @@ func (paths *Path) initPaths(cfg *Path) error { | |
| paths.Logs = filepath.Join(paths.Home, "logs") | ||
| } | ||
|
|
||
| if *hostFS != "" { | ||
| paths.Hostfs = *hostFS | ||
| } | ||
|
|
||
| if paths.Hostfs == "" { | ||
| paths.Hostfs = "/" | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| // IsCLISet returns true if the CLI system.hostfs value has been set | ||
| func IsCLISet() bool { | ||
| if *hostFS != "" { | ||
| return true | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // Resolve resolves a path to a location in one of the default | ||
| // folders. For example, Resolve(Home, "test") returns an absolute | ||
| // path for "test" in the home path. | ||
| func (paths *Path) Resolve(fileType FileType, path string) string { | ||
| // absolute paths are not changed | ||
| if filepath.IsAbs(path) { | ||
| // absolute paths are not changed for non-hostfs file types, since hostfs is a little odd | ||
| if filepath.IsAbs(path) && fileType != Hostfs { | ||
| return path | ||
| } | ||
|
|
||
|
|
@@ -136,6 +172,8 @@ func (paths *Path) Resolve(fileType FileType, path string) string { | |
| return filepath.Join(paths.Data, path) | ||
| case Logs: | ||
| return filepath.Join(paths.Logs, path) | ||
| case Hostfs: | ||
| return filepath.Join(paths.Hostfs, path) | ||
| default: | ||
| panic(fmt.Sprintf("Unknown file type: %s", fileType)) | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.