Default to utf-8 when no encoding type found parsing dogwrap output #268
+2
−1
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.
Observation:
When using
dogwrap
(via a Python 2pip install
) to run commands viacron
, in cases where thesubmit_mode
is set to all, it was expected that bothstdout
andstderr
would appear in DataDog. This was not the case.The event would appear, but the
stdout
/stderr
was lostThe output would appear correctly if the
dogwrap
command was run in the shell, just not incron
Cause:
In Python 2, the string from the
OutputReader
was being inspected for anencoding
. If this command was run within a shell, an encoding was found (in this case,ANSI_X3.4-1968
). However, when run fromcron
, no encoding was detected. Thus, attempting to execute a string decode (line.decode(None)
) resulted in an error.In Python 3, the encoding inspection defaults to UTF-8, which is a valid encoding type.
This meant the OutputReader would end up returning no values for
stdout
/stderr
, but the return code and command were still available and sent onto DataDog for client displayingSolution:
In cases where an encoding type is not identified, default to UTF-8
This will ensure the type is never None, and the default value is used.
An alternative solution to this PR is to not decode if no encoding type is identified, but that might cause more issues down the line.
Environment used for debugging and code testing: Ubuntu 16.04, Python 2.7.12/3.5.2