trieve_client/apis/
metrics_api.rs

1/*
2 * Trieve API
3 *
4 * Trieve OpenAPI Specification. This document describes all of the operations available through the Trieve API.
5 *
6 * The version of the OpenAPI document: 0.11.7
7 * Contact: developers@trieve.ai
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method [`get_metrics`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum GetMetricsError {
22    Status500(models::ErrorResponseBody),
23    UnknownValue(serde_json::Value),
24}
25
26
27/// This route allows you to view the number of items in each queue in the Prometheus format.
28pub async fn get_metrics(configuration: &configuration::Configuration, ) -> Result<String, Error<GetMetricsError>> {
29    let local_var_configuration = configuration;
30
31    let local_var_client = &local_var_configuration.client;
32
33    let local_var_uri_str = format!("{}/metrics", local_var_configuration.base_path);
34    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
35
36    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
37        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
38    }
39    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
40        let local_var_key = local_var_apikey.key.clone();
41        let local_var_value = match local_var_apikey.prefix {
42            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
43            None => local_var_key,
44        };
45        local_var_req_builder = local_var_req_builder.header("X-API-KEY", local_var_value);
46    };
47
48    let local_var_req = local_var_req_builder.build()?;
49    let local_var_resp = local_var_client.execute(local_var_req).await?;
50
51    let local_var_status = local_var_resp.status();
52    let local_var_content = local_var_resp.text().await?;
53
54    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
55        serde_json::from_str(&local_var_content).map_err(Error::from)
56    } else {
57        let local_var_entity: Option<GetMetricsError> = serde_json::from_str(&local_var_content).ok();
58        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
59        Err(Error::ResponseError(local_var_error))
60    }
61}
62