Skip to content

Commit 540cbc1

Browse files
authored
feat(health): exposing commit hash, features, uptime to the health (#394)
1 parent ae79632 commit 540cbc1

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

integration/integration.test.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ describe('blockchain api', () => {
2626
})
2727
describe('Health', () => {
2828
it('is healthy', async () => {
29-
const { status } = await http.get(`${baseUrl}/health`)
29+
const resp: any = await http.get(`${baseUrl}/health`)
3030

31-
expect(status).toBe(200)
31+
expect(resp.status).toBe(200)
32+
expect(resp.data).toContain('OK v')
33+
expect(resp.data).toContain('hash:')
34+
expect(resp.data).toContain('features:')
35+
expect(resp.data).toContain('uptime:')
3236
})
3337
})
3438
describe('Middlewares', () => {

src/handlers/health.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ use {
88
pub async fn handler(State(state): State<Arc<AppState>>) -> impl IntoResponse {
99
(
1010
StatusCode::OK,
11-
format!("OK v{}", state.compile_info.build().version()),
11+
format!(
12+
"OK v{}, commit hash: {}, features: {}, uptime: {:?} seconds",
13+
state.compile_info.build().version(),
14+
state.compile_info.git().short_hash(),
15+
state.compile_info.build().features(),
16+
state.uptime.elapsed().as_secs()
17+
),
1218
)
1319
}

src/state.rs

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub struct AppState {
2626
pub analytics: RPCAnalytics,
2727
pub compile_info: CompileInfo,
2828
pub ens_allowlist: Option<HashMap<H160, String>>,
29+
/// Service instance uptime measurement
30+
pub uptime: std::time::Instant,
2931
}
3032

3133
pub fn new_state(
@@ -46,6 +48,7 @@ pub fn new_state(
4648
analytics,
4749
compile_info: CompileInfo {},
4850
ens_allowlist,
51+
uptime: std::time::Instant::now(),
4952
}
5053
}
5154

0 commit comments

Comments
 (0)