Skip to content

Commit 89fbdb6

Browse files
authored
Added support for https in expvar scraping (#1213)
* Added support for https with no tls certificate verification Signed-off-by: Caleb Metz <[email protected]> * Added more error information to requests Signed-off-by: Caleb Metz <[email protected]> * Added more error info to json parsing of expvar results Signed-off-by: Caleb Metz <[email protected]> * Updated sleep from default 1sec to `sample_period` Signed-off-by: Caleb Metz <[email protected]> * Added CHANGELOG and updated comment. Signed-off-by: Caleb Metz <[email protected]> --------- Signed-off-by: Caleb Metz <[email protected]>
1 parent 58b098c commit 89fbdb6

File tree

4 files changed

+190
-10
lines changed

4 files changed

+190
-10
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## Added
99
- Introduced the ability for users to configure lading's sample rate,
1010
configuration option `sample_period_milliseconds` in `lading.yaml`.
11+
- Users can now configure expvar scraping on https endpoints, skipping certificate validation.
1112

1213
## [0.25.4]
1314
## Changed

Cargo.lock

+169
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lading/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ rand = { workspace = true, default-features = false, features = [
5858
"std_rng",
5959
] }
6060
regex = { version = "1.11" }
61-
reqwest = { version = "0.12", default-features = false, features = ["json"] }
61+
reqwest = { version = "0.12", default-features = false, features = ["json", "default-tls"] }
6262
rustc-hash = { workspace = true }
6363
serde = { workspace = true }
6464
serde_json = { workspace = true }

lading/src/target_metrics/expvar.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Expvar target metrics fetcher
22
//!
33
//! This module scrapes Go expvar formatted metrics from the target software.
4-
//! The metrics are formatted as a JSON tree that is fetched over HTTP.
4+
//! The metrics are formatted as a JSON tree that is fetched over HTTP or HTTPS.
55
66
use std::time::Duration;
77

@@ -80,24 +80,34 @@ impl Expvar {
8080
self.sample_period
8181
);
8282

83-
let client = reqwest::Client::new();
83+
// Disable certificate validation
84+
let client = reqwest::ClientBuilder::new()
85+
.danger_accept_invalid_certs(true)
86+
.build()
87+
.expect("Failed to build http/https client");
8488

8589
let server = async move {
8690
loop {
8791
tokio::time::sleep(self.sample_period).await;
88-
let Ok(resp) = client
92+
let resp = match client
8993
.get(&self.config.uri)
9094
.timeout(self.sample_period)
9195
.send()
9296
.await
93-
else {
94-
info!("failed to get expvar uri");
95-
continue;
97+
{
98+
Ok(resp) => resp, // If successful, return the response
99+
Err(err) => {
100+
info!("Failed to get expvar URI: {}", err);
101+
continue; // Skip the iteration on error
102+
}
96103
};
97104

98-
let Ok(json) = resp.json::<Value>().await else {
99-
info!("failed to parse expvar json");
100-
continue;
105+
let json = match resp.json::<Value>().await {
106+
Ok(json) => json, // Successfully parsed JSON
107+
Err(err) => {
108+
info!("Failed to parse expvar JSON: {}", err);
109+
continue; // Skip the iteration on error
110+
}
101111
};
102112

103113
// Add lading labels including user defined tags for this endpoint

0 commit comments

Comments
 (0)