Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add configurable timeout for Presto to querybook #1207

Merged
merged 3 commits into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion querybook/server/datasources/query_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def cancel_query_and_notify():
"RETRY", # Very unlikely case, because query normally do not retry
):

task.revoke() # last attempt to cancel it
task.revoke(terminate=True) # last attempt to cancel it
cancel_query_and_notify()
elif task.state == "ABORTED":
# In this case, the task is already aborted, but the status is running
Expand Down
6 changes: 6 additions & 0 deletions querybook/server/lib/query_executor/clients/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(
password: Optional[str] = None,
proxy_user: Optional[str] = None,
impersonate: bool = False,
connection_timeout: int = None,
*args: Any,
**kwargs: Any
) -> None:
Expand All @@ -59,6 +60,10 @@ def __init__(
host = presto_conf.host
port = 8080 if not presto_conf.port else presto_conf.port

requests_kwargs = {}
if connection_timeout and connection_timeout > 0:
requests_kwargs["timeout"] = connection_timeout

connection = presto.connect(
host,
port=port,
Expand All @@ -69,6 +74,7 @@ def __init__(
schema=presto_conf.schema,
source="querybook",
protocol=presto_conf.protocol,
requests_kwargs=requests_kwargs,
)
self._connection = connection
super(PrestoClient, self).__init__()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@
<p>See [here](https://prestodb.github.io/docs/current/installation/jdbc.html) for more details.</p>""",
),
),
(
"connection_timeout",
FormField(
field_type=FormFieldType.Number,
helper="Max number of seconds before timing out the request",
),
),
)

trino_executor_template = StructFormField(
Expand Down
16 changes: 12 additions & 4 deletions querybook/webapp/ui/SmartForm/SmartForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ function SimpleFormField<T>({
value: T;
onChange: onChangeFunc<T>;
}) {
const onFieldChange = React.useCallback(
(newVal: any) => onChange('', newVal),
[onChange]
);
const {
description,
hidden,
Expand All @@ -56,6 +52,18 @@ function SimpleFormField<T>({
field_type: fieldType,
options,
} = formField;

const onFieldChange = React.useCallback(
(newVal: any) => {
if (fieldType === 'number') {
newVal = Number(newVal);
}

return onChange('', newVal);
},
[onChange, fieldType]
);

let controlDOM: React.ReactChild;
if (fieldType === 'string' || fieldType === 'number') {
const inputProps = {
Expand Down