[airflow][presto] Gracefully handle 503 errors and avoid eval() #985
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.
TO: @mistercrunch
What? Why?
I was running an airflow job that executes a number of presto queries. The first bunch succeeded, and then the job suddenly died with this error:
What happened here is that presto was temporarily unavailable (a "hiccup") so it returned a 503 error. Our error-handling code expected the response to be
eval()
'able, which is true in most cases but not in the 503 case. With 503's, the message is just "Unexpected status code 503". You can't eval() that.We discussed this offline. We both agree that
eval()
is just a bad thing to do. You suggested usingjson.loads
instead. I tried that and found thatstr(e)
is not valid json. Instead, it's python-hash formatted. For example, it hasu
prefixes for all the strings.So I chose to take a different approach. I simply check for the values I expect to find (a la duck-typing). If they exist, I extract them and use them in the PrestoError. If not, I just str() the whole error.
How was it tested?
I executed an invalid query ("blah blah select...") and verified that we handle that error. Here's what I saw:
For the other case, rather than taking down presto, I simulated this by manually setting the error object to the string "Unexpected status code 503". Here's what I saw:
I'm brand new to airflow development so let me know if there are other/better ways to verify my change.