1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use crate::{
    http::HttpError,
    sinks::{elasticsearch::service::ElasticsearchResponse, util::service::HealthLogic},
};

#[derive(Clone)]
pub struct ElasticsearchHealthLogic;

impl HealthLogic for ElasticsearchHealthLogic {
    type Error = crate::Error;
    type Response = ElasticsearchResponse;

    fn is_healthy(&self, response: &Result<Self::Response, Self::Error>) -> Option<bool> {
        match response {
            Ok(response) => {
                let status = response.http_response.status();
                if status.is_success() {
                    Some(true)
                } else if status.is_server_error() {
                    Some(false)
                } else {
                    None
                }
            }
            Err(error) => match error.downcast_ref::<HttpError>() {
                Some(HttpError::CallRequest { .. }) => Some(false),
                _ => None,
            },
        }
    }
}