Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4216 from Aircloak/cristian/bugfix/misc
Browse files Browse the repository at this point in the history
Make query timeout configurable.
  • Loading branch information
cristianberneanu authored Mar 17, 2020
2 parents d3c6efd + b6fed7a commit 712f1d3
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
25 changes: 17 additions & 8 deletions air/docs/content/ops/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,11 @@ The general shape of `config.json` is:
"lcf_buckets_aggregation_limit": integer,
"max_parallel_queries": positive_integer,
"enable_case_support": boolean,
"connection_keep_time": integer,
"connect_timeout": integer
"connection_timeouts": {
"idle": integer,
"connect": integer,
"request": integer
}
}
```

Expand Down Expand Up @@ -379,13 +382,19 @@ simultaneously. The default value is 10.
The `enable_case_support` field is optional and controls whether restricted `CASE` statements are allowed or not in
anonymizing queries. The default value is false.

The `connection_keep_time` field is optional and it determines how many minutes idle database connections are kept
before they are closed. It needs to be an integer value between 1 and 1 440 (1 day). If not set, a default
timeout value of 1 minute is used.
The `connection_timeouts` field is optional and it controls various database connection timeouts.

The `connection_timeouts.idle` field is optional and it determines how many seconds idle database connections are kept
before they are closed. It needs to be an integer value between 1 and 86400 (1 day). If not set, a default timeout
value of 60 seconds (1 minute) is used.

The `connection_timeouts.connect` field is optional and it determines how many seconds the Insights Cloak waits for a
database connection to be established. It needs to be an integer value between 1 and 3600 (1 hour). If not set, a
default timeout value of 5 seconds is used.

The `connect_timeout` field is optional and it determines how many seconds the Insights Cloak waits for a database
connection to be established. It needs to be an integer value between 1 and 3 600 (1 hour). If not set, a default
timeout value of 5 seconds is used.
The `connection_timeouts.request` field is optional and it determines how many seconds the Insights Cloak waits for a
database request to complete. It needs to be an integer value between 1 and 86400 (1 day). If not set, a default
timeout value of 43200 seconds (12 hours) is used.

### Data source configuration

Expand Down
4 changes: 1 addition & 3 deletions air/lib/air_web/templates/changelog/changelog.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
`select_hints` field in the `parameters` section.
- The Oracle Instant Client version 18.3 is bundled with the container and no longer needs to be
provided separately.
- The timeout for idle connections can now be adjusted in the Cloak config file, under the `connection_keep_time` field.
- The timeout for connecting to a data source can now be adjusted in the Cloak config file, under the `connect_timeout`
field.
- Various data source connection timeouts can now be adjusted in the Cloak config file, under the `timeouts` field.
- Improved support for boolean expressions.
- Allowed inequalities between datetime columns and the current date.
- Added support for `CASE` statements in [standard queries](sql#query-and-subquery-types).
Expand Down
20 changes: 11 additions & 9 deletions cloak/lib/cloak.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ defmodule Cloak do
with {:ok, lcf_buckets_aggregation_limit} <- Aircloak.DeployConfig.fetch("lcf_buckets_aggregation_limit"),
do: Application.put_env(:cloak, :lcf_buckets_aggregation_limit, lcf_buckets_aggregation_limit)

with {:ok, minutes} <- Aircloak.DeployConfig.fetch("connection_keep_time"),
do: update_data_source_config!(:connection_keep_time, :timer.minutes(minutes))

with {:ok, seconds} <- Aircloak.DeployConfig.fetch("connect_timeout"),
do: update_data_source_config!(:connect_timeout, :timer.seconds(seconds))
with {:ok, connection_timeouts} <- Aircloak.DeployConfig.fetch("connection_timeouts") do
data_source_config =
Application.get_env(:cloak, :data_source)
|> update_timeout!(:connection_keep_time, connection_timeouts["idle"])
|> update_timeout!(:connect_timeout, connection_timeouts["connect"])
|> update_timeout!(:timeout, connection_timeouts["request"])

Application.put_env(:cloak, :data_source, data_source_config)
end

with {:ok, true} <- Aircloak.DeployConfig.fetch("enable_case_support"),
do: Application.put_env(:cloak, :enable_case_support, true)
Expand Down Expand Up @@ -80,8 +84,6 @@ defmodule Cloak do
end
end

defp update_data_source_config!(field, new_value) do
data_source_config = Application.get_env(:cloak, :data_source) |> Keyword.replace!(field, new_value)
Application.put_env(:cloak, :data_source, data_source_config)
end
defp update_timeout!(config, _field, nil), do: config
defp update_timeout!(config, field, new_value), do: Keyword.replace!(config, field, :timer.seconds(new_value))
end
11 changes: 9 additions & 2 deletions cloak/priv/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,15 @@
"features": {"$comment": "allowed for backward compatibility"},
"air_socket_url": {"$comment": "allowed for backward compatibility"},
"concurrency": {"type": "integer", "minimum": 0},
"connection_keep_time": {"type": "integer", "minimum": 1, "maximum": 1440},
"connect_timeout": {"type": "integer", "minimum": 1, "maximum": 3600},
"connection_timeouts": {
"type": "object",
"properties": {
"idle": {"type": "integer", "minimum": 1, "maximum": 86400},
"connect": {"type": "integer", "minimum": 1, "maximum": 3600},
"request": {"type": "integer", "minimum": 1, "maximum": 86400}
},
"additionalProperties": false
},
"lcf_buckets_aggregation_limit": {"type": "integer", "minimum": 0},
"sanitize_otp_errors": {"type": "boolean"},
"enable_case_support": {"type": "boolean"},
Expand Down

0 comments on commit 712f1d3

Please sign in to comment.