Compare commits
No commits in common. "5344242ce88478e1613b62bca0e31ebe53407618" and "2847a5a1e9f2637e97bd00a3ef0aa1605e589ecd" have entirely different histories.
5344242ce8
...
2847a5a1e9
|
|
@ -17,6 +17,3 @@ ENODE_MONITORING_PASSWORD = "admin_password_enode_monitoring" # # admin password
|
||||||
# IM configuration for max level of logging info
|
# IM configuration for max level of logging info
|
||||||
# for example DEBUG, INFO, WARN, ERROR, TRACE
|
# for example DEBUG, INFO, WARN, ERROR, TRACE
|
||||||
IM_LOG_INFO = "INFO"
|
IM_LOG_INFO = "INFO"
|
||||||
# IM configuration for setting up API connetion
|
|
||||||
# timeout (in secs). Default value - 10
|
|
||||||
IM_CONNECTION_TIMEOUT = "10"
|
|
||||||
|
|
@ -2,19 +2,12 @@
|
||||||
name = "api-grub"
|
name = "api-grub"
|
||||||
version = "1.0.2"
|
version = "1.0.2"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
authors = ["Vladislav Drozdov <maseeeeeeeed@gmail.com>"]
|
|
||||||
description = "API poller for ZVKS project"
|
|
||||||
homepage = "http://git.enode/deployer3000/integration-module/src/branch/master/crates/api-grub"
|
|
||||||
repository = "http://git.enode/deployer3000/integration-module/src/branch/master/crates/api-grub"
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
keywords = ["api", "grub", "zvks"]
|
|
||||||
publish = ["kellnr"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = { version = "1.0.217", features = ["derive"] }
|
serde = { version = "1.0.217", features = ["derive"] }
|
||||||
serde_json = "1.0.135"
|
serde_json = "1.0.135"
|
||||||
tokio = { version = "1.43.0", features = ["full"] }
|
tokio = { version = "1.43.0", features = ["full"] }
|
||||||
integr-structs = { version = ">=0.1.0", path="../integr-structs"}
|
integr-structs = {path = "../integr-structs"}
|
||||||
anyhow = "1.0.95"
|
anyhow = "1.0.95"
|
||||||
chrono = "0.4.39"
|
chrono = "0.4.39"
|
||||||
reqwest = { version = "0.12.12", features = ["rustls-tls", "json"] }
|
reqwest = { version = "0.12.12", features = ["rustls-tls", "json"] }
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,6 @@ use integr_structs::api::v3::{MetricOutputExtended, PrometheusMetricsExtended};
|
||||||
use tracing::{error, info, warn};
|
use tracing::{error, info, warn};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
// const IM_CONNECTION_TIMEOUT: String = std::env::var("IM_CONNECTION_TIMEOUT").unwrap_or_else(|_| "10".to_string());
|
|
||||||
|
|
||||||
/// # Fn `get_metrics_from_monitoring`
|
/// # Fn `get_metrics_from_monitoring`
|
||||||
///
|
///
|
||||||
/// A function to init pulling and exporting metrics mechanism
|
/// A function to init pulling and exporting metrics mechanism
|
||||||
|
|
@ -40,7 +38,7 @@ use std::collections::HashMap;
|
||||||
/// assert_eq!(get_metrics_from_monitoring(0, 5).await, Ok(()));
|
/// assert_eq!(get_metrics_from_monitoring(0, 5).await, Ok(()));
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
#[tracing::instrument(name = "cm_fn_initiator", skip_all)]
|
#[tracing::instrument(name = "CM mechanism", skip_all)]
|
||||||
pub async fn get_metrics_from_monitoring(duration: usize, delay: usize) -> anyhow::Result<()> {
|
pub async fn get_metrics_from_monitoring(duration: usize, delay: usize) -> anyhow::Result<()> {
|
||||||
|
|
||||||
let timer = tokio::time::Instant::now();
|
let timer = tokio::time::Instant::now();
|
||||||
|
|
@ -96,7 +94,6 @@ pub struct MonitoringImporter {
|
||||||
password : String,
|
password : String,
|
||||||
access_token : String,
|
access_token : String,
|
||||||
ts : String,
|
ts : String,
|
||||||
timeout : usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MonitoringImporter {
|
impl MonitoringImporter {
|
||||||
|
|
@ -118,7 +115,6 @@ impl MonitoringImporter {
|
||||||
password : env::var("ENODE_MONITORING_PASSWORD").unwrap_or_else(|_| String::new()),
|
password : env::var("ENODE_MONITORING_PASSWORD").unwrap_or_else(|_| String::new()),
|
||||||
access_token : String::new(),
|
access_token : String::new(),
|
||||||
ts : String::new(),
|
ts : String::new(),
|
||||||
timeout : std::env::var("IM_CONNECTION_TIMEOUT").unwrap_or_else(|_| "10".to_string()).parse().unwrap_or_else(|_| 10)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Function that checks is current `MonitoringImporter` valid
|
/// Function that checks is current `MonitoringImporter` valid
|
||||||
|
|
@ -144,7 +140,7 @@ impl MonitoringImporter {
|
||||||
///
|
///
|
||||||
/// *Also* it saves ts and access-key in it's runtime environment,
|
/// *Also* it saves ts and access-key in it's runtime environment,
|
||||||
/// there's no way to get access-key of session
|
/// there's no way to get access-key of session
|
||||||
#[tracing::instrument(name = "cm_fn_session_start", skip_all)]
|
#[tracing::instrument(name = "CM-session mechanism", skip_all)]
|
||||||
pub async fn start_session(&mut self) -> anyhow::Result<()> {
|
pub async fn start_session(&mut self) -> anyhow::Result<()> {
|
||||||
if !self.is_valid().await {
|
if !self.is_valid().await {
|
||||||
return Err(Error::msg("Invalid eNODE-Monitoring configuration"));
|
return Err(Error::msg("Invalid eNODE-Monitoring configuration"));
|
||||||
|
|
@ -157,7 +153,6 @@ impl MonitoringImporter {
|
||||||
loop {
|
loop {
|
||||||
let client = client
|
let client = client
|
||||||
.post(&url)
|
.post(&url)
|
||||||
.timeout(tokio::time::Duration::from_secs(self.timeout as u64))
|
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.json(&fortoken);
|
.json(&fortoken);
|
||||||
// let resp = client.send().await?;
|
// let resp = client.send().await?;
|
||||||
|
|
@ -196,7 +191,6 @@ impl MonitoringImporter {
|
||||||
let url = format!("http://{}/e-cmdb/api/query", self.ip);
|
let url = format!("http://{}/e-cmdb/api/query", self.ip);
|
||||||
let client = client
|
let client = client
|
||||||
.post(url)
|
.post(url)
|
||||||
.timeout(tokio::time::Duration::from_secs(self.timeout as u64))
|
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.header("access-token", &self.access_token)
|
.header("access-token", &self.access_token)
|
||||||
.json(&Query::default());
|
.json(&Query::default());
|
||||||
|
|
@ -262,12 +256,7 @@ impl MonitoringImporter {
|
||||||
let _permit = permit.acquire().await.unwrap();
|
let _permit = permit.acquire().await.unwrap();
|
||||||
|
|
||||||
let jh: JoinHandle<anyhow::Result<PrometheusMetricsExtended>> = tokio::spawn(async move {
|
let jh: JoinHandle<anyhow::Result<PrometheusMetricsExtended>> = tokio::spawn(async move {
|
||||||
Self::process_endpoint(
|
Self::process_endpoint(measure.clone(), client.clone(), arc.clone(), &hm).await
|
||||||
measure.clone(),
|
|
||||||
client.clone(),
|
|
||||||
arc.clone(),
|
|
||||||
&hm,
|
|
||||||
).await
|
|
||||||
|
|
||||||
});
|
});
|
||||||
jh_vec.push(jh);
|
jh_vec.push(jh);
|
||||||
|
|
@ -300,16 +289,10 @@ impl MonitoringImporter {
|
||||||
/// a slice of measures in special format `%5B%22measure$1%22,%20%22measure$2%22%5D`.
|
/// a slice of measures in special format `%5B%22measure$1%22,%20%22measure$2%22%5D`.
|
||||||
/// This is a neccesary measure to handle two types of requests and URL restrictions
|
/// This is a neccesary measure to handle two types of requests and URL restrictions
|
||||||
///
|
///
|
||||||
async fn process_endpoint(
|
async fn process_endpoint(measure: Arc<String>, client: Arc<Client>, arc: Arc<Self>, hm: &HashMap<String, String>) -> anyhow::Result<PrometheusMetricsExtended> {
|
||||||
measure: Arc<String>,
|
|
||||||
client: Arc<Client>,
|
|
||||||
arc: Arc<Self>,
|
|
||||||
hm: &HashMap<String, String>,
|
|
||||||
) -> anyhow::Result<PrometheusMetricsExtended> {
|
|
||||||
tracing::trace!("Processing CM endpoint with one or more measure names");
|
tracing::trace!("Processing CM endpoint with one or more measure names");
|
||||||
let resp = client
|
let resp = client
|
||||||
.get(format!("http://{}/e-nms/mirror/measure/{}", arc.ip, &measure))
|
.get(format!("http://{}/e-nms/mirror/measure/{}", arc.ip, &measure))
|
||||||
.timeout(tokio::time::Duration::from_secs(arc.timeout as u64))
|
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.header("access-token", &arc.access_token)
|
.header("access-token", &arc.access_token)
|
||||||
.send().await?
|
.send().await?
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,6 @@
|
||||||
name = "integr-structs"
|
name = "integr-structs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
description = "Structs for API poller in ZVKS project"
|
|
||||||
homepage = "http://git.enode/deployer3000/integration-module/src/branch/master/crates/integr-structs"
|
|
||||||
repository = "http://git.enode/deployer3000/integration-module/src/branch/master/crates/integr-structs"
|
|
||||||
license = "MIT OR Apache-2.0"
|
|
||||||
keywords = ["api", "grub", "zvks", "structs", "contracts"]
|
|
||||||
publish = ["kellnr"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.95"
|
anyhow = "1.0.95"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue