fastly_api/apis/
observability_aggregations_for_logs_api.rs

1/*
2 * Fastly API
3 *
4 * Via the Fastly API you can perform any of the operations that are possible within the management console,  including creating services, domains, and backends, configuring rules or uploading your own application code, as well as account operations such as user administration and billing reports. The API is organized into collections of endpoints that allow manipulation of objects related to Fastly services and accounts. For the most accurate and up-to-date API reference content, visit our [Developer Hub](https://www.fastly.com/documentation/reference/api/) 
5 *
6 */
7
8
9use reqwest;
10
11use crate::apis::ResponseContent;
12use super::{Error, configuration};
13
14/// struct for passing parameters to the method [`log_aggregations_get`]
15#[derive(Clone, Debug, Default)]
16pub struct LogAggregationsGetParams {
17    pub source: String,
18    pub service_id: String,
19    pub start: String,
20    pub end: String,
21    pub series: String,
22    pub limit: Option<f32>,
23    pub filter: Option<String>,
24    pub dimensions: Option<String>,
25    pub sort: Option<String>
26}
27
28
29/// struct for typed errors of method [`log_aggregations_get`]
30#[derive(Debug, Clone, Serialize, Deserialize)]
31#[serde(untagged)]
32pub enum LogAggregationsGetError {
33    UnknownValue(serde_json::Value),
34}
35
36
37/// Retrieves aggregated log results.
38pub async fn log_aggregations_get(configuration: &mut configuration::Configuration, params: LogAggregationsGetParams) -> Result<crate::models::LogAggregationsGetResponse, Error<LogAggregationsGetError>> {
39    let local_var_configuration = configuration;
40
41    // unbox the parameters
42    let source = params.source;
43    let service_id = params.service_id;
44    let start = params.start;
45    let end = params.end;
46    let series = params.series;
47    let limit = params.limit;
48    let filter = params.filter;
49    let dimensions = params.dimensions;
50    let sort = params.sort;
51
52
53    let local_var_client = &local_var_configuration.client;
54
55    let local_var_uri_str = format!("{}/observability/aggregations", local_var_configuration.base_path);
56    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
57
58    local_var_req_builder = local_var_req_builder.query(&[("source", &source.to_string())]);
59    local_var_req_builder = local_var_req_builder.query(&[("service_id", &service_id.to_string())]);
60    local_var_req_builder = local_var_req_builder.query(&[("start", &start.to_string())]);
61    local_var_req_builder = local_var_req_builder.query(&[("end", &end.to_string())]);
62    if let Some(ref local_var_str) = limit {
63        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
64    }
65    if let Some(ref local_var_str) = filter {
66        local_var_req_builder = local_var_req_builder.query(&[("filter", &local_var_str.to_string())]);
67    }
68    local_var_req_builder = local_var_req_builder.query(&[("series", &series.to_string())]);
69    if let Some(ref local_var_str) = dimensions {
70        local_var_req_builder = local_var_req_builder.query(&[("dimensions", &local_var_str.to_string())]);
71    }
72    if let Some(ref local_var_str) = sort {
73        local_var_req_builder = local_var_req_builder.query(&[("sort", &local_var_str.to_string())]);
74    }
75    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
76        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
77    }
78    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
79        let local_var_key = local_var_apikey.key.clone();
80        let local_var_value = match local_var_apikey.prefix {
81            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
82            None => local_var_key,
83        };
84        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
85    };
86
87    let local_var_req = local_var_req_builder.build()?;
88    let local_var_resp = local_var_client.execute(local_var_req).await?;
89
90    if "GET" != "GET" && "GET" != "HEAD" {
91      let headers = local_var_resp.headers();
92      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
93          Some(v) => v.to_str().unwrap().parse().unwrap(),
94          None => configuration::DEFAULT_RATELIMIT,
95      };
96      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
97          Some(v) => v.to_str().unwrap().parse().unwrap(),
98          None => 0,
99      };
100    }
101
102    let local_var_status = local_var_resp.status();
103    let local_var_content = local_var_resp.text().await?;
104
105    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
106        serde_json::from_str(&local_var_content).map_err(Error::from)
107    } else {
108        let local_var_entity: Option<LogAggregationsGetError> = serde_json::from_str(&local_var_content).ok();
109        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
110        Err(Error::ResponseError(local_var_error))
111    }
112}
113