@cryptotaxi247 / netdata-1 / commits / d9cc0b7f3

improvement(go.d/docker): respect ignore label (#19341)

Ilya Mashchenko committed Jan 7, 2025 at 21:17 UTC d9cc0b7f30df7635f87ab3f5ee968e30e7ddf0cb
2 files changed +14 -2
src/go/plugin/go.d/collector/docker/collect.go
+9
@@ -148,6 +148,10 @@ func (c *Collector) collectContainers(mx map[string]int64) error {
148 }
149 }
150
151 + if hasIgnoreLabel(cntr) {
152 + continue
153 + }
154 +
155 if len(cntr.Names) == 0 {
156 continue
157 }
@@ -202,3 +206,8 @@ func (c *Collector) negotiateAPIVersion() {
206
207 c.client.NegotiateAPIVersion(ctx)
208 }
209 +
210 +func hasIgnoreLabel(cntr types.Container) bool {
211 + v, _ := cntr.Labels["netdata.cloud/ignore"]
212 + return strings.EqualFold(v, "true") || strings.EqualFold(v, "yes")
213 +}
src/go/plugin/go.d/collector/docker/collector_test.go
+5 -2
@@ -404,7 +404,7 @@ func TestCollector_Collect(t *testing.T) {
404 "container_container9_state_restarting": 0,
405 "container_container9_state_running": 0,
406 "containers_health_status_healthy": 3,
407 - "containers_health_status_none": 3,
407 + "containers_health_status_none": 4,
408 "containers_health_status_not_running_unhealthy": 6,
409 "containers_health_status_starting": 3,
410 "containers_health_status_unhealthy": 1,
@@ -644,7 +644,7 @@ func TestCollector_Collect(t *testing.T) {
644 "container_container9_state_restarting": 0,
645 "container_container9_state_running": 0,
646 "containers_health_status_healthy": 3,
647 - "containers_health_status_none": 3,
647 + "containers_health_status_none": 4,
648 "containers_health_status_not_running_unhealthy": 6,
649 "containers_health_status_starting": 3,
650 "containers_health_status_unhealthy": 1,
@@ -800,6 +800,9 @@ func (m *mockClient) ContainerList(_ context.Context, opts typesContainer.ListOp
800 {Names: []string{"container14"}, State: "dead", Image: "example/example:v4"},
801 {Names: []string{"container15"}, State: "dead", Image: "example/example:v4"},
802 {Names: []string{"container16"}, State: "dead", Image: "example/example:v4"},
803 + {Names: []string{"container17"}, State: "dead", Image: "example/example:v4",
804 + Labels: map[string]string{"netdata.cloud/ignore": "true"},
805 + },
806 }
807 }
808