vector/sinks/loki/
healthcheck.rs1use super::config::LokiConfig;
2use crate::http::HttpClient;
3
4async fn fetch_status(
5 endpoint: &str,
6 config: &LokiConfig,
7 client: &HttpClient,
8) -> crate::Result<http::StatusCode> {
9 let endpoint = config.endpoint.append_path(endpoint)?;
10
11 let mut req = http::Request::get(endpoint.uri)
12 .body(hyper::Body::empty())
13 .expect("Building request never fails.");
14
15 if let Some(auth) = &config.auth {
16 auth.apply(&mut req);
17 }
18
19 Ok(client.send(req).await?.status())
20}
21
22pub async fn healthcheck(config: LokiConfig, client: HttpClient) -> crate::Result<()> {
23 let status = match fetch_status("ready", &config, &client).await? {
24 http::StatusCode::NOT_FOUND => {
26 debug!("Endpoint `/ready` not found. Retrying healthcheck with top level query.");
27 fetch_status("", &config, &client).await?
28 }
29 status => status,
30 };
31
32 match status {
33 http::StatusCode::OK => Ok(()),
34 _ => Err(format!("A non-successful status returned: {status}").into()),
35 }
36}