diff --git a/crates/api-grub/src/export.rs b/crates/api-grub/src/export.rs index 3e282b4..a984f7f 100644 --- a/crates/api-grub/src/export.rs +++ b/crates/api-grub/src/export.rs @@ -3,7 +3,7 @@ use integr_structs::api::v3::{PrometheusMetrics, PrometheusMetricsExtended}; use reqwest::Client; use tokio_postgres::NoTls; use std::env; -use anyhow::{Result}; +use anyhow::Result; use log::{info, error}; pub struct Exporter { @@ -34,51 +34,43 @@ impl Exporter { }, } } + #[allow(unused)] pub fn is_no_connection(&self) -> bool { self.pool.is_none() } pub fn init() -> Self { Self { pool : Self::pool_construct(), } } + #[allow(unused)] pub async fn get_connection_from_pool(&self) -> Option { if let Some(pool) = &self.pool { return Some(pool.get().await.ok()?); } None } + #[allow(unused)] pub async fn export_data(client: PgClient, metrics: &str) -> Result<()> { - // client. let query = client.prepare_cached("INSERT INTO metrics (body) VALUES ($1);").await?; let _ = client.query(&query, &[&metrics]).await?; Ok(()) } pub async fn export_metrics(metrics: PrometheusMetrics) -> Result { let url = env::var("EXPORTER_URL")?; - // let req = Request::new(Method::PUT, - // Url::parse(metrics)?); - // dbg!(&metrics); + let req = Client::new() .post(url) .json(&metrics) .send().await; - // dbg!(&req); - // dbg!(&req.unwrap().text().await); - // todo : rewrite with status code wrapping + req?; Ok(metrics.get_bytes_len()) } pub async fn export_extended_metrics(metrics: PrometheusMetricsExtended) -> Result { let url = env::var("EXPORTER_URL")?; - // let req = Request::new(Method::PUT, - // Url::parse(metrics)?); - // dbg!(&metrics); let req = Client::new() .post(url) .json(&metrics) .send().await; - // dbg!(&req); - // dbg!(&req.unwrap().text().await); - // todo : rewrite with status code wrapping req?; Ok(metrics.get_bytes_len()) }