operator/watchers: skip expensive debug log operations when disabled #35605
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.
Slightly modify the service handler debug statement to skip the expensive computation of service-related log fields when debug logs are disabled, as not used at all. In particular, rendering services and endpoints into the corresponding string representation is demanding both in terms of CPU time and memory allocations. Passing the original object as parameter, rather than the stringified version, allows to delegate this operation to slog, which is then skipped if debug logs are disabled.
Additionally, let's also rework the warning log to only include the service name and namespace as parameter for simplicity, as it is never expected to occur (all temporary errors are retried internally).
Related: 52c06e1 ("Add checks to avoid use of logrus WithFields function in hot paths")