1use crate::datadog;
5use async_stream::try_stream;
6use flate2::{
7 write::{GzEncoder, ZlibEncoder},
8 Compression,
9};
10use futures_core::stream::Stream;
11use reqwest::header::{HeaderMap, HeaderValue};
12use serde::{Deserialize, Serialize};
13use std::io::Write;
14
15#[non_exhaustive]
17#[derive(Clone, Default, Debug)]
18pub struct EstimateMetricsOutputSeriesOptionalParams {
19 pub filter_groups: Option<String>,
21 pub filter_hours_ago: Option<i32>,
23 pub filter_num_aggregations: Option<i32>,
25 pub filter_pct: Option<bool>,
27 pub filter_timespan_h: Option<i32>,
29}
30
31impl EstimateMetricsOutputSeriesOptionalParams {
32 pub fn filter_groups(mut self, value: String) -> Self {
34 self.filter_groups = Some(value);
35 self
36 }
37 pub fn filter_hours_ago(mut self, value: i32) -> Self {
39 self.filter_hours_ago = Some(value);
40 self
41 }
42 pub fn filter_num_aggregations(mut self, value: i32) -> Self {
44 self.filter_num_aggregations = Some(value);
45 self
46 }
47 pub fn filter_pct(mut self, value: bool) -> Self {
49 self.filter_pct = Some(value);
50 self
51 }
52 pub fn filter_timespan_h(mut self, value: i32) -> Self {
54 self.filter_timespan_h = Some(value);
55 self
56 }
57}
58
59#[non_exhaustive]
61#[derive(Clone, Default, Debug)]
62pub struct ListActiveMetricConfigurationsOptionalParams {
63 pub window_seconds: Option<i64>,
66}
67
68impl ListActiveMetricConfigurationsOptionalParams {
69 pub fn window_seconds(mut self, value: i64) -> Self {
72 self.window_seconds = Some(value);
73 self
74 }
75}
76
77#[non_exhaustive]
79#[derive(Clone, Default, Debug)]
80pub struct ListTagConfigurationsOptionalParams {
81 pub filter_configured: Option<bool>,
83 pub filter_tags_configured: Option<String>,
85 pub filter_metric_type:
87 Option<crate::datadogV2::model::MetricTagConfigurationMetricTypeCategory>,
88 pub filter_include_percentiles: Option<bool>,
91 pub filter_queried: Option<bool>,
94 pub filter_tags: Option<String>,
97 pub filter_related_assets: Option<bool>,
99 pub window_seconds: Option<i64>,
102 pub page_size: Option<i32>,
104 pub page_cursor: Option<String>,
108}
109
110impl ListTagConfigurationsOptionalParams {
111 pub fn filter_configured(mut self, value: bool) -> Self {
113 self.filter_configured = Some(value);
114 self
115 }
116 pub fn filter_tags_configured(mut self, value: String) -> Self {
118 self.filter_tags_configured = Some(value);
119 self
120 }
121 pub fn filter_metric_type(
123 mut self,
124 value: crate::datadogV2::model::MetricTagConfigurationMetricTypeCategory,
125 ) -> Self {
126 self.filter_metric_type = Some(value);
127 self
128 }
129 pub fn filter_include_percentiles(mut self, value: bool) -> Self {
132 self.filter_include_percentiles = Some(value);
133 self
134 }
135 pub fn filter_queried(mut self, value: bool) -> Self {
138 self.filter_queried = Some(value);
139 self
140 }
141 pub fn filter_tags(mut self, value: String) -> Self {
144 self.filter_tags = Some(value);
145 self
146 }
147 pub fn filter_related_assets(mut self, value: bool) -> Self {
149 self.filter_related_assets = Some(value);
150 self
151 }
152 pub fn window_seconds(mut self, value: i64) -> Self {
155 self.window_seconds = Some(value);
156 self
157 }
158 pub fn page_size(mut self, value: i32) -> Self {
160 self.page_size = Some(value);
161 self
162 }
163 pub fn page_cursor(mut self, value: String) -> Self {
167 self.page_cursor = Some(value);
168 self
169 }
170}
171
172#[non_exhaustive]
174#[derive(Clone, Default, Debug)]
175pub struct SubmitMetricsOptionalParams {
176 pub content_encoding: Option<crate::datadogV2::model::MetricContentEncoding>,
178}
179
180impl SubmitMetricsOptionalParams {
181 pub fn content_encoding(
183 mut self,
184 value: crate::datadogV2::model::MetricContentEncoding,
185 ) -> Self {
186 self.content_encoding = Some(value);
187 self
188 }
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize)]
193#[serde(untagged)]
194pub enum CreateBulkTagsMetricsConfigurationError {
195 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
196 UnknownValue(serde_json::Value),
197}
198
199#[derive(Debug, Clone, Serialize, Deserialize)]
201#[serde(untagged)]
202pub enum CreateTagConfigurationError {
203 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
204 UnknownValue(serde_json::Value),
205}
206
207#[derive(Debug, Clone, Serialize, Deserialize)]
209#[serde(untagged)]
210pub enum DeleteBulkTagsMetricsConfigurationError {
211 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
212 UnknownValue(serde_json::Value),
213}
214
215#[derive(Debug, Clone, Serialize, Deserialize)]
217#[serde(untagged)]
218pub enum DeleteTagConfigurationError {
219 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
220 UnknownValue(serde_json::Value),
221}
222
223#[derive(Debug, Clone, Serialize, Deserialize)]
225#[serde(untagged)]
226pub enum EstimateMetricsOutputSeriesError {
227 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
228 UnknownValue(serde_json::Value),
229}
230
231#[derive(Debug, Clone, Serialize, Deserialize)]
233#[serde(untagged)]
234pub enum ListActiveMetricConfigurationsError {
235 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
236 UnknownValue(serde_json::Value),
237}
238
239#[derive(Debug, Clone, Serialize, Deserialize)]
241#[serde(untagged)]
242pub enum ListMetricAssetsError {
243 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
244 UnknownValue(serde_json::Value),
245}
246
247#[derive(Debug, Clone, Serialize, Deserialize)]
249#[serde(untagged)]
250pub enum ListTagConfigurationByNameError {
251 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
252 UnknownValue(serde_json::Value),
253}
254
255#[derive(Debug, Clone, Serialize, Deserialize)]
257#[serde(untagged)]
258pub enum ListTagConfigurationsError {
259 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
260 UnknownValue(serde_json::Value),
261}
262
263#[derive(Debug, Clone, Serialize, Deserialize)]
265#[serde(untagged)]
266pub enum ListTagsByMetricNameError {
267 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
268 UnknownValue(serde_json::Value),
269}
270
271#[derive(Debug, Clone, Serialize, Deserialize)]
273#[serde(untagged)]
274pub enum ListVolumesByMetricNameError {
275 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
276 UnknownValue(serde_json::Value),
277}
278
279#[derive(Debug, Clone, Serialize, Deserialize)]
281#[serde(untagged)]
282pub enum QueryScalarDataError {
283 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
284 UnknownValue(serde_json::Value),
285}
286
287#[derive(Debug, Clone, Serialize, Deserialize)]
289#[serde(untagged)]
290pub enum QueryTimeseriesDataError {
291 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
292 UnknownValue(serde_json::Value),
293}
294
295#[derive(Debug, Clone, Serialize, Deserialize)]
297#[serde(untagged)]
298pub enum SubmitMetricsError {
299 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
300 UnknownValue(serde_json::Value),
301}
302
303#[derive(Debug, Clone, Serialize, Deserialize)]
305#[serde(untagged)]
306pub enum UpdateTagConfigurationError {
307 APIErrorResponse(crate::datadogV2::model::APIErrorResponse),
308 UnknownValue(serde_json::Value),
309}
310
311#[derive(Debug, Clone)]
327pub struct MetricsAPI {
328 config: datadog::Configuration,
329 client: reqwest_middleware::ClientWithMiddleware,
330}
331
332impl Default for MetricsAPI {
333 fn default() -> Self {
334 Self::with_config(datadog::Configuration::default())
335 }
336}
337
338impl MetricsAPI {
339 pub fn new() -> Self {
340 Self::default()
341 }
342 pub fn with_config(config: datadog::Configuration) -> Self {
343 let mut reqwest_client_builder = reqwest::Client::builder();
344
345 if let Some(proxy_url) = &config.proxy_url {
346 let proxy = reqwest::Proxy::all(proxy_url).expect("Failed to parse proxy URL");
347 reqwest_client_builder = reqwest_client_builder.proxy(proxy);
348 }
349
350 let mut middleware_client_builder =
351 reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
352
353 if config.enable_retry {
354 struct RetryableStatus;
355 impl reqwest_retry::RetryableStrategy for RetryableStatus {
356 fn handle(
357 &self,
358 res: &Result<reqwest::Response, reqwest_middleware::Error>,
359 ) -> Option<reqwest_retry::Retryable> {
360 match res {
361 Ok(success) => reqwest_retry::default_on_request_success(success),
362 Err(_) => None,
363 }
364 }
365 }
366 let backoff_policy = reqwest_retry::policies::ExponentialBackoff::builder()
367 .build_with_max_retries(config.max_retries);
368
369 let retry_middleware =
370 reqwest_retry::RetryTransientMiddleware::new_with_policy_and_strategy(
371 backoff_policy,
372 RetryableStatus,
373 );
374
375 middleware_client_builder = middleware_client_builder.with(retry_middleware);
376 }
377
378 let client = middleware_client_builder.build();
379
380 Self { config, client }
381 }
382
383 pub fn with_client_and_config(
384 config: datadog::Configuration,
385 client: reqwest_middleware::ClientWithMiddleware,
386 ) -> Self {
387 Self { config, client }
388 }
389
390 pub async fn create_bulk_tags_metrics_configuration(
398 &self,
399 body: crate::datadogV2::model::MetricBulkTagConfigCreateRequest,
400 ) -> Result<
401 crate::datadogV2::model::MetricBulkTagConfigResponse,
402 datadog::Error<CreateBulkTagsMetricsConfigurationError>,
403 > {
404 match self
405 .create_bulk_tags_metrics_configuration_with_http_info(body)
406 .await
407 {
408 Ok(response_content) => {
409 if let Some(e) = response_content.entity {
410 Ok(e)
411 } else {
412 Err(datadog::Error::Serde(serde::de::Error::custom(
413 "response content was None",
414 )))
415 }
416 }
417 Err(err) => Err(err),
418 }
419 }
420
421 pub async fn create_bulk_tags_metrics_configuration_with_http_info(
429 &self,
430 body: crate::datadogV2::model::MetricBulkTagConfigCreateRequest,
431 ) -> Result<
432 datadog::ResponseContent<crate::datadogV2::model::MetricBulkTagConfigResponse>,
433 datadog::Error<CreateBulkTagsMetricsConfigurationError>,
434 > {
435 let local_configuration = &self.config;
436 let operation_id = "v2.create_bulk_tags_metrics_configuration";
437
438 let local_client = &self.client;
439
440 let local_uri_str = format!(
441 "{}/api/v2/metrics/config/bulk-tags",
442 local_configuration.get_operation_host(operation_id)
443 );
444 let mut local_req_builder =
445 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
446
447 let mut headers = HeaderMap::new();
449 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
450 headers.insert("Accept", HeaderValue::from_static("application/json"));
451
452 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
454 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
455 Err(e) => {
456 log::warn!("Failed to parse user agent header: {e}, falling back to default");
457 headers.insert(
458 reqwest::header::USER_AGENT,
459 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
460 )
461 }
462 };
463
464 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
466 headers.insert(
467 "DD-API-KEY",
468 HeaderValue::from_str(local_key.key.as_str())
469 .expect("failed to parse DD-API-KEY header"),
470 );
471 };
472 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
473 headers.insert(
474 "DD-APPLICATION-KEY",
475 HeaderValue::from_str(local_key.key.as_str())
476 .expect("failed to parse DD-APPLICATION-KEY header"),
477 );
478 };
479
480 let output = Vec::new();
482 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
483 if body.serialize(&mut ser).is_ok() {
484 if let Some(content_encoding) = headers.get("Content-Encoding") {
485 match content_encoding.to_str().unwrap_or_default() {
486 "gzip" => {
487 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
488 let _ = enc.write_all(ser.into_inner().as_slice());
489 match enc.finish() {
490 Ok(buf) => {
491 local_req_builder = local_req_builder.body(buf);
492 }
493 Err(e) => return Err(datadog::Error::Io(e)),
494 }
495 }
496 "deflate" => {
497 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
498 let _ = enc.write_all(ser.into_inner().as_slice());
499 match enc.finish() {
500 Ok(buf) => {
501 local_req_builder = local_req_builder.body(buf);
502 }
503 Err(e) => return Err(datadog::Error::Io(e)),
504 }
505 }
506 "zstd1" => {
507 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
508 let _ = enc.write_all(ser.into_inner().as_slice());
509 match enc.finish() {
510 Ok(buf) => {
511 local_req_builder = local_req_builder.body(buf);
512 }
513 Err(e) => return Err(datadog::Error::Io(e)),
514 }
515 }
516 _ => {
517 local_req_builder = local_req_builder.body(ser.into_inner());
518 }
519 }
520 } else {
521 local_req_builder = local_req_builder.body(ser.into_inner());
522 }
523 }
524
525 local_req_builder = local_req_builder.headers(headers);
526 let local_req = local_req_builder.build()?;
527 log::debug!("request content: {:?}", local_req.body());
528 let local_resp = local_client.execute(local_req).await?;
529
530 let local_status = local_resp.status();
531 let local_content = local_resp.text().await?;
532 log::debug!("response content: {}", local_content);
533
534 if !local_status.is_client_error() && !local_status.is_server_error() {
535 match serde_json::from_str::<crate::datadogV2::model::MetricBulkTagConfigResponse>(
536 &local_content,
537 ) {
538 Ok(e) => {
539 return Ok(datadog::ResponseContent {
540 status: local_status,
541 content: local_content,
542 entity: Some(e),
543 })
544 }
545 Err(e) => return Err(datadog::Error::Serde(e)),
546 };
547 } else {
548 let local_entity: Option<CreateBulkTagsMetricsConfigurationError> =
549 serde_json::from_str(&local_content).ok();
550 let local_error = datadog::ResponseContent {
551 status: local_status,
552 content: local_content,
553 entity: local_entity,
554 };
555 Err(datadog::Error::ResponseError(local_error))
556 }
557 }
558
559 pub async fn create_tag_configuration(
565 &self,
566 metric_name: String,
567 body: crate::datadogV2::model::MetricTagConfigurationCreateRequest,
568 ) -> Result<
569 crate::datadogV2::model::MetricTagConfigurationResponse,
570 datadog::Error<CreateTagConfigurationError>,
571 > {
572 match self
573 .create_tag_configuration_with_http_info(metric_name, body)
574 .await
575 {
576 Ok(response_content) => {
577 if let Some(e) = response_content.entity {
578 Ok(e)
579 } else {
580 Err(datadog::Error::Serde(serde::de::Error::custom(
581 "response content was None",
582 )))
583 }
584 }
585 Err(err) => Err(err),
586 }
587 }
588
589 pub async fn create_tag_configuration_with_http_info(
595 &self,
596 metric_name: String,
597 body: crate::datadogV2::model::MetricTagConfigurationCreateRequest,
598 ) -> Result<
599 datadog::ResponseContent<crate::datadogV2::model::MetricTagConfigurationResponse>,
600 datadog::Error<CreateTagConfigurationError>,
601 > {
602 let local_configuration = &self.config;
603 let operation_id = "v2.create_tag_configuration";
604
605 let local_client = &self.client;
606
607 let local_uri_str = format!(
608 "{}/api/v2/metrics/{metric_name}/tags",
609 local_configuration.get_operation_host(operation_id),
610 metric_name = datadog::urlencode(metric_name)
611 );
612 let mut local_req_builder =
613 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
614
615 let mut headers = HeaderMap::new();
617 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
618 headers.insert("Accept", HeaderValue::from_static("application/json"));
619
620 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
622 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
623 Err(e) => {
624 log::warn!("Failed to parse user agent header: {e}, falling back to default");
625 headers.insert(
626 reqwest::header::USER_AGENT,
627 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
628 )
629 }
630 };
631
632 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
634 headers.insert(
635 "DD-API-KEY",
636 HeaderValue::from_str(local_key.key.as_str())
637 .expect("failed to parse DD-API-KEY header"),
638 );
639 };
640 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
641 headers.insert(
642 "DD-APPLICATION-KEY",
643 HeaderValue::from_str(local_key.key.as_str())
644 .expect("failed to parse DD-APPLICATION-KEY header"),
645 );
646 };
647
648 let output = Vec::new();
650 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
651 if body.serialize(&mut ser).is_ok() {
652 if let Some(content_encoding) = headers.get("Content-Encoding") {
653 match content_encoding.to_str().unwrap_or_default() {
654 "gzip" => {
655 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
656 let _ = enc.write_all(ser.into_inner().as_slice());
657 match enc.finish() {
658 Ok(buf) => {
659 local_req_builder = local_req_builder.body(buf);
660 }
661 Err(e) => return Err(datadog::Error::Io(e)),
662 }
663 }
664 "deflate" => {
665 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
666 let _ = enc.write_all(ser.into_inner().as_slice());
667 match enc.finish() {
668 Ok(buf) => {
669 local_req_builder = local_req_builder.body(buf);
670 }
671 Err(e) => return Err(datadog::Error::Io(e)),
672 }
673 }
674 "zstd1" => {
675 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
676 let _ = enc.write_all(ser.into_inner().as_slice());
677 match enc.finish() {
678 Ok(buf) => {
679 local_req_builder = local_req_builder.body(buf);
680 }
681 Err(e) => return Err(datadog::Error::Io(e)),
682 }
683 }
684 _ => {
685 local_req_builder = local_req_builder.body(ser.into_inner());
686 }
687 }
688 } else {
689 local_req_builder = local_req_builder.body(ser.into_inner());
690 }
691 }
692
693 local_req_builder = local_req_builder.headers(headers);
694 let local_req = local_req_builder.build()?;
695 log::debug!("request content: {:?}", local_req.body());
696 let local_resp = local_client.execute(local_req).await?;
697
698 let local_status = local_resp.status();
699 let local_content = local_resp.text().await?;
700 log::debug!("response content: {}", local_content);
701
702 if !local_status.is_client_error() && !local_status.is_server_error() {
703 match serde_json::from_str::<crate::datadogV2::model::MetricTagConfigurationResponse>(
704 &local_content,
705 ) {
706 Ok(e) => {
707 return Ok(datadog::ResponseContent {
708 status: local_status,
709 content: local_content,
710 entity: Some(e),
711 })
712 }
713 Err(e) => return Err(datadog::Error::Serde(e)),
714 };
715 } else {
716 let local_entity: Option<CreateTagConfigurationError> =
717 serde_json::from_str(&local_content).ok();
718 let local_error = datadog::ResponseContent {
719 status: local_status,
720 content: local_content,
721 entity: local_entity,
722 };
723 Err(datadog::Error::ResponseError(local_error))
724 }
725 }
726
727 pub async fn delete_bulk_tags_metrics_configuration(
732 &self,
733 body: crate::datadogV2::model::MetricBulkTagConfigDeleteRequest,
734 ) -> Result<
735 crate::datadogV2::model::MetricBulkTagConfigResponse,
736 datadog::Error<DeleteBulkTagsMetricsConfigurationError>,
737 > {
738 match self
739 .delete_bulk_tags_metrics_configuration_with_http_info(body)
740 .await
741 {
742 Ok(response_content) => {
743 if let Some(e) = response_content.entity {
744 Ok(e)
745 } else {
746 Err(datadog::Error::Serde(serde::de::Error::custom(
747 "response content was None",
748 )))
749 }
750 }
751 Err(err) => Err(err),
752 }
753 }
754
755 pub async fn delete_bulk_tags_metrics_configuration_with_http_info(
760 &self,
761 body: crate::datadogV2::model::MetricBulkTagConfigDeleteRequest,
762 ) -> Result<
763 datadog::ResponseContent<crate::datadogV2::model::MetricBulkTagConfigResponse>,
764 datadog::Error<DeleteBulkTagsMetricsConfigurationError>,
765 > {
766 let local_configuration = &self.config;
767 let operation_id = "v2.delete_bulk_tags_metrics_configuration";
768
769 let local_client = &self.client;
770
771 let local_uri_str = format!(
772 "{}/api/v2/metrics/config/bulk-tags",
773 local_configuration.get_operation_host(operation_id)
774 );
775 let mut local_req_builder =
776 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
777
778 let mut headers = HeaderMap::new();
780 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
781 headers.insert("Accept", HeaderValue::from_static("application/json"));
782
783 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
785 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
786 Err(e) => {
787 log::warn!("Failed to parse user agent header: {e}, falling back to default");
788 headers.insert(
789 reqwest::header::USER_AGENT,
790 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
791 )
792 }
793 };
794
795 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
797 headers.insert(
798 "DD-API-KEY",
799 HeaderValue::from_str(local_key.key.as_str())
800 .expect("failed to parse DD-API-KEY header"),
801 );
802 };
803 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
804 headers.insert(
805 "DD-APPLICATION-KEY",
806 HeaderValue::from_str(local_key.key.as_str())
807 .expect("failed to parse DD-APPLICATION-KEY header"),
808 );
809 };
810
811 let output = Vec::new();
813 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
814 if body.serialize(&mut ser).is_ok() {
815 if let Some(content_encoding) = headers.get("Content-Encoding") {
816 match content_encoding.to_str().unwrap_or_default() {
817 "gzip" => {
818 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
819 let _ = enc.write_all(ser.into_inner().as_slice());
820 match enc.finish() {
821 Ok(buf) => {
822 local_req_builder = local_req_builder.body(buf);
823 }
824 Err(e) => return Err(datadog::Error::Io(e)),
825 }
826 }
827 "deflate" => {
828 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
829 let _ = enc.write_all(ser.into_inner().as_slice());
830 match enc.finish() {
831 Ok(buf) => {
832 local_req_builder = local_req_builder.body(buf);
833 }
834 Err(e) => return Err(datadog::Error::Io(e)),
835 }
836 }
837 "zstd1" => {
838 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
839 let _ = enc.write_all(ser.into_inner().as_slice());
840 match enc.finish() {
841 Ok(buf) => {
842 local_req_builder = local_req_builder.body(buf);
843 }
844 Err(e) => return Err(datadog::Error::Io(e)),
845 }
846 }
847 _ => {
848 local_req_builder = local_req_builder.body(ser.into_inner());
849 }
850 }
851 } else {
852 local_req_builder = local_req_builder.body(ser.into_inner());
853 }
854 }
855
856 local_req_builder = local_req_builder.headers(headers);
857 let local_req = local_req_builder.build()?;
858 log::debug!("request content: {:?}", local_req.body());
859 let local_resp = local_client.execute(local_req).await?;
860
861 let local_status = local_resp.status();
862 let local_content = local_resp.text().await?;
863 log::debug!("response content: {}", local_content);
864
865 if !local_status.is_client_error() && !local_status.is_server_error() {
866 match serde_json::from_str::<crate::datadogV2::model::MetricBulkTagConfigResponse>(
867 &local_content,
868 ) {
869 Ok(e) => {
870 return Ok(datadog::ResponseContent {
871 status: local_status,
872 content: local_content,
873 entity: Some(e),
874 })
875 }
876 Err(e) => return Err(datadog::Error::Serde(e)),
877 };
878 } else {
879 let local_entity: Option<DeleteBulkTagsMetricsConfigurationError> =
880 serde_json::from_str(&local_content).ok();
881 let local_error = datadog::ResponseContent {
882 status: local_status,
883 content: local_content,
884 entity: local_entity,
885 };
886 Err(datadog::Error::ResponseError(local_error))
887 }
888 }
889
890 pub async fn delete_tag_configuration(
893 &self,
894 metric_name: String,
895 ) -> Result<(), datadog::Error<DeleteTagConfigurationError>> {
896 match self
897 .delete_tag_configuration_with_http_info(metric_name)
898 .await
899 {
900 Ok(_) => Ok(()),
901 Err(err) => Err(err),
902 }
903 }
904
905 pub async fn delete_tag_configuration_with_http_info(
908 &self,
909 metric_name: String,
910 ) -> Result<datadog::ResponseContent<()>, datadog::Error<DeleteTagConfigurationError>> {
911 let local_configuration = &self.config;
912 let operation_id = "v2.delete_tag_configuration";
913
914 let local_client = &self.client;
915
916 let local_uri_str = format!(
917 "{}/api/v2/metrics/{metric_name}/tags",
918 local_configuration.get_operation_host(operation_id),
919 metric_name = datadog::urlencode(metric_name)
920 );
921 let mut local_req_builder =
922 local_client.request(reqwest::Method::DELETE, local_uri_str.as_str());
923
924 let mut headers = HeaderMap::new();
926 headers.insert("Accept", HeaderValue::from_static("*/*"));
927
928 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
930 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
931 Err(e) => {
932 log::warn!("Failed to parse user agent header: {e}, falling back to default");
933 headers.insert(
934 reqwest::header::USER_AGENT,
935 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
936 )
937 }
938 };
939
940 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
942 headers.insert(
943 "DD-API-KEY",
944 HeaderValue::from_str(local_key.key.as_str())
945 .expect("failed to parse DD-API-KEY header"),
946 );
947 };
948 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
949 headers.insert(
950 "DD-APPLICATION-KEY",
951 HeaderValue::from_str(local_key.key.as_str())
952 .expect("failed to parse DD-APPLICATION-KEY header"),
953 );
954 };
955
956 local_req_builder = local_req_builder.headers(headers);
957 let local_req = local_req_builder.build()?;
958 log::debug!("request content: {:?}", local_req.body());
959 let local_resp = local_client.execute(local_req).await?;
960
961 let local_status = local_resp.status();
962 let local_content = local_resp.text().await?;
963 log::debug!("response content: {}", local_content);
964
965 if !local_status.is_client_error() && !local_status.is_server_error() {
966 Ok(datadog::ResponseContent {
967 status: local_status,
968 content: local_content,
969 entity: None,
970 })
971 } else {
972 let local_entity: Option<DeleteTagConfigurationError> =
973 serde_json::from_str(&local_content).ok();
974 let local_error = datadog::ResponseContent {
975 status: local_status,
976 content: local_content,
977 entity: local_entity,
978 };
979 Err(datadog::Error::ResponseError(local_error))
980 }
981 }
982
983 pub async fn estimate_metrics_output_series(
985 &self,
986 metric_name: String,
987 params: EstimateMetricsOutputSeriesOptionalParams,
988 ) -> Result<
989 crate::datadogV2::model::MetricEstimateResponse,
990 datadog::Error<EstimateMetricsOutputSeriesError>,
991 > {
992 match self
993 .estimate_metrics_output_series_with_http_info(metric_name, params)
994 .await
995 {
996 Ok(response_content) => {
997 if let Some(e) = response_content.entity {
998 Ok(e)
999 } else {
1000 Err(datadog::Error::Serde(serde::de::Error::custom(
1001 "response content was None",
1002 )))
1003 }
1004 }
1005 Err(err) => Err(err),
1006 }
1007 }
1008
1009 pub async fn estimate_metrics_output_series_with_http_info(
1011 &self,
1012 metric_name: String,
1013 params: EstimateMetricsOutputSeriesOptionalParams,
1014 ) -> Result<
1015 datadog::ResponseContent<crate::datadogV2::model::MetricEstimateResponse>,
1016 datadog::Error<EstimateMetricsOutputSeriesError>,
1017 > {
1018 let local_configuration = &self.config;
1019 let operation_id = "v2.estimate_metrics_output_series";
1020
1021 let filter_groups = params.filter_groups;
1023 let filter_hours_ago = params.filter_hours_ago;
1024 let filter_num_aggregations = params.filter_num_aggregations;
1025 let filter_pct = params.filter_pct;
1026 let filter_timespan_h = params.filter_timespan_h;
1027
1028 let local_client = &self.client;
1029
1030 let local_uri_str = format!(
1031 "{}/api/v2/metrics/{metric_name}/estimate",
1032 local_configuration.get_operation_host(operation_id),
1033 metric_name = datadog::urlencode(metric_name)
1034 );
1035 let mut local_req_builder =
1036 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1037
1038 if let Some(ref local_query_param) = filter_groups {
1039 local_req_builder =
1040 local_req_builder.query(&[("filter[groups]", &local_query_param.to_string())]);
1041 };
1042 if let Some(ref local_query_param) = filter_hours_ago {
1043 local_req_builder =
1044 local_req_builder.query(&[("filter[hours_ago]", &local_query_param.to_string())]);
1045 };
1046 if let Some(ref local_query_param) = filter_num_aggregations {
1047 local_req_builder = local_req_builder
1048 .query(&[("filter[num_aggregations]", &local_query_param.to_string())]);
1049 };
1050 if let Some(ref local_query_param) = filter_pct {
1051 local_req_builder =
1052 local_req_builder.query(&[("filter[pct]", &local_query_param.to_string())]);
1053 };
1054 if let Some(ref local_query_param) = filter_timespan_h {
1055 local_req_builder =
1056 local_req_builder.query(&[("filter[timespan_h]", &local_query_param.to_string())]);
1057 };
1058
1059 let mut headers = HeaderMap::new();
1061 headers.insert("Accept", HeaderValue::from_static("application/json"));
1062
1063 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1065 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1066 Err(e) => {
1067 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1068 headers.insert(
1069 reqwest::header::USER_AGENT,
1070 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1071 )
1072 }
1073 };
1074
1075 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1077 headers.insert(
1078 "DD-API-KEY",
1079 HeaderValue::from_str(local_key.key.as_str())
1080 .expect("failed to parse DD-API-KEY header"),
1081 );
1082 };
1083 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1084 headers.insert(
1085 "DD-APPLICATION-KEY",
1086 HeaderValue::from_str(local_key.key.as_str())
1087 .expect("failed to parse DD-APPLICATION-KEY header"),
1088 );
1089 };
1090
1091 local_req_builder = local_req_builder.headers(headers);
1092 let local_req = local_req_builder.build()?;
1093 log::debug!("request content: {:?}", local_req.body());
1094 let local_resp = local_client.execute(local_req).await?;
1095
1096 let local_status = local_resp.status();
1097 let local_content = local_resp.text().await?;
1098 log::debug!("response content: {}", local_content);
1099
1100 if !local_status.is_client_error() && !local_status.is_server_error() {
1101 match serde_json::from_str::<crate::datadogV2::model::MetricEstimateResponse>(
1102 &local_content,
1103 ) {
1104 Ok(e) => {
1105 return Ok(datadog::ResponseContent {
1106 status: local_status,
1107 content: local_content,
1108 entity: Some(e),
1109 })
1110 }
1111 Err(e) => return Err(datadog::Error::Serde(e)),
1112 };
1113 } else {
1114 let local_entity: Option<EstimateMetricsOutputSeriesError> =
1115 serde_json::from_str(&local_content).ok();
1116 let local_error = datadog::ResponseContent {
1117 status: local_status,
1118 content: local_content,
1119 entity: local_entity,
1120 };
1121 Err(datadog::Error::ResponseError(local_error))
1122 }
1123 }
1124
1125 pub async fn list_active_metric_configurations(
1127 &self,
1128 metric_name: String,
1129 params: ListActiveMetricConfigurationsOptionalParams,
1130 ) -> Result<
1131 crate::datadogV2::model::MetricSuggestedTagsAndAggregationsResponse,
1132 datadog::Error<ListActiveMetricConfigurationsError>,
1133 > {
1134 match self
1135 .list_active_metric_configurations_with_http_info(metric_name, params)
1136 .await
1137 {
1138 Ok(response_content) => {
1139 if let Some(e) = response_content.entity {
1140 Ok(e)
1141 } else {
1142 Err(datadog::Error::Serde(serde::de::Error::custom(
1143 "response content was None",
1144 )))
1145 }
1146 }
1147 Err(err) => Err(err),
1148 }
1149 }
1150
1151 pub async fn list_active_metric_configurations_with_http_info(
1153 &self,
1154 metric_name: String,
1155 params: ListActiveMetricConfigurationsOptionalParams,
1156 ) -> Result<
1157 datadog::ResponseContent<
1158 crate::datadogV2::model::MetricSuggestedTagsAndAggregationsResponse,
1159 >,
1160 datadog::Error<ListActiveMetricConfigurationsError>,
1161 > {
1162 let local_configuration = &self.config;
1163 let operation_id = "v2.list_active_metric_configurations";
1164
1165 let window_seconds = params.window_seconds;
1167
1168 let local_client = &self.client;
1169
1170 let local_uri_str = format!(
1171 "{}/api/v2/metrics/{metric_name}/active-configurations",
1172 local_configuration.get_operation_host(operation_id),
1173 metric_name = datadog::urlencode(metric_name)
1174 );
1175 let mut local_req_builder =
1176 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1177
1178 if let Some(ref local_query_param) = window_seconds {
1179 local_req_builder =
1180 local_req_builder.query(&[("window[seconds]", &local_query_param.to_string())]);
1181 };
1182
1183 let mut headers = HeaderMap::new();
1185 headers.insert("Accept", HeaderValue::from_static("application/json"));
1186
1187 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1189 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1190 Err(e) => {
1191 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1192 headers.insert(
1193 reqwest::header::USER_AGENT,
1194 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1195 )
1196 }
1197 };
1198
1199 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1201 headers.insert(
1202 "DD-API-KEY",
1203 HeaderValue::from_str(local_key.key.as_str())
1204 .expect("failed to parse DD-API-KEY header"),
1205 );
1206 };
1207 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1208 headers.insert(
1209 "DD-APPLICATION-KEY",
1210 HeaderValue::from_str(local_key.key.as_str())
1211 .expect("failed to parse DD-APPLICATION-KEY header"),
1212 );
1213 };
1214
1215 local_req_builder = local_req_builder.headers(headers);
1216 let local_req = local_req_builder.build()?;
1217 log::debug!("request content: {:?}", local_req.body());
1218 let local_resp = local_client.execute(local_req).await?;
1219
1220 let local_status = local_resp.status();
1221 let local_content = local_resp.text().await?;
1222 log::debug!("response content: {}", local_content);
1223
1224 if !local_status.is_client_error() && !local_status.is_server_error() {
1225 match serde_json::from_str::<
1226 crate::datadogV2::model::MetricSuggestedTagsAndAggregationsResponse,
1227 >(&local_content)
1228 {
1229 Ok(e) => {
1230 return Ok(datadog::ResponseContent {
1231 status: local_status,
1232 content: local_content,
1233 entity: Some(e),
1234 })
1235 }
1236 Err(e) => return Err(datadog::Error::Serde(e)),
1237 };
1238 } else {
1239 let local_entity: Option<ListActiveMetricConfigurationsError> =
1240 serde_json::from_str(&local_content).ok();
1241 let local_error = datadog::ResponseContent {
1242 status: local_status,
1243 content: local_content,
1244 entity: local_entity,
1245 };
1246 Err(datadog::Error::ResponseError(local_error))
1247 }
1248 }
1249
1250 pub async fn list_metric_assets(
1252 &self,
1253 metric_name: String,
1254 ) -> Result<crate::datadogV2::model::MetricAssetsResponse, datadog::Error<ListMetricAssetsError>>
1255 {
1256 match self.list_metric_assets_with_http_info(metric_name).await {
1257 Ok(response_content) => {
1258 if let Some(e) = response_content.entity {
1259 Ok(e)
1260 } else {
1261 Err(datadog::Error::Serde(serde::de::Error::custom(
1262 "response content was None",
1263 )))
1264 }
1265 }
1266 Err(err) => Err(err),
1267 }
1268 }
1269
1270 pub async fn list_metric_assets_with_http_info(
1272 &self,
1273 metric_name: String,
1274 ) -> Result<
1275 datadog::ResponseContent<crate::datadogV2::model::MetricAssetsResponse>,
1276 datadog::Error<ListMetricAssetsError>,
1277 > {
1278 let local_configuration = &self.config;
1279 let operation_id = "v2.list_metric_assets";
1280
1281 let local_client = &self.client;
1282
1283 let local_uri_str = format!(
1284 "{}/api/v2/metrics/{metric_name}/assets",
1285 local_configuration.get_operation_host(operation_id),
1286 metric_name = datadog::urlencode(metric_name)
1287 );
1288 let mut local_req_builder =
1289 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1290
1291 let mut headers = HeaderMap::new();
1293 headers.insert("Accept", HeaderValue::from_static("application/json"));
1294
1295 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1297 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1298 Err(e) => {
1299 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1300 headers.insert(
1301 reqwest::header::USER_AGENT,
1302 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1303 )
1304 }
1305 };
1306
1307 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1309 headers.insert(
1310 "DD-API-KEY",
1311 HeaderValue::from_str(local_key.key.as_str())
1312 .expect("failed to parse DD-API-KEY header"),
1313 );
1314 };
1315 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1316 headers.insert(
1317 "DD-APPLICATION-KEY",
1318 HeaderValue::from_str(local_key.key.as_str())
1319 .expect("failed to parse DD-APPLICATION-KEY header"),
1320 );
1321 };
1322
1323 local_req_builder = local_req_builder.headers(headers);
1324 let local_req = local_req_builder.build()?;
1325 log::debug!("request content: {:?}", local_req.body());
1326 let local_resp = local_client.execute(local_req).await?;
1327
1328 let local_status = local_resp.status();
1329 let local_content = local_resp.text().await?;
1330 log::debug!("response content: {}", local_content);
1331
1332 if !local_status.is_client_error() && !local_status.is_server_error() {
1333 match serde_json::from_str::<crate::datadogV2::model::MetricAssetsResponse>(
1334 &local_content,
1335 ) {
1336 Ok(e) => {
1337 return Ok(datadog::ResponseContent {
1338 status: local_status,
1339 content: local_content,
1340 entity: Some(e),
1341 })
1342 }
1343 Err(e) => return Err(datadog::Error::Serde(e)),
1344 };
1345 } else {
1346 let local_entity: Option<ListMetricAssetsError> =
1347 serde_json::from_str(&local_content).ok();
1348 let local_error = datadog::ResponseContent {
1349 status: local_status,
1350 content: local_content,
1351 entity: local_entity,
1352 };
1353 Err(datadog::Error::ResponseError(local_error))
1354 }
1355 }
1356
1357 pub async fn list_tag_configuration_by_name(
1359 &self,
1360 metric_name: String,
1361 ) -> Result<
1362 crate::datadogV2::model::MetricTagConfigurationResponse,
1363 datadog::Error<ListTagConfigurationByNameError>,
1364 > {
1365 match self
1366 .list_tag_configuration_by_name_with_http_info(metric_name)
1367 .await
1368 {
1369 Ok(response_content) => {
1370 if let Some(e) = response_content.entity {
1371 Ok(e)
1372 } else {
1373 Err(datadog::Error::Serde(serde::de::Error::custom(
1374 "response content was None",
1375 )))
1376 }
1377 }
1378 Err(err) => Err(err),
1379 }
1380 }
1381
1382 pub async fn list_tag_configuration_by_name_with_http_info(
1384 &self,
1385 metric_name: String,
1386 ) -> Result<
1387 datadog::ResponseContent<crate::datadogV2::model::MetricTagConfigurationResponse>,
1388 datadog::Error<ListTagConfigurationByNameError>,
1389 > {
1390 let local_configuration = &self.config;
1391 let operation_id = "v2.list_tag_configuration_by_name";
1392
1393 let local_client = &self.client;
1394
1395 let local_uri_str = format!(
1396 "{}/api/v2/metrics/{metric_name}/tags",
1397 local_configuration.get_operation_host(operation_id),
1398 metric_name = datadog::urlencode(metric_name)
1399 );
1400 let mut local_req_builder =
1401 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1402
1403 let mut headers = HeaderMap::new();
1405 headers.insert("Accept", HeaderValue::from_static("application/json"));
1406
1407 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1409 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1410 Err(e) => {
1411 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1412 headers.insert(
1413 reqwest::header::USER_AGENT,
1414 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1415 )
1416 }
1417 };
1418
1419 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1421 headers.insert(
1422 "DD-API-KEY",
1423 HeaderValue::from_str(local_key.key.as_str())
1424 .expect("failed to parse DD-API-KEY header"),
1425 );
1426 };
1427 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1428 headers.insert(
1429 "DD-APPLICATION-KEY",
1430 HeaderValue::from_str(local_key.key.as_str())
1431 .expect("failed to parse DD-APPLICATION-KEY header"),
1432 );
1433 };
1434
1435 local_req_builder = local_req_builder.headers(headers);
1436 let local_req = local_req_builder.build()?;
1437 log::debug!("request content: {:?}", local_req.body());
1438 let local_resp = local_client.execute(local_req).await?;
1439
1440 let local_status = local_resp.status();
1441 let local_content = local_resp.text().await?;
1442 log::debug!("response content: {}", local_content);
1443
1444 if !local_status.is_client_error() && !local_status.is_server_error() {
1445 match serde_json::from_str::<crate::datadogV2::model::MetricTagConfigurationResponse>(
1446 &local_content,
1447 ) {
1448 Ok(e) => {
1449 return Ok(datadog::ResponseContent {
1450 status: local_status,
1451 content: local_content,
1452 entity: Some(e),
1453 })
1454 }
1455 Err(e) => return Err(datadog::Error::Serde(e)),
1456 };
1457 } else {
1458 let local_entity: Option<ListTagConfigurationByNameError> =
1459 serde_json::from_str(&local_content).ok();
1460 let local_error = datadog::ResponseContent {
1461 status: local_status,
1462 content: local_content,
1463 entity: local_entity,
1464 };
1465 Err(datadog::Error::ResponseError(local_error))
1466 }
1467 }
1468
1469 pub async fn list_tag_configurations(
1474 &self,
1475 params: ListTagConfigurationsOptionalParams,
1476 ) -> Result<
1477 crate::datadogV2::model::MetricsAndMetricTagConfigurationsResponse,
1478 datadog::Error<ListTagConfigurationsError>,
1479 > {
1480 match self.list_tag_configurations_with_http_info(params).await {
1481 Ok(response_content) => {
1482 if let Some(e) = response_content.entity {
1483 Ok(e)
1484 } else {
1485 Err(datadog::Error::Serde(serde::de::Error::custom(
1486 "response content was None",
1487 )))
1488 }
1489 }
1490 Err(err) => Err(err),
1491 }
1492 }
1493
1494 pub fn list_tag_configurations_with_pagination(
1495 &self,
1496 mut params: ListTagConfigurationsOptionalParams,
1497 ) -> impl Stream<
1498 Item = Result<
1499 crate::datadogV2::model::MetricsAndMetricTagConfigurations,
1500 datadog::Error<ListTagConfigurationsError>,
1501 >,
1502 > + '_ {
1503 try_stream! {
1504 let mut page_size: i32 = 10000;
1505 if params.page_size.is_none() {
1506 params.page_size = Some(page_size);
1507 } else {
1508 page_size = params.page_size.unwrap().clone();
1509 }
1510 loop {
1511 let resp = self.list_tag_configurations(params.clone()).await?;
1512 let Some(data) = resp.data else { break };
1513
1514 let r = data;
1515 let count = r.len();
1516 for team in r {
1517 yield team;
1518 }
1519
1520 if count < page_size as usize {
1521 break;
1522 }
1523 let Some(meta) = resp.meta else { break };
1524 let Some(pagination) = meta.pagination else { break };
1525 let Some(next_cursor) = pagination.next_cursor.unwrap() else { break };
1526
1527 params.page_cursor = Some(next_cursor);
1528 }
1529 }
1530 }
1531
1532 pub async fn list_tag_configurations_with_http_info(
1537 &self,
1538 params: ListTagConfigurationsOptionalParams,
1539 ) -> Result<
1540 datadog::ResponseContent<
1541 crate::datadogV2::model::MetricsAndMetricTagConfigurationsResponse,
1542 >,
1543 datadog::Error<ListTagConfigurationsError>,
1544 > {
1545 let local_configuration = &self.config;
1546 let operation_id = "v2.list_tag_configurations";
1547
1548 let filter_configured = params.filter_configured;
1550 let filter_tags_configured = params.filter_tags_configured;
1551 let filter_metric_type = params.filter_metric_type;
1552 let filter_include_percentiles = params.filter_include_percentiles;
1553 let filter_queried = params.filter_queried;
1554 let filter_tags = params.filter_tags;
1555 let filter_related_assets = params.filter_related_assets;
1556 let window_seconds = params.window_seconds;
1557 let page_size = params.page_size;
1558 let page_cursor = params.page_cursor;
1559
1560 let local_client = &self.client;
1561
1562 let local_uri_str = format!(
1563 "{}/api/v2/metrics",
1564 local_configuration.get_operation_host(operation_id)
1565 );
1566 let mut local_req_builder =
1567 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1568
1569 if let Some(ref local_query_param) = filter_configured {
1570 local_req_builder =
1571 local_req_builder.query(&[("filter[configured]", &local_query_param.to_string())]);
1572 };
1573 if let Some(ref local_query_param) = filter_tags_configured {
1574 local_req_builder = local_req_builder
1575 .query(&[("filter[tags_configured]", &local_query_param.to_string())]);
1576 };
1577 if let Some(ref local_query_param) = filter_metric_type {
1578 local_req_builder =
1579 local_req_builder.query(&[("filter[metric_type]", &local_query_param.to_string())]);
1580 };
1581 if let Some(ref local_query_param) = filter_include_percentiles {
1582 local_req_builder = local_req_builder.query(&[(
1583 "filter[include_percentiles]",
1584 &local_query_param.to_string(),
1585 )]);
1586 };
1587 if let Some(ref local_query_param) = filter_queried {
1588 local_req_builder =
1589 local_req_builder.query(&[("filter[queried]", &local_query_param.to_string())]);
1590 };
1591 if let Some(ref local_query_param) = filter_tags {
1592 local_req_builder =
1593 local_req_builder.query(&[("filter[tags]", &local_query_param.to_string())]);
1594 };
1595 if let Some(ref local_query_param) = filter_related_assets {
1596 local_req_builder = local_req_builder
1597 .query(&[("filter[related_assets]", &local_query_param.to_string())]);
1598 };
1599 if let Some(ref local_query_param) = window_seconds {
1600 local_req_builder =
1601 local_req_builder.query(&[("window[seconds]", &local_query_param.to_string())]);
1602 };
1603 if let Some(ref local_query_param) = page_size {
1604 local_req_builder =
1605 local_req_builder.query(&[("page[size]", &local_query_param.to_string())]);
1606 };
1607 if let Some(ref local_query_param) = page_cursor {
1608 local_req_builder =
1609 local_req_builder.query(&[("page[cursor]", &local_query_param.to_string())]);
1610 };
1611
1612 let mut headers = HeaderMap::new();
1614 headers.insert("Accept", HeaderValue::from_static("application/json"));
1615
1616 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1618 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1619 Err(e) => {
1620 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1621 headers.insert(
1622 reqwest::header::USER_AGENT,
1623 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1624 )
1625 }
1626 };
1627
1628 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1630 headers.insert(
1631 "DD-API-KEY",
1632 HeaderValue::from_str(local_key.key.as_str())
1633 .expect("failed to parse DD-API-KEY header"),
1634 );
1635 };
1636 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1637 headers.insert(
1638 "DD-APPLICATION-KEY",
1639 HeaderValue::from_str(local_key.key.as_str())
1640 .expect("failed to parse DD-APPLICATION-KEY header"),
1641 );
1642 };
1643
1644 local_req_builder = local_req_builder.headers(headers);
1645 let local_req = local_req_builder.build()?;
1646 log::debug!("request content: {:?}", local_req.body());
1647 let local_resp = local_client.execute(local_req).await?;
1648
1649 let local_status = local_resp.status();
1650 let local_content = local_resp.text().await?;
1651 log::debug!("response content: {}", local_content);
1652
1653 if !local_status.is_client_error() && !local_status.is_server_error() {
1654 match serde_json::from_str::<
1655 crate::datadogV2::model::MetricsAndMetricTagConfigurationsResponse,
1656 >(&local_content)
1657 {
1658 Ok(e) => {
1659 return Ok(datadog::ResponseContent {
1660 status: local_status,
1661 content: local_content,
1662 entity: Some(e),
1663 })
1664 }
1665 Err(e) => return Err(datadog::Error::Serde(e)),
1666 };
1667 } else {
1668 let local_entity: Option<ListTagConfigurationsError> =
1669 serde_json::from_str(&local_content).ok();
1670 let local_error = datadog::ResponseContent {
1671 status: local_status,
1672 content: local_content,
1673 entity: local_entity,
1674 };
1675 Err(datadog::Error::ResponseError(local_error))
1676 }
1677 }
1678
1679 pub async fn list_tags_by_metric_name(
1681 &self,
1682 metric_name: String,
1683 ) -> Result<
1684 crate::datadogV2::model::MetricAllTagsResponse,
1685 datadog::Error<ListTagsByMetricNameError>,
1686 > {
1687 match self
1688 .list_tags_by_metric_name_with_http_info(metric_name)
1689 .await
1690 {
1691 Ok(response_content) => {
1692 if let Some(e) = response_content.entity {
1693 Ok(e)
1694 } else {
1695 Err(datadog::Error::Serde(serde::de::Error::custom(
1696 "response content was None",
1697 )))
1698 }
1699 }
1700 Err(err) => Err(err),
1701 }
1702 }
1703
1704 pub async fn list_tags_by_metric_name_with_http_info(
1706 &self,
1707 metric_name: String,
1708 ) -> Result<
1709 datadog::ResponseContent<crate::datadogV2::model::MetricAllTagsResponse>,
1710 datadog::Error<ListTagsByMetricNameError>,
1711 > {
1712 let local_configuration = &self.config;
1713 let operation_id = "v2.list_tags_by_metric_name";
1714
1715 let local_client = &self.client;
1716
1717 let local_uri_str = format!(
1718 "{}/api/v2/metrics/{metric_name}/all-tags",
1719 local_configuration.get_operation_host(operation_id),
1720 metric_name = datadog::urlencode(metric_name)
1721 );
1722 let mut local_req_builder =
1723 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1724
1725 let mut headers = HeaderMap::new();
1727 headers.insert("Accept", HeaderValue::from_static("application/json"));
1728
1729 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1731 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1732 Err(e) => {
1733 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1734 headers.insert(
1735 reqwest::header::USER_AGENT,
1736 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1737 )
1738 }
1739 };
1740
1741 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1743 headers.insert(
1744 "DD-API-KEY",
1745 HeaderValue::from_str(local_key.key.as_str())
1746 .expect("failed to parse DD-API-KEY header"),
1747 );
1748 };
1749 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1750 headers.insert(
1751 "DD-APPLICATION-KEY",
1752 HeaderValue::from_str(local_key.key.as_str())
1753 .expect("failed to parse DD-APPLICATION-KEY header"),
1754 );
1755 };
1756
1757 local_req_builder = local_req_builder.headers(headers);
1758 let local_req = local_req_builder.build()?;
1759 log::debug!("request content: {:?}", local_req.body());
1760 let local_resp = local_client.execute(local_req).await?;
1761
1762 let local_status = local_resp.status();
1763 let local_content = local_resp.text().await?;
1764 log::debug!("response content: {}", local_content);
1765
1766 if !local_status.is_client_error() && !local_status.is_server_error() {
1767 match serde_json::from_str::<crate::datadogV2::model::MetricAllTagsResponse>(
1768 &local_content,
1769 ) {
1770 Ok(e) => {
1771 return Ok(datadog::ResponseContent {
1772 status: local_status,
1773 content: local_content,
1774 entity: Some(e),
1775 })
1776 }
1777 Err(e) => return Err(datadog::Error::Serde(e)),
1778 };
1779 } else {
1780 let local_entity: Option<ListTagsByMetricNameError> =
1781 serde_json::from_str(&local_content).ok();
1782 let local_error = datadog::ResponseContent {
1783 status: local_status,
1784 content: local_content,
1785 entity: local_entity,
1786 };
1787 Err(datadog::Error::ResponseError(local_error))
1788 }
1789 }
1790
1791 pub async fn list_volumes_by_metric_name(
1795 &self,
1796 metric_name: String,
1797 ) -> Result<
1798 crate::datadogV2::model::MetricVolumesResponse,
1799 datadog::Error<ListVolumesByMetricNameError>,
1800 > {
1801 match self
1802 .list_volumes_by_metric_name_with_http_info(metric_name)
1803 .await
1804 {
1805 Ok(response_content) => {
1806 if let Some(e) = response_content.entity {
1807 Ok(e)
1808 } else {
1809 Err(datadog::Error::Serde(serde::de::Error::custom(
1810 "response content was None",
1811 )))
1812 }
1813 }
1814 Err(err) => Err(err),
1815 }
1816 }
1817
1818 pub async fn list_volumes_by_metric_name_with_http_info(
1822 &self,
1823 metric_name: String,
1824 ) -> Result<
1825 datadog::ResponseContent<crate::datadogV2::model::MetricVolumesResponse>,
1826 datadog::Error<ListVolumesByMetricNameError>,
1827 > {
1828 let local_configuration = &self.config;
1829 let operation_id = "v2.list_volumes_by_metric_name";
1830
1831 let local_client = &self.client;
1832
1833 let local_uri_str = format!(
1834 "{}/api/v2/metrics/{metric_name}/volumes",
1835 local_configuration.get_operation_host(operation_id),
1836 metric_name = datadog::urlencode(metric_name)
1837 );
1838 let mut local_req_builder =
1839 local_client.request(reqwest::Method::GET, local_uri_str.as_str());
1840
1841 let mut headers = HeaderMap::new();
1843 headers.insert("Accept", HeaderValue::from_static("application/json"));
1844
1845 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1847 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1848 Err(e) => {
1849 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1850 headers.insert(
1851 reqwest::header::USER_AGENT,
1852 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1853 )
1854 }
1855 };
1856
1857 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1859 headers.insert(
1860 "DD-API-KEY",
1861 HeaderValue::from_str(local_key.key.as_str())
1862 .expect("failed to parse DD-API-KEY header"),
1863 );
1864 };
1865 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1866 headers.insert(
1867 "DD-APPLICATION-KEY",
1868 HeaderValue::from_str(local_key.key.as_str())
1869 .expect("failed to parse DD-APPLICATION-KEY header"),
1870 );
1871 };
1872
1873 local_req_builder = local_req_builder.headers(headers);
1874 let local_req = local_req_builder.build()?;
1875 log::debug!("request content: {:?}", local_req.body());
1876 let local_resp = local_client.execute(local_req).await?;
1877
1878 let local_status = local_resp.status();
1879 let local_content = local_resp.text().await?;
1880 log::debug!("response content: {}", local_content);
1881
1882 if !local_status.is_client_error() && !local_status.is_server_error() {
1883 match serde_json::from_str::<crate::datadogV2::model::MetricVolumesResponse>(
1884 &local_content,
1885 ) {
1886 Ok(e) => {
1887 return Ok(datadog::ResponseContent {
1888 status: local_status,
1889 content: local_content,
1890 entity: Some(e),
1891 })
1892 }
1893 Err(e) => return Err(datadog::Error::Serde(e)),
1894 };
1895 } else {
1896 let local_entity: Option<ListVolumesByMetricNameError> =
1897 serde_json::from_str(&local_content).ok();
1898 let local_error = datadog::ResponseContent {
1899 status: local_status,
1900 content: local_content,
1901 entity: local_entity,
1902 };
1903 Err(datadog::Error::ResponseError(local_error))
1904 }
1905 }
1906
1907 pub async fn query_scalar_data(
1911 &self,
1912 body: crate::datadogV2::model::ScalarFormulaQueryRequest,
1913 ) -> Result<
1914 crate::datadogV2::model::ScalarFormulaQueryResponse,
1915 datadog::Error<QueryScalarDataError>,
1916 > {
1917 match self.query_scalar_data_with_http_info(body).await {
1918 Ok(response_content) => {
1919 if let Some(e) = response_content.entity {
1920 Ok(e)
1921 } else {
1922 Err(datadog::Error::Serde(serde::de::Error::custom(
1923 "response content was None",
1924 )))
1925 }
1926 }
1927 Err(err) => Err(err),
1928 }
1929 }
1930
1931 pub async fn query_scalar_data_with_http_info(
1935 &self,
1936 body: crate::datadogV2::model::ScalarFormulaQueryRequest,
1937 ) -> Result<
1938 datadog::ResponseContent<crate::datadogV2::model::ScalarFormulaQueryResponse>,
1939 datadog::Error<QueryScalarDataError>,
1940 > {
1941 let local_configuration = &self.config;
1942 let operation_id = "v2.query_scalar_data";
1943
1944 let local_client = &self.client;
1945
1946 let local_uri_str = format!(
1947 "{}/api/v2/query/scalar",
1948 local_configuration.get_operation_host(operation_id)
1949 );
1950 let mut local_req_builder =
1951 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
1952
1953 let mut headers = HeaderMap::new();
1955 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
1956 headers.insert("Accept", HeaderValue::from_static("application/json"));
1957
1958 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
1960 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
1961 Err(e) => {
1962 log::warn!("Failed to parse user agent header: {e}, falling back to default");
1963 headers.insert(
1964 reqwest::header::USER_AGENT,
1965 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
1966 )
1967 }
1968 };
1969
1970 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
1972 headers.insert(
1973 "DD-API-KEY",
1974 HeaderValue::from_str(local_key.key.as_str())
1975 .expect("failed to parse DD-API-KEY header"),
1976 );
1977 };
1978 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
1979 headers.insert(
1980 "DD-APPLICATION-KEY",
1981 HeaderValue::from_str(local_key.key.as_str())
1982 .expect("failed to parse DD-APPLICATION-KEY header"),
1983 );
1984 };
1985
1986 let output = Vec::new();
1988 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
1989 if body.serialize(&mut ser).is_ok() {
1990 if let Some(content_encoding) = headers.get("Content-Encoding") {
1991 match content_encoding.to_str().unwrap_or_default() {
1992 "gzip" => {
1993 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
1994 let _ = enc.write_all(ser.into_inner().as_slice());
1995 match enc.finish() {
1996 Ok(buf) => {
1997 local_req_builder = local_req_builder.body(buf);
1998 }
1999 Err(e) => return Err(datadog::Error::Io(e)),
2000 }
2001 }
2002 "deflate" => {
2003 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2004 let _ = enc.write_all(ser.into_inner().as_slice());
2005 match enc.finish() {
2006 Ok(buf) => {
2007 local_req_builder = local_req_builder.body(buf);
2008 }
2009 Err(e) => return Err(datadog::Error::Io(e)),
2010 }
2011 }
2012 "zstd1" => {
2013 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2014 let _ = enc.write_all(ser.into_inner().as_slice());
2015 match enc.finish() {
2016 Ok(buf) => {
2017 local_req_builder = local_req_builder.body(buf);
2018 }
2019 Err(e) => return Err(datadog::Error::Io(e)),
2020 }
2021 }
2022 _ => {
2023 local_req_builder = local_req_builder.body(ser.into_inner());
2024 }
2025 }
2026 } else {
2027 local_req_builder = local_req_builder.body(ser.into_inner());
2028 }
2029 }
2030
2031 local_req_builder = local_req_builder.headers(headers);
2032 let local_req = local_req_builder.build()?;
2033 log::debug!("request content: {:?}", local_req.body());
2034 let local_resp = local_client.execute(local_req).await?;
2035
2036 let local_status = local_resp.status();
2037 let local_content = local_resp.text().await?;
2038 log::debug!("response content: {}", local_content);
2039
2040 if !local_status.is_client_error() && !local_status.is_server_error() {
2041 match serde_json::from_str::<crate::datadogV2::model::ScalarFormulaQueryResponse>(
2042 &local_content,
2043 ) {
2044 Ok(e) => {
2045 return Ok(datadog::ResponseContent {
2046 status: local_status,
2047 content: local_content,
2048 entity: Some(e),
2049 })
2050 }
2051 Err(e) => return Err(datadog::Error::Serde(e)),
2052 };
2053 } else {
2054 let local_entity: Option<QueryScalarDataError> =
2055 serde_json::from_str(&local_content).ok();
2056 let local_error = datadog::ResponseContent {
2057 status: local_status,
2058 content: local_content,
2059 entity: local_entity,
2060 };
2061 Err(datadog::Error::ResponseError(local_error))
2062 }
2063 }
2064
2065 pub async fn query_timeseries_data(
2068 &self,
2069 body: crate::datadogV2::model::TimeseriesFormulaQueryRequest,
2070 ) -> Result<
2071 crate::datadogV2::model::TimeseriesFormulaQueryResponse,
2072 datadog::Error<QueryTimeseriesDataError>,
2073 > {
2074 match self.query_timeseries_data_with_http_info(body).await {
2075 Ok(response_content) => {
2076 if let Some(e) = response_content.entity {
2077 Ok(e)
2078 } else {
2079 Err(datadog::Error::Serde(serde::de::Error::custom(
2080 "response content was None",
2081 )))
2082 }
2083 }
2084 Err(err) => Err(err),
2085 }
2086 }
2087
2088 pub async fn query_timeseries_data_with_http_info(
2091 &self,
2092 body: crate::datadogV2::model::TimeseriesFormulaQueryRequest,
2093 ) -> Result<
2094 datadog::ResponseContent<crate::datadogV2::model::TimeseriesFormulaQueryResponse>,
2095 datadog::Error<QueryTimeseriesDataError>,
2096 > {
2097 let local_configuration = &self.config;
2098 let operation_id = "v2.query_timeseries_data";
2099
2100 let local_client = &self.client;
2101
2102 let local_uri_str = format!(
2103 "{}/api/v2/query/timeseries",
2104 local_configuration.get_operation_host(operation_id)
2105 );
2106 let mut local_req_builder =
2107 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2108
2109 let mut headers = HeaderMap::new();
2111 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2112 headers.insert("Accept", HeaderValue::from_static("application/json"));
2113
2114 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2116 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2117 Err(e) => {
2118 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2119 headers.insert(
2120 reqwest::header::USER_AGENT,
2121 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2122 )
2123 }
2124 };
2125
2126 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2128 headers.insert(
2129 "DD-API-KEY",
2130 HeaderValue::from_str(local_key.key.as_str())
2131 .expect("failed to parse DD-API-KEY header"),
2132 );
2133 };
2134 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2135 headers.insert(
2136 "DD-APPLICATION-KEY",
2137 HeaderValue::from_str(local_key.key.as_str())
2138 .expect("failed to parse DD-APPLICATION-KEY header"),
2139 );
2140 };
2141
2142 let output = Vec::new();
2144 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2145 if body.serialize(&mut ser).is_ok() {
2146 if let Some(content_encoding) = headers.get("Content-Encoding") {
2147 match content_encoding.to_str().unwrap_or_default() {
2148 "gzip" => {
2149 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2150 let _ = enc.write_all(ser.into_inner().as_slice());
2151 match enc.finish() {
2152 Ok(buf) => {
2153 local_req_builder = local_req_builder.body(buf);
2154 }
2155 Err(e) => return Err(datadog::Error::Io(e)),
2156 }
2157 }
2158 "deflate" => {
2159 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2160 let _ = enc.write_all(ser.into_inner().as_slice());
2161 match enc.finish() {
2162 Ok(buf) => {
2163 local_req_builder = local_req_builder.body(buf);
2164 }
2165 Err(e) => return Err(datadog::Error::Io(e)),
2166 }
2167 }
2168 "zstd1" => {
2169 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2170 let _ = enc.write_all(ser.into_inner().as_slice());
2171 match enc.finish() {
2172 Ok(buf) => {
2173 local_req_builder = local_req_builder.body(buf);
2174 }
2175 Err(e) => return Err(datadog::Error::Io(e)),
2176 }
2177 }
2178 _ => {
2179 local_req_builder = local_req_builder.body(ser.into_inner());
2180 }
2181 }
2182 } else {
2183 local_req_builder = local_req_builder.body(ser.into_inner());
2184 }
2185 }
2186
2187 local_req_builder = local_req_builder.headers(headers);
2188 let local_req = local_req_builder.build()?;
2189 log::debug!("request content: {:?}", local_req.body());
2190 let local_resp = local_client.execute(local_req).await?;
2191
2192 let local_status = local_resp.status();
2193 let local_content = local_resp.text().await?;
2194 log::debug!("response content: {}", local_content);
2195
2196 if !local_status.is_client_error() && !local_status.is_server_error() {
2197 match serde_json::from_str::<crate::datadogV2::model::TimeseriesFormulaQueryResponse>(
2198 &local_content,
2199 ) {
2200 Ok(e) => {
2201 return Ok(datadog::ResponseContent {
2202 status: local_status,
2203 content: local_content,
2204 entity: Some(e),
2205 })
2206 }
2207 Err(e) => return Err(datadog::Error::Serde(e)),
2208 };
2209 } else {
2210 let local_entity: Option<QueryTimeseriesDataError> =
2211 serde_json::from_str(&local_content).ok();
2212 let local_error = datadog::ResponseContent {
2213 status: local_status,
2214 content: local_content,
2215 entity: local_entity,
2216 };
2217 Err(datadog::Error::ResponseError(local_error))
2218 }
2219 }
2220
2221 pub async fn submit_metrics(
2234 &self,
2235 body: crate::datadogV2::model::MetricPayload,
2236 params: SubmitMetricsOptionalParams,
2237 ) -> Result<crate::datadogV2::model::IntakePayloadAccepted, datadog::Error<SubmitMetricsError>>
2238 {
2239 match self.submit_metrics_with_http_info(body, params).await {
2240 Ok(response_content) => {
2241 if let Some(e) = response_content.entity {
2242 Ok(e)
2243 } else {
2244 Err(datadog::Error::Serde(serde::de::Error::custom(
2245 "response content was None",
2246 )))
2247 }
2248 }
2249 Err(err) => Err(err),
2250 }
2251 }
2252
2253 pub async fn submit_metrics_with_http_info(
2266 &self,
2267 body: crate::datadogV2::model::MetricPayload,
2268 params: SubmitMetricsOptionalParams,
2269 ) -> Result<
2270 datadog::ResponseContent<crate::datadogV2::model::IntakePayloadAccepted>,
2271 datadog::Error<SubmitMetricsError>,
2272 > {
2273 let local_configuration = &self.config;
2274 let operation_id = "v2.submit_metrics";
2275
2276 let content_encoding = params.content_encoding;
2278
2279 let local_client = &self.client;
2280
2281 let local_uri_str = format!(
2282 "{}/api/v2/series",
2283 local_configuration.get_operation_host(operation_id)
2284 );
2285 let mut local_req_builder =
2286 local_client.request(reqwest::Method::POST, local_uri_str.as_str());
2287
2288 let mut headers = HeaderMap::new();
2290 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2291 headers.insert("Accept", HeaderValue::from_static("application/json"));
2292
2293 if let Some(ref local) = content_encoding {
2294 headers.insert(
2295 "Content-Encoding",
2296 local
2297 .to_string()
2298 .parse()
2299 .expect("failed to parse Content-Encoding header"),
2300 );
2301 }
2302
2303 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2305 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2306 Err(e) => {
2307 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2308 headers.insert(
2309 reqwest::header::USER_AGENT,
2310 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2311 )
2312 }
2313 };
2314
2315 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2317 headers.insert(
2318 "DD-API-KEY",
2319 HeaderValue::from_str(local_key.key.as_str())
2320 .expect("failed to parse DD-API-KEY header"),
2321 );
2322 };
2323
2324 let output = Vec::new();
2326 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2327 if body.serialize(&mut ser).is_ok() {
2328 if let Some(content_encoding) = headers.get("Content-Encoding") {
2329 match content_encoding.to_str().unwrap_or_default() {
2330 "gzip" => {
2331 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2332 let _ = enc.write_all(ser.into_inner().as_slice());
2333 match enc.finish() {
2334 Ok(buf) => {
2335 local_req_builder = local_req_builder.body(buf);
2336 }
2337 Err(e) => return Err(datadog::Error::Io(e)),
2338 }
2339 }
2340 "deflate" => {
2341 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2342 let _ = enc.write_all(ser.into_inner().as_slice());
2343 match enc.finish() {
2344 Ok(buf) => {
2345 local_req_builder = local_req_builder.body(buf);
2346 }
2347 Err(e) => return Err(datadog::Error::Io(e)),
2348 }
2349 }
2350 "zstd1" => {
2351 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2352 let _ = enc.write_all(ser.into_inner().as_slice());
2353 match enc.finish() {
2354 Ok(buf) => {
2355 local_req_builder = local_req_builder.body(buf);
2356 }
2357 Err(e) => return Err(datadog::Error::Io(e)),
2358 }
2359 }
2360 _ => {
2361 local_req_builder = local_req_builder.body(ser.into_inner());
2362 }
2363 }
2364 } else {
2365 local_req_builder = local_req_builder.body(ser.into_inner());
2366 }
2367 }
2368
2369 local_req_builder = local_req_builder.headers(headers);
2370 let local_req = local_req_builder.build()?;
2371 log::debug!("request content: {:?}", local_req.body());
2372 let local_resp = local_client.execute(local_req).await?;
2373
2374 let local_status = local_resp.status();
2375 let local_content = local_resp.text().await?;
2376 log::debug!("response content: {}", local_content);
2377
2378 if !local_status.is_client_error() && !local_status.is_server_error() {
2379 match serde_json::from_str::<crate::datadogV2::model::IntakePayloadAccepted>(
2380 &local_content,
2381 ) {
2382 Ok(e) => {
2383 return Ok(datadog::ResponseContent {
2384 status: local_status,
2385 content: local_content,
2386 entity: Some(e),
2387 })
2388 }
2389 Err(e) => return Err(datadog::Error::Serde(e)),
2390 };
2391 } else {
2392 let local_entity: Option<SubmitMetricsError> =
2393 serde_json::from_str(&local_content).ok();
2394 let local_error = datadog::ResponseContent {
2395 status: local_status,
2396 content: local_content,
2397 entity: local_entity,
2398 };
2399 Err(datadog::Error::ResponseError(local_error))
2400 }
2401 }
2402
2403 pub async fn update_tag_configuration(
2409 &self,
2410 metric_name: String,
2411 body: crate::datadogV2::model::MetricTagConfigurationUpdateRequest,
2412 ) -> Result<
2413 crate::datadogV2::model::MetricTagConfigurationResponse,
2414 datadog::Error<UpdateTagConfigurationError>,
2415 > {
2416 match self
2417 .update_tag_configuration_with_http_info(metric_name, body)
2418 .await
2419 {
2420 Ok(response_content) => {
2421 if let Some(e) = response_content.entity {
2422 Ok(e)
2423 } else {
2424 Err(datadog::Error::Serde(serde::de::Error::custom(
2425 "response content was None",
2426 )))
2427 }
2428 }
2429 Err(err) => Err(err),
2430 }
2431 }
2432
2433 pub async fn update_tag_configuration_with_http_info(
2439 &self,
2440 metric_name: String,
2441 body: crate::datadogV2::model::MetricTagConfigurationUpdateRequest,
2442 ) -> Result<
2443 datadog::ResponseContent<crate::datadogV2::model::MetricTagConfigurationResponse>,
2444 datadog::Error<UpdateTagConfigurationError>,
2445 > {
2446 let local_configuration = &self.config;
2447 let operation_id = "v2.update_tag_configuration";
2448
2449 let local_client = &self.client;
2450
2451 let local_uri_str = format!(
2452 "{}/api/v2/metrics/{metric_name}/tags",
2453 local_configuration.get_operation_host(operation_id),
2454 metric_name = datadog::urlencode(metric_name)
2455 );
2456 let mut local_req_builder =
2457 local_client.request(reqwest::Method::PATCH, local_uri_str.as_str());
2458
2459 let mut headers = HeaderMap::new();
2461 headers.insert("Content-Type", HeaderValue::from_static("application/json"));
2462 headers.insert("Accept", HeaderValue::from_static("application/json"));
2463
2464 match HeaderValue::from_str(local_configuration.user_agent.as_str()) {
2466 Ok(user_agent) => headers.insert(reqwest::header::USER_AGENT, user_agent),
2467 Err(e) => {
2468 log::warn!("Failed to parse user agent header: {e}, falling back to default");
2469 headers.insert(
2470 reqwest::header::USER_AGENT,
2471 HeaderValue::from_static(datadog::DEFAULT_USER_AGENT.as_str()),
2472 )
2473 }
2474 };
2475
2476 if let Some(local_key) = local_configuration.auth_keys.get("apiKeyAuth") {
2478 headers.insert(
2479 "DD-API-KEY",
2480 HeaderValue::from_str(local_key.key.as_str())
2481 .expect("failed to parse DD-API-KEY header"),
2482 );
2483 };
2484 if let Some(local_key) = local_configuration.auth_keys.get("appKeyAuth") {
2485 headers.insert(
2486 "DD-APPLICATION-KEY",
2487 HeaderValue::from_str(local_key.key.as_str())
2488 .expect("failed to parse DD-APPLICATION-KEY header"),
2489 );
2490 };
2491
2492 let output = Vec::new();
2494 let mut ser = serde_json::Serializer::with_formatter(output, datadog::DDFormatter);
2495 if body.serialize(&mut ser).is_ok() {
2496 if let Some(content_encoding) = headers.get("Content-Encoding") {
2497 match content_encoding.to_str().unwrap_or_default() {
2498 "gzip" => {
2499 let mut enc = GzEncoder::new(Vec::new(), Compression::default());
2500 let _ = enc.write_all(ser.into_inner().as_slice());
2501 match enc.finish() {
2502 Ok(buf) => {
2503 local_req_builder = local_req_builder.body(buf);
2504 }
2505 Err(e) => return Err(datadog::Error::Io(e)),
2506 }
2507 }
2508 "deflate" => {
2509 let mut enc = ZlibEncoder::new(Vec::new(), Compression::default());
2510 let _ = enc.write_all(ser.into_inner().as_slice());
2511 match enc.finish() {
2512 Ok(buf) => {
2513 local_req_builder = local_req_builder.body(buf);
2514 }
2515 Err(e) => return Err(datadog::Error::Io(e)),
2516 }
2517 }
2518 "zstd1" => {
2519 let mut enc = zstd::stream::Encoder::new(Vec::new(), 0).unwrap();
2520 let _ = enc.write_all(ser.into_inner().as_slice());
2521 match enc.finish() {
2522 Ok(buf) => {
2523 local_req_builder = local_req_builder.body(buf);
2524 }
2525 Err(e) => return Err(datadog::Error::Io(e)),
2526 }
2527 }
2528 _ => {
2529 local_req_builder = local_req_builder.body(ser.into_inner());
2530 }
2531 }
2532 } else {
2533 local_req_builder = local_req_builder.body(ser.into_inner());
2534 }
2535 }
2536
2537 local_req_builder = local_req_builder.headers(headers);
2538 let local_req = local_req_builder.build()?;
2539 log::debug!("request content: {:?}", local_req.body());
2540 let local_resp = local_client.execute(local_req).await?;
2541
2542 let local_status = local_resp.status();
2543 let local_content = local_resp.text().await?;
2544 log::debug!("response content: {}", local_content);
2545
2546 if !local_status.is_client_error() && !local_status.is_server_error() {
2547 match serde_json::from_str::<crate::datadogV2::model::MetricTagConfigurationResponse>(
2548 &local_content,
2549 ) {
2550 Ok(e) => {
2551 return Ok(datadog::ResponseContent {
2552 status: local_status,
2553 content: local_content,
2554 entity: Some(e),
2555 })
2556 }
2557 Err(e) => return Err(datadog::Error::Serde(e)),
2558 };
2559 } else {
2560 let local_entity: Option<UpdateTagConfigurationError> =
2561 serde_json::from_str(&local_content).ok();
2562 let local_error = datadog::ResponseContent {
2563 status: local_status,
2564 content: local_content,
2565 entity: local_entity,
2566 };
2567 Err(datadog::Error::ResponseError(local_error))
2568 }
2569 }
2570}