use std::sync::Arc;
use crate::error::{map_manager_err, ManagerError};
use crate::gen::manager::apis::configuration::Configuration;
use crate::gen::manager::apis::{manager_api, metric_api};
use crate::gen::manager::models;
use crate::retry::{with_retry, RetryPolicy};
pub struct MetricsResource {
pub(crate) cfg: Arc<Configuration>,
pub(crate) retry: RetryPolicy,
}
impl MetricsResource {
pub async fn list_ids(&self) -> Result<models::MetricIdItemsResponse, ManagerError> {
with_retry(&self.retry, true, || {
manager_api::list_metric_ids(self.cfg.as_ref())
})
.await
.map_err(map_manager_err)
}
pub async fn definitions(&self) -> Result<models::MetricDefinitionListResponse, ManagerError> {
with_retry(&self.retry, true, || {
manager_api::get_all_metric_definitions(self.cfg.as_ref())
})
.await
.map_err(map_manager_err)
}
pub async fn get(&self, id: &str) -> Result<models::MetricResponse, ManagerError> {
with_retry(&self.retry, true, || {
manager_api::get_metric(self.cfg.as_ref(), id)
})
.await
.map_err(map_manager_err)
}
pub async fn describe(
&self,
id: &str,
) -> Result<models::MetricDefinitionItemResponse, ManagerError> {
with_retry(&self.retry, true, || {
metric_api::get_metric_definition(self.cfg.as_ref(), id)
})
.await
.map_err(map_manager_err)
}
}