Skip to content
Closed
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
48 changes: 45 additions & 3 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ tiff = "0.10.0"
tilejson = "0.4"
tokio = { version = "1", features = ["macros"] }
tokio-postgres-rustls = "0.13"
tracing = { version = "0.1.41", features = ["log"] }
tracing-log = { version = "0.2.0", features = ["interest-cache"] }
tracing-subscriber = { version = "0.3.19", features = ["env-filter", "json", "fmt", "chrono"] }
url = "2.5"
walkdir = "2.5.0"
xxhash-rust = { version = "0.8", features = ["xxh3"] }
Expand Down
19 changes: 11 additions & 8 deletions martin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ maintainer = "Yuri Astrakhan <[email protected]>, Stepan Kuzmin <to.stepan
maintainer-scripts = "../debian"
depends = "$auto"
assets = [
["target/release/martin", "/usr/bin/martin", "755"],
["target/release/martin-cp", "/usr/bin/martin-cp", "755"],
["target/release/mbtiles", "/usr/bin/mbtiles", "755"],
["../README.md", "/usr/share/doc/martin/README.md", "644"],
["../debian/config.yaml", "/usr/share/doc/martin/config.yaml", "644"],
["../debian/config.yaml", "/usr/local/etc/martin/config.yaml", "644"],
["target/release/martin","/usr/bin/martin","755"],
["target/release/martin-cp","/usr/bin/martin-cp","755"],
["target/release/mbtiles","/usr/bin/mbtiles","755"],
["../README.md","/usr/share/doc/martin/README.md","644"],
["../debian/config.yaml","/usr/share/doc/martin/config.yaml","644"],
["../debian/config.yaml","/usr/local/etc/martin/config.yaml","644"],
]

# see https://github.com/kornelski/cargo-deb/blob/main/systemd.md#packagemetadatadebsystemd-units-options
Expand Down Expand Up @@ -56,14 +56,14 @@ name = "bench"
harness = false

[features]
default = ["cog", "fonts", "lambda", "mbtiles", "metrics", "pmtiles", "postgres", "sprites", "styles", "webui"]
default = ["cog","fonts","lambda","mbtiles","metrics","pmtiles","postgres","sprites","styles","webui"]
cog = ["dep:png", "dep:tiff"]
fonts = ["dep:bit-set", "dep:pbf_font_tools", "dep:regex"]
lambda = ["dep:lambda-web"]
mbtiles = ["dep:mbtiles"]
metrics = ["dep:actix-web-prom"]
pmtiles = ["dep:aws-config", "dep:pmtiles"]
postgres = ["dep:deadpool-postgres", "dep:enum-display", "dep:json-patch", "dep:postgis", "dep:postgres", "dep:postgres-protocol", "dep:regex", "dep:rustls-native-certs", "dep:rustls-pemfile", "dep:semver", "dep:tokio-postgres-rustls"]
postgres = ["dep:deadpool-postgres","dep:enum-display","dep:json-patch","dep:postgis","dep:postgres","dep:postgres-protocol","dep:regex","dep:rustls-native-certs","dep:rustls-pemfile","dep:semver","dep:tokio-postgres-rustls"]
sprites = ["dep:spreet", "tokio/fs"]
styles = ["dep:walkdir", "tokio/fs"]
webui = ["dep:actix-web-static-files", "dep:static-files", "dep:walkdir"]
Expand Down Expand Up @@ -116,6 +116,9 @@ tiff = { workspace = true, optional = true }
tilejson.workspace = true
tokio = { workspace = true, features = ["io-std"] }
tokio-postgres-rustls = { workspace = true, optional = true }
tracing.workspace = true
tracing-log.workspace = true
tracing-subscriber.workspace = true
url.workspace = true
walkdir = { workspace = true, optional = true }
xxhash-rust.workspace = true
Expand Down
5 changes: 4 additions & 1 deletion martin/src/args/root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use clap::builder::styling::AnsiColor;
use log::warn;

use crate::MartinError::ConfigAndConnectionsError;
use crate::MartinResult;
#[cfg(feature = "fonts")]
use crate::OptOneMany;
use crate::args::connections::Arguments;
Expand All @@ -21,6 +20,7 @@ use crate::config::Config;
feature = "styles",
))]
use crate::file_config::FileConfigEnum;
use crate::{LogFormatOptions, MartinResult};

/// Defines the styles used for the CLI help output.
const HELP_STYLES: Styles = Styles::styled()
Expand Down Expand Up @@ -69,6 +69,9 @@ pub struct MetaArgs {
pub watch: bool,
/// Connection strings, e.g. `postgres://...` or `/path/to/files`
pub connection: Vec<String>,
/// Logging format
#[arg(long)]
pub log_format: Option<LogFormatOptions>,
}

#[derive(Parser, Debug, Clone, PartialEq, Default)]
Expand Down
26 changes: 21 additions & 5 deletions martin/src/bin/martin-cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ use clap::builder::Styles;
use clap::builder::styling::AnsiColor;
use futures::TryStreamExt;
use futures::stream::{self, StreamExt};
use log::{debug, error, info, log_enabled};
use log::{debug, error, info, log_enabled, warn};
use martin::args::{Args, ExtraArgs, MetaArgs, OsEnv, SrvArgs};
use martin::mbtiles::MbtilesError;
use martin::srv::{DynTileSource, merge_tilejson};
use martin::{
Config, MartinError, MartinResult, ServerState, TileData, TileInfoSource, read_config,
Config, LogFormatOptions, MartinError, MartinResult, ReloadableTracingConfiguration,
ServerState, TileData, TileInfoSource, read_config,
};
use martin_tile_utils::{TileCoord, TileInfo, TileRect, append_rect, bbox_to_xyz};
use mbtiles::UpdateZoomType::GrowOnly;
Expand Down Expand Up @@ -132,6 +133,18 @@ fn parse_key_value(s: &str) -> Result<(String, String), String> {
}

async fn start(copy_args: CopierArgs) -> MartinCpResult<()> {
let trace = ReloadableTracingConfiguration::init_global_registry("martin_cp=info");
if let Ok(fmt) = std::env::var("MARTIN_CP_LOG_FORMAT") {
use clap::ValueEnum;
if let Ok(fmt) = LogFormatOptions::from_str(&fmt, true) {
trace.reload_fmt(fmt);
} else {
warn!("ignoring invalid log format for MARTIN_CP_LOG_FORMAT");
}
}
if let Some(fmt) = copy_args.meta.log_format {
trace.reload_fmt(fmt);
}
info!("martin-cp tile copier v{VERSION}");

let env = OsEnv::default();
Expand All @@ -155,6 +168,12 @@ async fn start(copy_args: CopierArgs) -> MartinCpResult<()> {
args.merge_into_config(&mut config, &env)?;
config.finalize()?;

if let Some(observability) = &config.srv.observability {
if let Some(fmt) = observability.log_format {
trace.reload_fmt(fmt);
}
}

let sources = config.resolve().await?;

if let Some(file_name) = save_config {
Expand Down Expand Up @@ -476,9 +495,6 @@ async fn init_schema(

#[actix_web::main]
async fn main() {
let env = env_logger::Env::default().default_filter_or("martin_cp=info");
env_logger::Builder::from_env(env).init();

if let Err(e) = start(CopierArgs::parse()).await {
// Ensure the message is printed, even if the logging is disabled
if log_enabled!(log::Level::Error) {
Expand Down
25 changes: 20 additions & 5 deletions martin/src/bin/martin.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
use clap::Parser;
use log::{error, info, log_enabled};
use log::{error, info, log_enabled, warn};
use martin::args::{Args, OsEnv};
use martin::srv::new_server;
use martin::{Config, MartinResult, read_config};
use martin::{Config, LogFormatOptions, MartinResult, ReloadableTracingConfiguration, read_config};

const VERSION: &str = env!("CARGO_PKG_VERSION");

async fn start(args: Args) -> MartinResult<()> {
let trace = ReloadableTracingConfiguration::init_global_registry("martin=info");
if let Ok(fmt) = std::env::var("MARTIN_LOG_FORMAT") {
use clap::ValueEnum;
if let Ok(fmt) = LogFormatOptions::from_str(&fmt, true) {
trace.reload_fmt(fmt);
} else {
warn!("ignoring invalid log format for MARTIN_LOG_FORMAT");
}
}
if let Some(fmt) = args.meta.log_format {
trace.reload_fmt(fmt);
}
info!("Starting Martin v{VERSION}");

let env = OsEnv::default();
Expand All @@ -21,6 +33,12 @@ async fn start(args: Args) -> MartinResult<()> {

args.merge_into_config(&mut config, &env)?;
config.finalize()?;

if let Some(observability) = &config.srv.observability {
if let Some(fmt) = observability.log_format {
trace.reload_fmt(fmt);
}
}
let sources = config.resolve().await?;

if let Some(file_name) = save_config {
Expand Down Expand Up @@ -50,9 +68,6 @@ async fn start(args: Args) -> MartinResult<()> {

#[actix_web::main]
async fn main() {
let env = env_logger::Env::default().default_filter_or("martin=info");
env_logger::Builder::from_env(env).init();

if let Err(e) = start(Args::parse()).await {
// Ensure the message is printed, even if the logging is disabled
if log_enabled!(log::Level::Error) {
Expand Down
5 changes: 4 additions & 1 deletion martin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ pub use source::{
};

mod utils;
pub use utils::{IdResolver, MartinError, MartinResult, NO_MAIN_CACHE, OptBoolObj, OptOneMany};
pub use utils::{
IdResolver, LogFormatOptions, MartinError, MartinResult, NO_MAIN_CACHE, OptBoolObj, OptOneMany,
ReloadableTracingConfiguration,
};

pub mod args;
#[cfg(feature = "cog")]
Expand Down
2 changes: 1 addition & 1 deletion martin/src/pg/query_tables.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use martin_tile_utils::EARTH_CIRCUMFERENCE_DEGREES;
use std::collections::HashMap;

use futures::pin_mut;
use log::{debug, warn};
use martin_tile_utils::EARTH_CIRCUMFERENCE_DEGREES;
use postgis::ewkb;
use postgres_protocol::escape::{escape_identifier, escape_literal};
use serde_json::Value;
Expand Down
6 changes: 4 additions & 2 deletions martin/src/srv/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::collections::HashMap;
use serde::{Deserialize, Serialize};

use super::cors::CorsConfig;
use crate::LogFormatOptions;
use crate::args::PreferredEncoding;

pub const KEEP_ALIVE_DEFAULT: u64 = 75;
Expand All @@ -21,16 +22,17 @@ pub struct SrvConfig {
pub web_ui: Option<crate::args::WebUiMode>,
pub cors: Option<CorsConfig>,
/// Advanced monitoring options
#[cfg(feature = "metrics")]
pub observability: Option<ObservabilityConfig>,
}

/// More advanced monitoring montoring options
#[cfg(feature = "metrics")]
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Default)]
pub struct ObservabilityConfig {
/// Configure the logging format
pub log_format: Option<LogFormatOptions>,
/// Configure metrics reported under `/_/metrics`
#[cfg(feature = "metrics")]
pub metrics: Option<MetricsConfig>,
}

Expand Down
2 changes: 2 additions & 0 deletions martin/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ pub use cfg_containers::{OptBoolObj, OptOneMany};

mod error;
pub use error::*;
mod tracing;
pub use tracing::*;

mod id_resolver;
pub use id_resolver::IdResolver;
Expand Down
Loading
Loading