[core][subprocess output] Fix unintended empty output errors #3024
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?
This PR accomplishes two related goals: primarily, it increases the robustness by which subprocess_output.py determines if the output is empty. Secondly, it updates postfix.py so that it does not raise an error when it examines empty postfix queues.
This recent PR refactored and cleaned up subprocess_output.py. At the same time, the conditional used to validate the emptiness (or non-emptiness) of the output was subtly changed. Specifically, emptiness was previously checked via
and after the refactor was checked via
This was an important change, since the output from
subprocess.Popen
is always non-None, and therefore the conditionis None
would never evaluate to True. Conversely,if not output
correctly evaluates to True for empty output, but it will also (and undesirably) evaluate to True for non-empty output that is literally0
.Since we want to know about zero-length output that is never None, we should measure the length of the output and evaluate that, i.e.
This will evaluate to True for empty output, but False for a literal output of
0
. This PR makes this change.This PR also makes a related change: the postfix.py check now passes
raise_on_empty_output=False
to get_subprocess_output since the postfix check functions by counting the number of regular files found in a given directory. Empty postfix queues produce no output for this check, which causes it to raiseSubprocessOutputEmptyError
without the False parameter. By passing the False parameter, we indicate that empty output is permitted, and the error is not raised.Motivation
After updating from agent 5.9.1 => 5.10.0 in my testing environment, I noticed that I had stopped receiving postfix metrics. A look inside the collector log revealed this:
This host handles almost no mail, so the postfix check will almost always produce empty output. This empty output was not a problem in 5.9.1 though, since empty output was never evaluated as such.
I first attempted to fix this just by adding the False parameter to get_subprocess_output in postfix.py; this worked, but felt like an incomplete solution, hence the update to subprocess_output.py which should allow it to accurately evaluate empty and non-empty output.