Skip to content

Commit 6e9fbc2

Browse files
committed
add nodeExporter.collectors.netdev settings.
1 parent b225152 commit 6e9fbc2

File tree

10 files changed

+164
-4
lines changed

10 files changed

+164
-4
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- [#1855](https://github.com/openshift/cluster-monitoring-operator/pull/1855) Add nodeExporter.collectors.cpufreq settings.
1010
- [#1882](https://github.com/openshift/cluster-monitoring-operator/issues/1882) Allow configuring secrets in alertmanager component (platform)
1111
- [#1876](https://github.com/openshift/cluster-monitoring-operator/pull/1876) Add nodeExporter.collectors.tcpstat settings.
12+
- [#1888](https://github.com/openshift/cluster-monitoring-operator/pull/1888) Add nodeExporter.collectors.netdev settings.
1213

1314

1415
## 4.12

Documentation/api.md

+17
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ Configuring Cluster Monitoring is optional. If the config does not exist or is e
2727
* [KubeStateMetricsConfig](#kubestatemetricsconfig)
2828
* [NodeExporterCollectorConfig](#nodeexportercollectorconfig)
2929
* [NodeExporterCollectorCpufreqConfig](#nodeexportercollectorcpufreqconfig)
30+
* [NodeExporterCollectorNetDevConfig](#nodeexportercollectornetdevconfig)
3031
* [NodeExporterCollectorTcpStatConfig](#nodeexportercollectortcpstatconfig)
3132
* [NodeExporterConfig](#nodeexporterconfig)
3233
* [OpenShiftStateMetricsConfig](#openshiftstatemetricsconfig)
@@ -190,6 +191,7 @@ The `NodeExporterCollectorConfig` resource defines settings for individual colle
190191
| -------- | ---- | ----------- |
191192
| cpufreq | [NodeExporterCollectorCpufreqConfig](#nodeexportercollectorcpufreqconfig) | Defines the configuration of the `cpufreq` collector, which collects CPU frequency statistics. Disabled by default. |
192193
| tcpstat | [NodeExporterCollectorTcpStatConfig](#nodeexportercollectortcpstatconfig) | Defines the configuration of the `tcpstat` collector, which collects TCP connection statistics. Disabled by default. |
194+
| netdev | [NodeExporterCollectorNetDevConfig](#nodeexportercollectornetdevconfig) | Defines the configuration of the `netdev` collector, which collects network devices statistics. Enabled by default. |
193195

194196
[Back to TOC](#table-of-contents)
195197

@@ -208,6 +210,21 @@ The `NodeExporterCollectorCpufreqConfig` resource works as an on/off switch for
208210

209211
[Back to TOC](#table-of-contents)
210212

213+
## NodeExporterCollectorNetDevConfig
214+
215+
#### Description
216+
217+
The `NodeExporterCollectorNetDevConfig` resource works as an on/off switch for the `netdev` collector of the `node-exporter` agent. By default, the `netdev` collector is enabled. If disabled, these metrics become unavailable: `node_network_receive_bytes_total`, `node_network_receive_compressed_total`, `node_network_receive_drop_total`, `node_network_receive_errs_total`, `node_network_receive_fifo_total`, `node_network_receive_frame_total`, `node_network_receive_multicast_total`, `node_network_receive_nohandler_total`, `node_network_receive_packets_total`, `node_network_transmit_bytes_total`, `node_network_transmit_carrier_total`, `node_network_transmit_colls_total`, `node_network_transmit_compressed_total`, `node_network_transmit_drop_total`, `node_network_transmit_errs_total`, `node_network_transmit_fifo_total`, `node_network_transmit_packets_total`.
218+
219+
220+
<em>appears in: [NodeExporterCollectorConfig](#nodeexportercollectorconfig)</em>
221+
222+
| Property | Type | Description |
223+
| -------- | ---- | ----------- |
224+
| enabled | bool | A Boolean flag that enables or disables the `netdev` collector. |
225+
226+
[Back to TOC](#table-of-contents)
227+
211228
## NodeExporterCollectorTcpStatConfig
212229

213230
#### Description

Documentation/openshiftdocs/index.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ The configuration file itself is always defined under the `config.yaml` key in t
4747
* link:modules/kubestatemetricsconfig.adoc[KubeStateMetricsConfig]
4848
* link:modules/nodeexportercollectorconfig.adoc[NodeExporterCollectorConfig]
4949
* link:modules/nodeexportercollectorcpufreqconfig.adoc[NodeExporterCollectorCpufreqConfig]
50+
* link:modules/nodeexportercollectornetdevconfig.adoc[NodeExporterCollectorNetDevConfig]
5051
* link:modules/nodeexportercollectortcpstatconfig.adoc[NodeExporterCollectorTcpStatConfig]
5152
* link:modules/nodeexporterconfig.adoc[NodeExporterConfig]
5253
* link:modules/openshiftstatemetricsconfig.adoc[OpenShiftStateMetricsConfig]

Documentation/openshiftdocs/modules/nodeexportercollectorconfig.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Appears in: link:nodeexporterconfig.adoc[NodeExporterConfig]
2222

2323
|tcpstat|link:nodeexportercollectortcpstatconfig.adoc[NodeExporterCollectorTcpStatConfig]|Defines the configuration of the `tcpstat` collector, which collects TCP connection statistics. Disabled by default.
2424

25+
|netdev|link:nodeexportercollectornetdevconfig.adoc[NodeExporterCollectorNetDevConfig]|Defines the configuration of the `netdev` collector, which collects network devices statistics. Enabled by default.
26+
2527
|===
2628

2729
link:../index.adoc[Back to TOC]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// DO NOT EDIT THE CONTENT IN THIS FILE. It is automatically generated from the
2+
// source code for the Cluster Monitoring Operator. Any changes made to this
3+
// file will be overwritten when the content is re-generated. If you wish to
4+
// make edits, read the docgen utility instructions in the source code for the
5+
// CMO.
6+
:_content-type: ASSEMBLY
7+
8+
== NodeExporterCollectorNetDevConfig
9+
10+
=== Description
11+
12+
The `NodeExporterCollectorNetDevConfig` resource works as an on/off switch for the `netdev` collector of the `node-exporter` agent. By default, the `netdev` collector is enabled. If disabled, these metrics become unavailable: `node_network_receive_bytes_total`, `node_network_receive_compressed_total`, `node_network_receive_drop_total`, `node_network_receive_errs_total`, `node_network_receive_fifo_total`, `node_network_receive_frame_total`, `node_network_receive_multicast_total`, `node_network_receive_nohandler_total`, `node_network_receive_packets_total`, `node_network_transmit_bytes_total`, `node_network_transmit_carrier_total`, `node_network_transmit_colls_total`, `node_network_transmit_compressed_total`, `node_network_transmit_drop_total`, `node_network_transmit_errs_total`, `node_network_transmit_fifo_total`, `node_network_transmit_packets_total`.
13+
14+
15+
16+
Appears in: link:nodeexportercollectorconfig.adoc[NodeExporterCollectorConfig]
17+
18+
[options="header"]
19+
|===
20+
| Property | Type | Description
21+
|enabled|bool|A Boolean flag that enables or disables the `netdev` collector.
22+
23+
|===
24+
25+
link:../index.adoc[Back to TOC]

pkg/manifests/config.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func (cfg *TelemeterClientConfig) IsEnabled() bool {
188188

189189
func NewConfig(content io.Reader) (*Config, error) {
190190
c := Config{}
191-
cmc := ClusterMonitoringConfiguration{}
191+
cmc := defaultClusterMonitoringConfiguration()
192192
err := k8syaml.NewYAMLOrJSONDecoder(content, 4096).Decode(&cmc)
193193
if err != nil {
194194
return nil, err
@@ -200,6 +200,18 @@ func NewConfig(content io.Reader) (*Config, error) {
200200
return res, nil
201201
}
202202

203+
func defaultClusterMonitoringConfiguration() ClusterMonitoringConfiguration {
204+
return ClusterMonitoringConfiguration{
205+
NodeExporterConfig: NodeExporterConfig{
206+
Collectors: NodeExporterCollectorConfig{
207+
NetDev: NodeExporterCollectorNetDevConfig{
208+
Enabled: true,
209+
},
210+
},
211+
},
212+
}
213+
}
214+
203215
func (c *Config) applyDefaults() {
204216
if c.Images == nil {
205217
c.Images = &Images{}
@@ -392,7 +404,7 @@ func NewConfigFromString(content string) (*Config, error) {
392404

393405
func NewDefaultConfig() *Config {
394406
c := &Config{}
395-
cmc := ClusterMonitoringConfiguration{}
407+
cmc := defaultClusterMonitoringConfiguration()
396408
c.ClusterMonitoringConfiguration = &cmc
397409
c.UserWorkloadConfiguration = NewDefaultUserWorkloadMonitoringConfig()
398410
c.applyDefaults()

pkg/manifests/manifests.go

+7
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,13 @@ func (f *Factory) updateNodeExporterArgs(args []string) []string {
815815
} else {
816816
args = setArg(args, "--no-collector.tcpstat", "")
817817
}
818+
819+
if f.config.ClusterMonitoringConfiguration.NodeExporterConfig.Collectors.NetDev.Enabled {
820+
args = setArg(args, "--collector.netdev", "")
821+
} else {
822+
args = setArg(args, "--no-collector.netdev", "")
823+
}
824+
818825
return args
819826
}
820827

pkg/manifests/manifests_test.go

+17-2
Original file line numberDiff line numberDiff line change
@@ -2835,9 +2835,13 @@ func TestNodeExporterCollectorSettings(t *testing.T) {
28352835
name: "default config",
28362836
config: "",
28372837
argsPresent: []string{"--no-collector.cpufreq",
2838-
"--no-collector.tcpstat"},
2838+
"--no-collector.tcpstat",
2839+
"--collector.netdev",
2840+
},
28392841
argsAbsent: []string{"--collector.cpufreq",
2840-
"--collector.tcpstat"},
2842+
"--collector.tcpstat",
2843+
"--no-collector.netdev",
2844+
},
28412845
},
28422846
{
28432847
name: "enable cpufreq collector",
@@ -2861,6 +2865,17 @@ nodeExporter:
28612865
argsPresent: []string{"--collector.tcpstat"},
28622866
argsAbsent: []string{"--no-collector.tcpstat"},
28632867
},
2868+
{
2869+
name: "disable netdev collector",
2870+
config: `
2871+
nodeExporter:
2872+
collectors:
2873+
netdev:
2874+
enabled: false
2875+
`,
2876+
argsPresent: []string{"--no-collector.netdev"},
2877+
argsAbsent: []string{"--collector.netdev"},
2878+
},
28642879
}
28652880

28662881
for _, test := range tests {

pkg/manifests/types.go

+29
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,9 @@ type NodeExporterCollectorConfig struct {
264264
// Defines the configuration of the `tcpstat` collector, which collects TCP connection statistics.
265265
// Disabled by default.
266266
TcpStat NodeExporterCollectorTcpStatConfig `json:"tcpstat,omitempty"`
267+
// Defines the configuration of the `netdev` collector, which collects network devices statistics.
268+
// Enabled by default.
269+
NetDev NodeExporterCollectorNetDevConfig `json:"netdev,omitempty"`
267270
}
268271

269272
// The `NodeExporterCollectorCpufreqConfig` resource works as an on/off switch for
@@ -286,6 +289,32 @@ type NodeExporterCollectorTcpStatConfig struct {
286289
Enabled bool `json:"enabled,omitempty"`
287290
}
288291

292+
// The `NodeExporterCollectorNetDevConfig` resource works as an on/off switch for
293+
// the `netdev` collector of the `node-exporter` agent.
294+
// By default, the `netdev` collector is enabled.
295+
// If disabled, these metrics become unavailable:
296+
// `node_network_receive_bytes_total`,
297+
// `node_network_receive_compressed_total`,
298+
// `node_network_receive_drop_total`,
299+
// `node_network_receive_errs_total`,
300+
// `node_network_receive_fifo_total`,
301+
// `node_network_receive_frame_total`,
302+
// `node_network_receive_multicast_total`,
303+
// `node_network_receive_nohandler_total`,
304+
// `node_network_receive_packets_total`,
305+
// `node_network_transmit_bytes_total`,
306+
// `node_network_transmit_carrier_total`,
307+
// `node_network_transmit_colls_total`,
308+
// `node_network_transmit_compressed_total`,
309+
// `node_network_transmit_drop_total`,
310+
// `node_network_transmit_errs_total`,
311+
// `node_network_transmit_fifo_total`,
312+
// `node_network_transmit_packets_total`.
313+
type NodeExporterCollectorNetDevConfig struct {
314+
// A Boolean flag that enables or disables the `netdev` collector.
315+
Enabled bool `json:"enabled,omitempty"`
316+
}
317+
289318
// The `UserWorkloadConfiguration` resource defines the settings
290319
// responsible for user-defined projects in the
291320
// `user-workload-monitoring-config` config map in the

test/e2e/node_exporter_test.go

+51
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,54 @@ nodeExporter:
8383
}
8484

8585
}
86+
87+
func TestNodeExporterCollectorDisablement(t *testing.T) {
88+
t.Cleanup(func() {
89+
f.MustDeleteConfigMap(t, &corev1.ConfigMap{
90+
ObjectMeta: metav1.ObjectMeta{
91+
Name: clusterMonitorConfigMapName,
92+
Namespace: f.Ns,
93+
},
94+
})
95+
})
96+
97+
tests := []struct {
98+
nameCollector string
99+
config string
100+
}{
101+
{
102+
nameCollector: "netdev",
103+
config: `
104+
nodeExporter:
105+
collectors:
106+
netdev:
107+
enabled: false`,
108+
},
109+
}
110+
111+
for _, test := range tests {
112+
t.Run("Disable Collector: "+test.nameCollector, func(st *testing.T) {
113+
f.PrometheusK8sClient.WaitForQueryReturn(
114+
t, 5*time.Minute, fmt.Sprintf(`min(node_scrape_collector_success{collector="%s"})`, test.nameCollector),
115+
func(v float64) error {
116+
if v == 1 {
117+
return nil
118+
}
119+
return fmt.Errorf(`expecting min(node_scrape_collector_success{collector="%s"}) = 1 but got %v.`, test.nameCollector, v)
120+
},
121+
)
122+
123+
f.MustCreateOrUpdateConfigMap(t, configMapWithData(t, test.config))
124+
125+
f.PrometheusK8sClient.WaitForQueryReturn(
126+
t, 5*time.Minute, fmt.Sprintf(`absent_over_time(node_scrape_collector_success{collector="%s"}[1m])`, test.nameCollector),
127+
func(v float64) error {
128+
if v == 0 {
129+
return fmt.Errorf(`expecting absent_over_time(node_scrape_collector_success{collector="%s"}[1m])> 0 but got %v.`, test.nameCollector, v)
130+
}
131+
return nil
132+
},
133+
)
134+
})
135+
}
136+
}

0 commit comments

Comments
 (0)