fastly_api/apis/
insights_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 [`get_log_insights`]
15#[derive(Clone, Debug, Default)]
16pub struct GetLogInsightsParams {
17    pub visualization: String,
18    pub service_id: String,
19    pub start: String,
20    pub end: String,
21    pub pops: Option<String>,
22    pub domain: Option<String>,
23    pub domain_exact_match: Option<bool>,
24    pub limit: Option<f32>
25}
26
27
28/// struct for typed errors of method [`get_log_insights`]
29#[derive(Debug, Clone, Serialize, Deserialize)]
30#[serde(untagged)]
31pub enum GetLogInsightsError {
32    UnknownValue(serde_json::Value),
33}
34
35
36/// Retrieves statistics from sampled log records.
37pub async fn get_log_insights(configuration: &mut configuration::Configuration, params: GetLogInsightsParams) -> Result<crate::models::GetLogInsightsResponse, Error<GetLogInsightsError>> {
38    let local_var_configuration = configuration;
39
40    // unbox the parameters
41    let visualization = params.visualization;
42    let service_id = params.service_id;
43    let start = params.start;
44    let end = params.end;
45    let pops = params.pops;
46    let domain = params.domain;
47    let domain_exact_match = params.domain_exact_match;
48    let limit = params.limit;
49
50
51    let local_var_client = &local_var_configuration.client;
52
53    let local_var_uri_str = format!("{}/observability/log-insights", local_var_configuration.base_path);
54    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
55
56    local_var_req_builder = local_var_req_builder.query(&[("visualization", &visualization.to_string())]);
57    local_var_req_builder = local_var_req_builder.query(&[("service_id", &service_id.to_string())]);
58    local_var_req_builder = local_var_req_builder.query(&[("start", &start.to_string())]);
59    local_var_req_builder = local_var_req_builder.query(&[("end", &end.to_string())]);
60    if let Some(ref local_var_str) = pops {
61        local_var_req_builder = local_var_req_builder.query(&[("pops", &local_var_str.to_string())]);
62    }
63    if let Some(ref local_var_str) = domain {
64        local_var_req_builder = local_var_req_builder.query(&[("domain", &local_var_str.to_string())]);
65    }
66    if let Some(ref local_var_str) = domain_exact_match {
67        local_var_req_builder = local_var_req_builder.query(&[("domain_exact_match", &local_var_str.to_string())]);
68    }
69    if let Some(ref local_var_str) = limit {
70        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
71    }
72    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
73        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
74    }
75    if let Some(ref local_var_apikey) = local_var_configuration.api_key {
76        let local_var_key = local_var_apikey.key.clone();
77        let local_var_value = match local_var_apikey.prefix {
78            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
79            None => local_var_key,
80        };
81        local_var_req_builder = local_var_req_builder.header("Fastly-Key", local_var_value);
82    };
83
84    let local_var_req = local_var_req_builder.build()?;
85    let local_var_resp = local_var_client.execute(local_var_req).await?;
86
87    if "GET" != "GET" && "GET" != "HEAD" {
88      let headers = local_var_resp.headers();
89      local_var_configuration.rate_limit_remaining = match headers.get("Fastly-RateLimit-Remaining") {
90          Some(v) => v.to_str().unwrap().parse().unwrap(),
91          None => configuration::DEFAULT_RATELIMIT,
92      };
93      local_var_configuration.rate_limit_reset = match headers.get("Fastly-RateLimit-Reset") {
94          Some(v) => v.to_str().unwrap().parse().unwrap(),
95          None => 0,
96      };
97    }
98
99    let local_var_status = local_var_resp.status();
100    let local_var_content = local_var_resp.text().await?;
101
102    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
103        serde_json::from_str(&local_var_content).map_err(Error::from)
104    } else {
105        let local_var_entity: Option<GetLogInsightsError> = serde_json::from_str(&local_var_content).ok();
106        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
107        Err(Error::ResponseError(local_var_error))
108    }
109}
110