apache / apache/druid

Router does not log failed query requests

Open
#13,765 1 comment 0 reactions 0 assignees View on GitHub
Error handling
Dominant language
Java
Stars
14.1k
Forks
3.8k
Avg merge
2d 58m
Merged PRs (30d)
233

Description

### Affected Version

26.0.0-SNAPSHOT

### Description

I am testing the new catalog functionality. To do this, I send a (malformed) request that looks like this:

```json
{
"query":"\nREPLACE INTO \"myWiki3\" OVERWRITE ALL\nSELECT\n TIME_PARSE(\"timestamp\") AS \"__time\",\n namespace,\n page,\n channel,\n \"user\",\n countryName,\n CASE WHEN isRobot = \\'true\\' THEN 1 ELSE 0 END AS isRobot,\n \"added\",\n \"delta\",\n CASE WHEN isNew = \\'true\\' THEN 1 ELSE 0 END AS isNew,\n CAST(\"deltaBucket\" AS DOUBLE) AS deltaBucket,\n \"deleted\"\nFROM TABLE(ext.wikiSample(\n uris => ?\n))\nPARTITIONED BY DAY\n",
"parameters":[
[
"wikipedia.json.gz"
]
],
"resultFormat":"object"
}
```

The key thing to notice is parameters: they are not of the correct form. However, it was hard to figure that out from the error provided from the Router, which failed to deserialize the request:

```json
{
"error":"Unknown exception",
"errorMessage":"Cannot deserialize instance of `org.apache.druid.sql.http.SqlParameter` out of START_ARRAY token\n at [Source: (org.eclipse.jetty.server.HttpInputOverHTTP); line: 1, column: 463] (through reference chain: org.apache.druid.sql.http.SqlQuery[\"parameters\"]->java.util.ArrayList[0])",
"errorClass":"com.fasterxml.jackson.databind.exc.MismatchedInputException",
"host":"None"
}
```

Clearly, something has gone wrong. Is a code bug or a user error? Very hard to tell. If a user error, what is wrong? The point of this ticket, _there is no log file entry_. That is, if I go the router log file, I see no entry for the above error. As a result, it is very difficult to track down what is going wrong other than to guess from the error message.

The request is to log any time that the Router fails to forward a SQL query.

The error is that the `parameters` field is a list of (name, type) pairs, but I provided just the value. So, a second request is to provide a better error message, such as "Incorrect parameter format. See SqlQuery docs" or "... Parameters must be name/value maps." Or, perhaps, more general: "SQL request has the wrong structure. See [SQLRequest] for details." with a link to the docs.

A third point would be: why is the router deserializing the query request? Why isn't it a simple pass-through? And, if we must deserialize, why are we not using the same code that the Broker uses? The Broker is able to deserialize the above.

Contributor guide

Open the contributing guide

Research direction

Reproduce the malformed SQL request against the Router and inspect the Router's SQL request deserialization and forwarding path. Compare that behavior with the Broker's handling, as requested in the issue. Done means failed SQL forwarding is logged and the response explains the invalid parameters structure or links to the relevant SqlQuery documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.