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

Configure database idle and max lifetime #169

Merged
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
18 changes: 18 additions & 0 deletions grpc-ingest/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,16 @@ pub struct ConfigIngesterPostgres {
deserialize_with = "deserialize_usize_str"
)]
pub max_connections: usize,
#[serde(
default = "ConfigIngesterPostgres::default_idle_timeout",
deserialize_with = "deserialize_duration_str"
)]
pub idle_timeout: Duration,
#[serde(
default = "ConfigIngesterPostgres::default_max_lifetime",
deserialize_with = "deserialize_duration_str"
)]
pub max_lifetime: Duration,
}

impl ConfigIngesterPostgres {
Expand All @@ -253,6 +263,14 @@ impl ConfigIngesterPostgres {
pub const fn default_max_connections() -> usize {
50
}

pub const fn default_idle_timeout() -> Duration {
Duration::from_millis(75)
}

pub const fn default_max_lifetime() -> Duration {
Duration::from_millis(125)
}
}

#[derive(Debug, Clone, Default, Deserialize)]
Expand Down
2 changes: 2 additions & 0 deletions grpc-ingest/src/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub async fn create_pool(config: ConfigIngesterPostgres) -> anyhow::Result<PgPoo
PgPoolOptions::new()
.min_connections(config.min_connections.try_into()?)
.max_connections(config.max_connections.try_into()?)
.idle_timeout(config.idle_timeout)
.max_lifetime(config.max_lifetime)
.connect_with(options)
.await
.map_err(Into::into)
Expand Down
Loading