[AGENTONB-2814] Emit exceeded goroutines number as error log #2496
+86
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
{"level":"ERROR","ts":"2026-01-15T13:19:04.732Z","logger":"setup.healthz","msg":"healthz check entering failing state","checker":"goroutines-number","goroutines":262,"limit":50,"error":"too many goroutines: 262 > limit: 50","stacktrace":"main.newGoroutinesNumberHealthzCheck.func1\n\t/workspace/cmd/main.go:520\nsigs.k8s.io/controller-runtime/pkg/healthz.(*Handler).serveAggregated\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.20.4/pkg/healthz/healthz.go:59\nsigs.k8s.io/controller-runtime/pkg/healthz.(*Handler).ServeHTTP\n\t/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.20.4/pkg/healthz/healthz.go:148\nsigs.k8s.io/controller-runtime/pkg/manager.(*controllerManager).addHealthProbeServer.StripPrefix.func4\n\t/usr/local/go/src/net/http/server.go:2384\nnet/http.HandlerFunc.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2322\nnet/http.(*ServeMux).ServeHTTP\n\t/usr/local/go/src/net/http/server.go:2861\nnet/http.serverHandler.ServeHTTP\n\t/usr/local/go/src/net/http/server.go:3340\nnet/http.(*conn).serve\n\t/usr/local/go/src/net/http/server.go:2109"}Motivation
{"level":"DEBUG","ts":"2026-01-15T13:19:04.733Z","logger":"controller-runtime.healthz","msg":"healthz check failed","checker":"goroutines-number","error":"too many goroutines: 262 > limit: 50"}or at the info level without any details (doesn't wrap the error):
{"level":"INFO","ts":"2026-01-15T13:19:04.733Z","logger":"controller-runtime.healthz","msg":"healthz check failed","statuses":[{}]}Additional Notes
We use
sync/atomicto keep a consistent protected state instead of a clearer boolean flag as we could have multiple HTTP requests to access it (someone manually probing on top of the kubelet probe, concurrent probe requests, etc.) so we don't want to flip-flopAlternative approaches:
customSetupLogging(we use it to route info to stdout and err to stderr), but it would be a lot of plumbing for a single log and we'd need to make sure we not only promote it to err correctly but also not twiceMinimum Agent Versions
Are there minimum versions of the Datadog Agent and/or Cluster Agent required?
Describe your test plan
ERRORand ensure you see the goroutine one:Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel