proxy: add flag to enable http pool for all users (#5959)

## Problem

#5123

## Summary of changes

Add `--sql-over-http-pool-opt-in true` default cli arg. Allows us to set
`--sql-over-http-pool-opt-in false` region-by-region
This commit is contained in:
Conrad Ludgate
2023-11-30 10:19:30 +00:00
committed by GitHub
parent f05d1b598a
commit fc77c42c57
4 changed files with 14 additions and 6 deletions

View File

@@ -90,6 +90,9 @@ struct ProxyCliArgs {
/// timeout for http connections
#[clap(long, default_value = "15s", value_parser = humantime::parse_duration)]
sql_over_http_timeout: tokio::time::Duration,
/// Whether the SQL over http pool is opt-in
#[clap(long, default_value_t = true, value_parser = clap::builder::BoolishValueParser::new(), action = clap::ArgAction::Set)]
sql_over_http_pool_opt_in: bool,
/// timeout for scram authentication protocol
#[clap(long, default_value = "15s", value_parser = humantime::parse_duration)]
scram_protocol_timeout: tokio::time::Duration,
@@ -275,7 +278,8 @@ fn build_config(args: &ProxyCliArgs) -> anyhow::Result<&'static ProxyConfig> {
}
};
let http_config = HttpConfig {
sql_over_http_timeout: args.sql_over_http_timeout,
timeout: args.sql_over_http_timeout,
pool_opt_in: args.sql_over_http_pool_opt_in,
};
let authentication_config = AuthenticationConfig {
scram_protocol_timeout: args.scram_protocol_timeout,

View File

@@ -34,7 +34,8 @@ pub struct TlsConfig {
}
pub struct HttpConfig {
pub sql_over_http_timeout: tokio::time::Duration,
pub timeout: tokio::time::Duration,
pub pool_opt_in: bool,
}
pub struct AuthenticationConfig {

View File

@@ -204,8 +204,8 @@ pub async fn handle(
config: &'static HttpConfig,
) -> Result<Response<Body>, ApiError> {
let result = tokio::time::timeout(
config.sql_over_http_timeout,
handle_inner(request, sni_hostname, conn_pool, session_id),
config.timeout,
handle_inner(config, request, sni_hostname, conn_pool, session_id),
)
.await;
let mut response = match result {
@@ -269,7 +269,7 @@ pub async fn handle(
Err(_) => {
let message = format!(
"HTTP-Connection timed out, execution time exeeded {} seconds",
config.sql_over_http_timeout.as_secs()
config.timeout.as_secs()
);
error!(message);
json_response(
@@ -287,6 +287,7 @@ pub async fn handle(
#[instrument(name = "sql-over-http", fields(pid = tracing::field::Empty), skip_all)]
async fn handle_inner(
config: &'static HttpConfig,
request: Request<Body>,
sni_hostname: Option<String>,
conn_pool: Arc<GlobalConnPool>,
@@ -311,7 +312,8 @@ async fn handle_inner(
let array_mode = headers.get(&ARRAY_MODE) == Some(&HEADER_VALUE_TRUE);
// Allow connection pooling only if explicitly requested
let allow_pool = headers.get(&ALLOW_POOL) == Some(&HEADER_VALUE_TRUE);
// or if we have decided that http pool is no longer opt-in
let allow_pool = !config.pool_opt_in || headers.get(&ALLOW_POOL) == Some(&HEADER_VALUE_TRUE);
// isolation level, read only and deferrable

View File

@@ -2114,6 +2114,7 @@ class NeonProxy(PgProtocol):
# Console auth backend params
*["--auth-backend", "console"],
*["--auth-endpoint", self.endpoint],
*["--sql-over-http-pool-opt-in", "false"],
]
if self.fixed_rate_limit is not None:
args += [