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

Fix martin --auto-bounds silently ignored with --config #1223

Merged
merged 2 commits into from
Mar 1, 2024
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions martin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,13 @@ bit-set = { workspace = true, optional = true }
brotli.workspace = true
clap.workspace = true
deadpool-postgres = { workspace = true, optional = true }
enum-display.workspace = true
env_logger.workspace = true
flate2.workspace = true
futures.workspace = true
itertools.workspace = true
json-patch = { workspace = true, optional = true }
lambda-web = { workspace = true, optional = true }
log.workspace = true
martin-tile-utils.workspace = true
mbtiles = { workspace = true, optional = true }
Expand All @@ -92,8 +94,8 @@ num_cpus.workspace = true
pbf_font_tools = { workspace = true, optional = true }
pmtiles = { workspace = true, optional = true }
postgis = { workspace = true, optional = true }
postgres-protocol = { workspace = true, optional = true }
postgres = { workspace = true, optional = true }
postgres-protocol = { workspace = true, optional = true }
regex.workspace = true
rustls-native-certs.workspace = true
rustls-pemfile.workspace = true
Expand All @@ -110,7 +112,6 @@ tilejson.workspace = true
tokio = { workspace = true, features = ["io-std"] }
tokio-postgres-rustls = { workspace = true, optional = true }
url.workspace = true
lambda-web = { workspace = true, optional = true }

[dev-dependencies]
cargo-husky.workspace = true
Expand Down
32 changes: 21 additions & 11 deletions martin/src/args/pg.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::time::Duration;

use clap::ValueEnum;
use enum_display::EnumDisplay;
use log::{info, warn};
use serde::{Deserialize, Serialize};

Expand All @@ -13,8 +14,11 @@ use crate::utils::{OptBoolObj, OptOneMany};
// Must match the help string for BoundsType::Quick
pub const DEFAULT_BOUNDS_TIMEOUT: Duration = Duration::from_secs(5);

#[derive(PartialEq, Eq, Default, Debug, Clone, Copy, Serialize, Deserialize, ValueEnum)]
#[derive(
PartialEq, Eq, Default, Debug, Clone, Copy, Serialize, Deserialize, ValueEnum, EnumDisplay,
)]
#[serde(rename_all = "lowercase")]
#[enum_display(case = "Kebab")]
pub enum BoundsCalcType {
/// Compute table geometry bounds, but abort if it takes longer than 5 seconds.
#[default]
Expand All @@ -37,7 +41,7 @@ pub struct PgArgs {
/// If a spatial PG table has SRID 0, then this default SRID will be used as a fallback.
#[arg(short, long)]
pub default_srid: Option<i32>,
#[arg(help = format!("Maximum Postgres connections pool size [DEFAULT: {}]", POOL_SIZE_DEFAULT), short, long)]
#[arg(help = format!("Maximum Postgres connections pool size [DEFAULT: {POOL_SIZE_DEFAULT}]"), short, long)]
pub pool_size: Option<usize>,
/// Limit the number of features in a tile from a PG table source.
#[arg(short, long)]
Expand Down Expand Up @@ -76,29 +80,35 @@ impl PgArgs {
}
}

/// Apply CLI parameters from `self` to the configuration loaded from the config file `pg_config`
pub fn override_config<'a>(self, pg_config: &mut OptOneMany<PgConfig>, env: &impl Env<'a>) {
if self.default_srid.is_some() {
info!("Overriding configured default SRID to {} on all Postgres connections because of a CLI parameter", self.default_srid.unwrap());
if let Some(default_srid) = self.default_srid {
info!("Overriding configured default SRID to {default_srid} on all Postgres connections because of a CLI parameter");
pg_config.iter_mut().for_each(|c| {
c.default_srid = self.default_srid;
});
}
if self.pool_size.is_some() {
info!("Overriding configured pool size to {} on all Postgres connections because of a CLI parameter", self.pool_size.unwrap());
if let Some(pool_size) = self.pool_size {
info!("Overriding configured pool size to {pool_size} on all Postgres connections because of a CLI parameter");
pg_config.iter_mut().for_each(|c| {
c.pool_size = self.pool_size;
});
}
if self.max_feature_count.is_some() {
info!("Overriding maximum feature count to {} on all Postgres connections because of a CLI parameter", self.max_feature_count.unwrap());
if let Some(auto_bounds) = self.auto_bounds {
info!("Overriding auto_bounds to {auto_bounds} on all Postgres connections because of a CLI parameter");
pg_config.iter_mut().for_each(|c| {
c.auto_bounds = self.auto_bounds;
});
}
if let Some(max_feature_count) = self.max_feature_count {
info!("Overriding maximum feature count to {max_feature_count} on all Postgres connections because of a CLI parameter");
pg_config.iter_mut().for_each(|c| {
c.max_feature_count = self.max_feature_count;
});
}

if self.ca_root_file.is_some() {
if let Some(ref ca_root_file) = self.ca_root_file {
info!("Overriding root certificate file to {} on all Postgres connections because of a CLI parameter",
self.ca_root_file.as_ref().unwrap().display());
ca_root_file.display());
pg_config.iter_mut().for_each(|c| {
c.ssl_certificates.ssl_root_cert = self.ca_root_file.clone();
});
Expand Down
4 changes: 2 additions & 2 deletions martin/src/args/srv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use crate::srv::{SrvConfig, KEEP_ALIVE_DEFAULT, LISTEN_ADDRESSES_DEFAULT};
#[derive(clap::Args, Debug, PartialEq, Default)]
#[command(about, version)]
pub struct SrvArgs {
#[arg(help = format!("Connection keep alive timeout. [DEFAULT: {}]", KEEP_ALIVE_DEFAULT), short, long)]
#[arg(help = format!("Connection keep alive timeout. [DEFAULT: {KEEP_ALIVE_DEFAULT}]"), short, long)]
pub keep_alive: Option<u64>,
#[arg(help = format!("The socket address to bind. [DEFAULT: {}]", LISTEN_ADDRESSES_DEFAULT), short, long)]
#[arg(help = format!("The socket address to bind. [DEFAULT: {LISTEN_ADDRESSES_DEFAULT}]"), short, long)]
pub listen_addresses: Option<String>,
/// Set TileJSON URL path prefix, ignoring X-Rewrite-URL header. Must begin with a `/`. Examples: `/`, `/tiles`
#[arg(long)]
Expand Down
Loading