druid-io / pydruid

A Python connector for Druid
Other
506 stars 194 forks source link

Surface HTML errors #121

Closed betodealmeida closed 6 years ago

betodealmeida commented 6 years ago

Our Druid cluster is returning an HTML error message when OOMing:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 500 </title>
</head>
<body>
<h2>HTTP ERROR: 500</h2>
<p>Problem accessing /druid/v2/. Reason:
<pre>    javax.servlet.ServletException: java.lang.OutOfMemoryError: GC overhead limit exceeded</pre></p>
<hr /><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.3.19.v20170502</a><hr/>
</body>
</html>

This message is not surfaced correctly to the client, since the client expects a JSON response from Druid. Here's how it's currently surfaced:

{"error": "HTTP Error 500: Server Error \n Druid Error: None \n Query is: {\n    \"queryType\": \"scan\",\n    \"dataSource\": \"driver_locations\",\n    \"dimensions\": [\n        \"location\"\n    ],\n    \"granularity\": \"all\",\n    \"intervals\": \"2011-02-13T00:00:00+00:00/2101-01-01T00:00:00+00:00\",\n    \"metrics\": [],\n    \"limit\": 50000\n}"}

I modified the code that checks for errors in the client so that if an HTML response is returned the error message is correctly extracted from the <PRE></PRE> tags. With this, the error is surfaced correctly (although somewhat verbose):

HTTP Error 500: <html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1"/>
<title>Error 500 </title>
</head>
<body>
<h2>HTTP ERROR: 500</h2>
<p>Problem accessing /druid/v2/. Reason:
<pre>    javax.servlet.ServletException: java.lang.OutOfMemoryError: GC overhead limit exceeded</pre></p>
<hr /><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.3.19.v20170502</a><hr/>
</body>
</html>
 Druid Error: javax.servlet.ServletException: java.lang.OutOfMemoryError: GC overhead limit exceeded
 Query is: {
    "queryType": "topN",
    "dataSource": "testdatasource",
    "granularity": "all",
    "intervals": "2015-12-29/pt1h",
    "aggregations": [
        {
            "type": "doubleSum",
            "fieldName": "count",
            "name": "count"
        }
    ],
    "dimension": "user_name",
    "metric": "count",
    "filter": {
        "type": "selector",
        "dimension": "user_lang",
        "value": "en"
    },
    "threshold": 1,
    "context": {
        "timeout": 1000
    }
}
mistercrunch commented 6 years ago

@gianm seems like that should be fixed upstream, but PyDruid should probably handle it as well for the sake of supporting previous versions.

mistercrunch commented 6 years ago

@betodealmeida the build failed :(

betodealmeida commented 6 years ago

Looks like JSONDecodeError was introduced in Python 3.5 only, I added a workaround.