diff --git a/metrics-exporter-prometheus/Cargo.toml b/metrics-exporter-prometheus/Cargo.toml index 308a11be..8b0542d1 100644 --- a/metrics-exporter-prometheus/Cargo.toml +++ b/metrics-exporter-prometheus/Cargo.toml @@ -20,7 +20,9 @@ keywords = ["metrics", "telemetry", "prometheus"] default = ["http-listener", "push-gateway"] async-runtime = ["tokio", "hyper"] http-listener = ["async-runtime", "hyper/server", "ipnet"] -push-gateway = ["async-runtime", "hyper/client", "hyper-tls", "tracing"] +push-gateway = ["async-runtime", "hyper/client", "tracing"] +native-tls = ["hyper-tls"] +rustls-tls = ["hyper-rustls"] [dependencies] metrics = { version = "^0.21", path = "../metrics" } @@ -36,6 +38,8 @@ ipnet = { version = "2", optional = true } tokio = { version = "1", features = ["rt", "net", "time"], optional = true } tracing = { version = "0.1.26", optional = true } hyper-tls = { version = "0.5.0", optional = true } +hyper-rustls = { version = "0.24.2", optional = true } +cfg-if = "1.0.0" [dev-dependencies] tracing = "0.1" diff --git a/metrics-exporter-prometheus/src/builder.rs b/metrics-exporter-prometheus/src/builder.rs index cc86dc97..06903bd5 100644 --- a/metrics-exporter-prometheus/src/builder.rs +++ b/metrics-exporter-prometheus/src/builder.rs @@ -29,7 +29,6 @@ use hyper::{ http::HeaderValue, Method, Request, Uri, }; -use hyper_tls::HttpsConnector; use indexmap::IndexMap; #[cfg(feature = "http-listener")] @@ -462,8 +461,16 @@ impl PrometheusBuilder { #[cfg(feature = "push-gateway")] ExporterConfig::PushGateway { endpoint, interval, username, password } => { let exporter = async move { - let https = HttpsConnector::new(); - let client = Client::builder().build::<_, hyper::Body>(https); + cfg_if::cfg_if! { + if #[cfg(feature = "native-tls")] { + let client = Client::builder().build::<_, hyper::Body>(hyper_tls::HttpsConnector::new()); + } else if #[cfg(feature = "rustls-tls")] { + let client = Client::builder().build::<_, hyper::Body>(hyper_rustls::HttpsConnectorBuilder::new()); + } else { + let client = Client::builder().build_http(); + } + } + let auth = username.as_ref().map(|name| basic_auth(name, password.as_deref())); loop {