From b097057a22929487858e7f2dbdbee9af840383dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BB=97=20Tr=E1=BB=8Dng=20H=E1=BA=A3i?= <41283691+hainenber@users.noreply.github.com> Date: Thu, 23 Nov 2023 22:54:30 +0700 Subject: [PATCH] feat(comp/cadvisor): allow user to disable collecting root Cgroup stats (#5713) Signed-off-by: hainenber --- CHANGELOG.md | 6 +++++- component/prometheus/exporter/cadvisor/cadvisor.go | 5 ++++- .../staticconvert/internal/build/cadvisor_exporter.go | 1 + .../reference/components/prometheus.exporter.cadvisor.md | 1 + .../static/configuration/integrations/cadvisor-config.md | 3 +++ go.mod | 2 +- go.sum | 4 ++-- pkg/integrations/cadvisor/cadvisor.go | 3 ++- pkg/integrations/cadvisor/common.go | 5 +++++ 9 files changed, 24 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e12f420fccf6..3fe92de24606 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,9 +17,13 @@ Main (unreleased) - Agent Management: Introduce support for templated configuration. (@jcreixell) ### Enhancements - + - Flow Windows service: Support environment variables. (@jkroepke) +- Allow disabling collection of root Cgroup stats in + `prometheus.exporter.cadvisor` (flow mode) and the `cadvisor` integration + (static mode). (@hainenber) + ### Bugfixes - Permit `X-Faro-Session-ID` header in CORS requests for the `faro.receiver` diff --git a/component/prometheus/exporter/cadvisor/cadvisor.go b/component/prometheus/exporter/cadvisor/cadvisor.go index 79542dbf0087..14e60493930e 100644 --- a/component/prometheus/exporter/cadvisor/cadvisor.go +++ b/component/prometheus/exporter/cadvisor/cadvisor.go @@ -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. @@ -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. @@ -103,6 +105,7 @@ func (a *Arguments) Convert() *cadvisor.Config { DockerTLSKey: a.DockerTLSKey, DockerTLSCA: a.DockerTLSCA, DockerOnly: a.DockerOnly, + DisableRootCgroupStats: a.DisableRootCgroupStats, } return cfg diff --git a/converter/internal/staticconvert/internal/build/cadvisor_exporter.go b/converter/internal/staticconvert/internal/build/cadvisor_exporter.go index dbedebfb2967..0c6445c5376f 100644 --- a/converter/internal/staticconvert/internal/build/cadvisor_exporter.go +++ b/converter/internal/staticconvert/internal/build/cadvisor_exporter.go @@ -33,5 +33,6 @@ func toCadvisorExporter(config *cadvisor_integration.Config) *cadvisor.Arguments DockerTLSKey: config.DockerTLSKey, DockerTLSCA: config.DockerTLSCA, DockerOnly: config.DockerOnly, + DisableRootCgroupStats: config.DisableRootCgroupStats, } } diff --git a/docs/sources/flow/reference/components/prometheus.exporter.cadvisor.md b/docs/sources/flow/reference/components/prometheus.exporter.cadvisor.md index 567783c38702..845a0fe0adec 100644 --- a/docs/sources/flow/reference/components/prometheus.exporter.cadvisor.md +++ b/docs/sources/flow/reference/components/prometheus.exporter.cadvisor.md @@ -43,6 +43,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`. diff --git a/docs/sources/static/configuration/integrations/cadvisor-config.md b/docs/sources/static/configuration/integrations/cadvisor-config.md index 16dedf0a5205..adf92dcff827 100644 --- a/docs/sources/static/configuration/integrations/cadvisor-config.md +++ b/docs/sources/static/configuration/integrations/cadvisor-config.md @@ -115,4 +115,7 @@ Full reference of options: # Only report docker containers in addition to root stats [docker_only: | default = false] + + # Disable collecting root Cgroup stats + [disable_root_cgroup_stats: | default = false] ``` diff --git a/go.mod b/go.mod index 891de83235af..9362ef24beb5 100644 --- a/go.mod +++ b/go.mod @@ -695,7 +695,7 @@ replace ( // TODO(tpaschalis) this is to remove global instantiation of plugins // and allow non-singleton components. // https://github.com/grafana/cadvisor/tree/grafana-v0.47-noglobals - github.com/google/cadvisor => github.com/grafana/cadvisor v0.0.0-20230927082732-0d72868a513e + github.com/google/cadvisor => github.com/grafana/cadvisor v0.0.0-20231110094609-5f7917925dea // TODO(mattdurham): this is so you can debug on windows, when PR is merged into perflib, can you use that // and eventually remove if windows_exporter shifts to it. https://github.com/leoluk/perflib_exporter/pull/43 diff --git a/go.sum b/go.sum index 0384745ab682..3678215219aa 100644 --- a/go.sum +++ b/go.sum @@ -1038,8 +1038,8 @@ github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/ad github.com/gosnmp/gosnmp v1.36.0 h1:1Si+MImHcKIqFc3/kJEs2LOULP1nlFKlzPFyrMOk5Qk= github.com/gosnmp/gosnmp v1.36.0/go.mod h1:iLcZxN2MxKhH0jPQDVMZaSNypw1ykqVi27O79koQj6w= github.com/gotestyourself/gotestyourself v2.2.0+incompatible/go.mod h1:zZKM6oeNM8k+FRljX1mnzVYeS8wiGgQyvST1/GafPbY= -github.com/grafana/cadvisor v0.0.0-20230927082732-0d72868a513e h1:hCYDh2cmnNFAjwcMlrSuptDZqjXUc3he4h61/xL/ANY= -github.com/grafana/cadvisor v0.0.0-20230927082732-0d72868a513e/go.mod h1:XjiOCFjmxXIWwauV5p39Mr2Yxlpyk72uKQH1UZvd4fQ= +github.com/grafana/cadvisor v0.0.0-20231110094609-5f7917925dea h1:Q5f5/nJJ0SbusZjA6F6XkJuHDbl2/PqdTGw6wHsuccA= +github.com/grafana/cadvisor v0.0.0-20231110094609-5f7917925dea/go.mod h1:XjiOCFjmxXIWwauV5p39Mr2Yxlpyk72uKQH1UZvd4fQ= github.com/grafana/ckit v0.0.0-20230906125525-c046c99a5c04 h1:tG8Qxq4dN1WqakMmsPaxaH4+OQhYg5HVsarw5acLBX8= github.com/grafana/ckit v0.0.0-20230906125525-c046c99a5c04/go.mod h1:HOnDIbkxfvVlDM5FBujt0uawGLfdpdTeqE7fIwfBmQk= github.com/grafana/cloudflare-go v0.0.0-20230110200409-c627cf6792f2 h1:qhugDMdQ4Vp68H0tp/0iN17DM2ehRo1rLEdOFe/gB8I= diff --git a/pkg/integrations/cadvisor/cadvisor.go b/pkg/integrations/cadvisor/cadvisor.go index b0c854e692de..cfe8380eb3b6 100644 --- a/pkg/integrations/cadvisor/cadvisor.go +++ b/pkg/integrations/cadvisor/cadvisor.go @@ -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 { diff --git a/pkg/integrations/cadvisor/common.go b/pkg/integrations/cadvisor/common.go index 1ff7bc658f1b..0ce16d6c4907 100644 --- a/pkg/integrations/cadvisor/common.go +++ b/pkg/integrations/cadvisor/common.go @@ -32,6 +32,8 @@ var DefaultConfig = Config{ // Raw config defaults DockerOnly: false, + + DisableRootCgroupStats: false, } // Config controls cadvisor @@ -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 }