Skip to content

Commit 50f88aa

Browse files
authored
feat(uptime): basic http endpoint (#435)
Just returning a 500 for gets; useful for testing.
1 parent fbd52eb commit 50f88aa

File tree

7 files changed

+225
-25
lines changed

7 files changed

+225
-25
lines changed

Cargo.lock

Lines changed: 131 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ iprange = "0.6.7"
6565
http = "1.2.0"
6666
relay-pattern = { git = "https://github.com/getsentry/relay", rev = "7ba03b5f6ffe95c2429ba315f661d2b8ee3c0efe" }
6767
pest = "2.7.15"
68+
axum = "0.8.6"
6869

6970
[patch.crates-io]
7071
rdkafka = { git = "https://github.com/fede1024/rust-rdkafka" }

src/app/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ pub struct Config {
159159

160160
/// Whether this uptime checker will write to redis or not.
161161
pub redis_readonly: bool,
162+
163+
pub webserver_port: u16,
162164
}
163165

164166
impl Default for Config {
@@ -201,6 +203,7 @@ impl Default for Config {
201203
redis_timeouts_ms: 30_000,
202204
enable_metrics: false,
203205
redis_readonly: false,
206+
webserver_port: 12345,
204207
}
205208
}
206209
}
@@ -357,6 +360,7 @@ mod tests {
357360
redis_timeouts_ms: 30_000,
358361
enable_metrics: false,
359362
redis_readonly: false,
363+
webserver_port: 12345,
360364
}
361365
);
362366
},
@@ -404,6 +408,7 @@ mod tests {
404408
),
405409
("UPTIME_CHECKER_INTERFACE", "eth0"),
406410
("UPTIME_CHECKER_REDIS_READONLY", "true"),
411+
("UPTIME_CHECKER_WEBSERVER_PORT", "81"),
407412
],
408413
|config| {
409414
assert_eq!(
@@ -452,6 +457,7 @@ mod tests {
452457
redis_timeouts_ms: 30_000,
453458
enable_metrics: false,
454459
redis_readonly: true,
460+
webserver_port: 81,
455461
}
456462
);
457463
},

src/endpoint/execute_config.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::endpoint::EndpointState;
2+
use axum::{extract::State, response::IntoResponse, Json};
3+
use http::StatusCode;
4+
use serde::Serialize;
5+
use std::sync::Arc;
6+
7+
#[derive(Debug, Serialize)]
8+
#[serde(tag = "error")]
9+
#[serde(rename_all = "snake_case")]
10+
pub(crate) enum ExecuteError {
11+
Unknown,
12+
}
13+
14+
impl IntoResponse for ExecuteError {
15+
fn into_response(self) -> axum::response::Response {
16+
let status = match &self {
17+
ExecuteError::Unknown => StatusCode::INTERNAL_SERVER_ERROR,
18+
};
19+
20+
(status, Json(self)).into_response()
21+
}
22+
}
23+
24+
pub(crate) async fn execute_config(
25+
State(_state): State<Arc<EndpointState>>,
26+
) -> Result<(), ExecuteError> {
27+
Err(ExecuteError::Unknown)
28+
}

0 commit comments

Comments
 (0)