Compare commits

..

8 Commits

Author SHA1 Message Date
deployer3000 5344242ce8 Merge pull request 'rc' (#19) from rc into master 2025-03-12 17:48:41 +03:00
YurijO 1ba496f053 Merge pull request '-kellnr' (#20) from feature/1163 into rc
test-org/integration-module/pipeline/pr-master Build succeeded
Reviewed-on: http://git.enode/deployer3000/integration-module/pulls/20
2025-03-12 17:45:04 +03:00
prplV f069a81b0d -kellnr
test-org/integration-module/pipeline/pr-rc This commit looks good Details
2025-03-12 17:43:17 +03:00
YurijO ce1a9d287d Merge pull request 'feature/1163' (#18) from feature/1163 into rc
test-org/integration-module/pipeline/pr-master There was a failure building this commit Details
Reviewed-on: http://192.168.2.61/deployer3000/integration-module/pulls/18
Reviewed-by: DmitriyA <faleo1999@mail.ru>
Reviewed-by: YurijO <ya@ya.ru>
2025-03-12 14:59:57 +03:00
prplV 10efa07aab kellnr test 2
test-org/integration-module/pipeline/pr-rc This commit looks good Details
2025-03-12 13:20:19 +03:00
prplV 43e24c136c urls fixed 2025-03-12 13:02:17 +03:00
prplV 0562a1637c kellnr test 2025-03-12 13:01:48 +03:00
prplV f238f2ce28 timeout for reqs added 2025-03-12 12:58:54 +03:00
4 changed files with 40 additions and 7 deletions

View File

@ -17,3 +17,6 @@ ENODE_MONITORING_PASSWORD = "admin_password_enode_monitoring" # # admin password
# IM configuration for max level of logging info
# for example DEBUG, INFO, WARN, ERROR, TRACE
IM_LOG_INFO = "INFO"
# IM configuration for setting up API connetion
# timeout (in secs). Default value - 10
IM_CONNECTION_TIMEOUT = "10"

View File

@ -2,12 +2,19 @@
name = "api-grub"
version = "1.0.2"
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]
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.135"
tokio = { version = "1.43.0", features = ["full"] }
integr-structs = {path = "../integr-structs"}
integr-structs = { version = ">=0.1.0", path="../integr-structs"}
anyhow = "1.0.95"
chrono = "0.4.39"
reqwest = { version = "0.12.12", features = ["rustls-tls", "json"] }

View File

@ -13,6 +13,8 @@ use integr_structs::api::v3::{MetricOutputExtended, PrometheusMetricsExtended};
use tracing::{error, info, warn};
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`
///
/// A function to init pulling and exporting metrics mechanism
@ -38,7 +40,7 @@ use std::collections::HashMap;
/// assert_eq!(get_metrics_from_monitoring(0, 5).await, Ok(()));
/// ```
///
#[tracing::instrument(name = "CM mechanism", skip_all)]
#[tracing::instrument(name = "cm_fn_initiator", skip_all)]
pub async fn get_metrics_from_monitoring(duration: usize, delay: usize) -> anyhow::Result<()> {
let timer = tokio::time::Instant::now();
@ -94,6 +96,7 @@ pub struct MonitoringImporter {
password : String,
access_token : String,
ts : String,
timeout : usize,
}
impl MonitoringImporter {
@ -115,6 +118,7 @@ impl MonitoringImporter {
password : env::var("ENODE_MONITORING_PASSWORD").unwrap_or_else(|_| String::new()),
access_token : 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
@ -140,7 +144,7 @@ impl MonitoringImporter {
///
/// *Also* it saves ts and access-key in it's runtime environment,
/// there's no way to get access-key of session
#[tracing::instrument(name = "CM-session mechanism", skip_all)]
#[tracing::instrument(name = "cm_fn_session_start", skip_all)]
pub async fn start_session(&mut self) -> anyhow::Result<()> {
if !self.is_valid().await {
return Err(Error::msg("Invalid eNODE-Monitoring configuration"));
@ -153,6 +157,7 @@ impl MonitoringImporter {
loop {
let client = client
.post(&url)
.timeout(tokio::time::Duration::from_secs(self.timeout as u64))
.header("Content-Type", "application/json")
.json(&fortoken);
// let resp = client.send().await?;
@ -191,6 +196,7 @@ impl MonitoringImporter {
let url = format!("http://{}/e-cmdb/api/query", self.ip);
let client = client
.post(url)
.timeout(tokio::time::Duration::from_secs(self.timeout as u64))
.header("Content-Type", "application/json")
.header("access-token", &self.access_token)
.json(&Query::default());
@ -256,7 +262,12 @@ impl MonitoringImporter {
let _permit = permit.acquire().await.unwrap();
let jh: JoinHandle<anyhow::Result<PrometheusMetricsExtended>> = tokio::spawn(async move {
Self::process_endpoint(measure.clone(), client.clone(), arc.clone(), &hm).await
Self::process_endpoint(
measure.clone(),
client.clone(),
arc.clone(),
&hm,
).await
});
jh_vec.push(jh);
@ -289,10 +300,16 @@ impl MonitoringImporter {
/// 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
///
async fn process_endpoint(measure: Arc<String>, client: Arc<Client>, arc: Arc<Self>, hm: &HashMap<String, String>) -> anyhow::Result<PrometheusMetricsExtended> {
async fn process_endpoint(
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");
let resp = client
.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("access-token", &arc.access_token)
.send().await?

View File

@ -2,6 +2,12 @@
name = "integr-structs"
version = "0.1.0"
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]
anyhow = "1.0.95"