Feat/expose health and raft metrics
I want to expose the health and the raft state metrics
Two new gauges are added:
typesense_health: 1 if the target responds with 200 HTTP code and the response is {"ok": true}
# HELP typesense_health Health status of Typesense instance (1 = healthy, 0 = unhealthy)
# TYPE typesense_health gauge
and typesense_raft_state: 1 = leader, 4 = follower, 0 = other
# HELP typesense_raft_state Raft state of Typesense node (1 = leader, 4 = follower, 0 = other)
# TYPE typesense_raft_state gauge
This is useful as I am running Typesense in HA mode with 3 instances, and I need to configure alerts for a missing leader.
Also, I see that the metrics exporter defaults metric if the 401 response is sent:
Define default:
let mut stats_data: TypesenseStats = TypesenseStats::default();
Update if the HTTP code is 200
reqwest::StatusCode::OK => {
match res.json::<TypesenseStats>().await {
Ok(parsed) => {
stats_data = parsed;
}
Err(_) => println!("Hm, the response didn't match the shape we expected."),
};
}
Return
Ok(stats_data)
But if the response fails completely or times out, nothing happens I added the timeout for the request that is disabled by default and added the error handler for failed requests and timeouts
let res = match client
.get(url)
.header("X-TYPESENSE-API-KEY", format!("{}", args.typesense_api_key))
.send()
.await
{
Ok(res) => res,
Err(e) => {
println!("Stats endpoint: request failed (timeout/connection error): {:?}", e);
return Ok(stats_data);
}
};
This is also related to this issue: https://github.com/imatefx/typesense-prometheus-exporter/issues/2