From d817f5c6f4909eeafbd9ff9ceadbf29302169bfa Mon Sep 17 00:00:00 2001 From: Qingwen Zhao <864593343@qq.com> Date: Fri, 22 Sep 2023 02:05:30 +0800 Subject: [PATCH] add https support in Prometheus gateway (#392) --- metrics-exporter-prometheus/Cargo.toml | 3 ++- metrics-exporter-prometheus/src/builder.rs | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/metrics-exporter-prometheus/Cargo.toml b/metrics-exporter-prometheus/Cargo.toml index 3073e46b..308a11be 100644 --- a/metrics-exporter-prometheus/Cargo.toml +++ b/metrics-exporter-prometheus/Cargo.toml @@ -20,7 +20,7 @@ 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", "tracing"] +push-gateway = ["async-runtime", "hyper/client", "hyper-tls", "tracing"] [dependencies] metrics = { version = "^0.21", path = "../metrics" } @@ -35,6 +35,7 @@ hyper = { version = "0.14", default-features = false, features = ["tcp", "http1" 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 } [dev-dependencies] tracing = "0.1" diff --git a/metrics-exporter-prometheus/src/builder.rs b/metrics-exporter-prometheus/src/builder.rs index 26ba6353..8c41ce15 100644 --- a/metrics-exporter-prometheus/src/builder.rs +++ b/metrics-exporter-prometheus/src/builder.rs @@ -29,6 +29,7 @@ use hyper::{ http::HeaderValue, Method, Request, Uri, }; +use hyper_tls::HttpsConnector; use indexmap::IndexMap; #[cfg(feature = "http-listener")] @@ -460,7 +461,8 @@ impl PrometheusBuilder { #[cfg(feature = "push-gateway")] ExporterConfig::PushGateway { endpoint, interval, username, password } => { let exporter = async move { - let client = Client::new(); + let https = HttpsConnector::new(); + let client = Client::builder().build::<_, hyper::Body>(https); let auth = username.as_ref().map(|name| basic_auth(name, password.as_deref())); loop {