Skip to content

Commit

Permalink
feat(comp/cadvisor): allow user to disable collecting root Cgroup stats
Browse files Browse the repository at this point in the history
Signed-off-by: hainenber <[email protected]>
  • Loading branch information
hainenber committed Nov 4, 2023
1 parent ffccd0a commit 24a6b28
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion component/prometheus/exporter/cadvisor/cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ var DefaultArguments = Arguments{
DockerTLSKey: "key.pem",
DockerTLSCA: "ca.pem",

DockerOnly: false,
DockerOnly: false,
DisableRootCgroupStats: false,
}

// Arguments configures the prometheus.exporter.cadvisor component.
Expand All @@ -66,6 +67,7 @@ type Arguments struct {
DockerTLSKey string `river:"docker_tls_key,attr,optional"`
DockerTLSCA string `river:"docker_tls_ca,attr,optional"`
DockerOnly bool `river:"docker_only,attr,optional"`
DisableRootCgroupStats bool `river:"disable_root_cgroup_stats,attr,optional"`
}

// SetToDefault implements river.Defaulter.
Expand Down Expand Up @@ -103,6 +105,7 @@ func (a *Arguments) Convert() *cadvisor.Config {
DockerTLSKey: a.DockerTLSKey,
DockerTLSCA: a.DockerTLSCA,
DockerOnly: a.DockerOnly,
DisableRootCgroupStats: a.DisableRootCgroupStats,
}

return cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ func toCadvisorExporter(config *cadvisor_integration.Config) *cadvisor.Arguments
DockerTLSKey: config.DockerTLSKey,
DockerTLSCA: config.DockerTLSCA,
DockerOnly: config.DockerOnly,
DisableRootCgroupStats: config.DisableRootCgroupStats,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Name | Type | Description | Default | Required
`docker_tls_key` | `string` | Path to private key for TLS connection to docker. | `key.pem` | no
`docker_tls_ca` | `string` | Path to a trusted CA for TLS connection to docker. | `ca.pem` | no
`docker_only` | `bool` | Only report docker containers in addition to root stats. | `false` | no
`disable_root_cgroup_stats` | `bool` | Disable collecting root Cgroup stats. | `false` | no

For `allowlisted_container_labels` to take effect, `store_container_labels` must be set to `false`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,7 @@ Full reference of options:

# Only report docker containers in addition to root stats
[docker_only: <boolean> | default = false]

# Disable collecting root Cgroup stats
[disable_root_cgroup_stats: <boolean> | default = false]
```
3 changes: 2 additions & 1 deletion pkg/integrations/cadvisor/cadvisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ func New(logger log.Logger, c *Config) (integrations.Integration, error) {
}

rawOpts := raw.Options{
DockerOnly: c.DockerOnly,
DockerOnly: c.DockerOnly,
DisableRootCgroupStats: c.DisableRootCgroupStats,
}
rm, err := manager.New(plugins, memoryStorage, sysFs, manager.HousekeepingConfigFlags, includedMetrics, &collectorHTTPClient, c.RawCgroupPrefixAllowlist, c.EnvMetadataAllowlist, c.PerfEventsConfig, time.Duration(c.ResctrlInterval), rawOpts)
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/integrations/cadvisor/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ var DefaultConfig = Config{

// Raw config defaults
DockerOnly: false,

DisableRootCgroupStats: false,
}

// Config controls cadvisor
Expand Down Expand Up @@ -91,6 +93,9 @@ type Config struct {
// DockerOnly only report docker containers in addition to root stats
DockerOnly bool `yaml:"docker_only,omitempty"`

// DisableRootCgroupStats informs the exporter not collecting stats from the root cgroup.
DisableRootCgroupStats bool `yaml:"disable_root_cgroup_stats,omitempty"`

// Hold on to the logger passed to config.NewIntegration, to be passed to klog, as yet another unsafe global that needs to be set.
logger log.Logger //nolint:unused,structcheck // logger is only used on linux
}
Expand Down

0 comments on commit 24a6b28

Please sign in to comment.