Compare commits

..

14 Commits

Author SHA1 Message Date
James Brotosky 23529f1f94 Merge pull request 'Fixing timeout issue' (#60) from fix/timeout into master
Reviewed-on: brotoskyj/AirlockTools#60
2026-01-16 16:04:22 -05:00
brotoskyj 963aa3bcfb Fixing timeout issue
Build Library / Build Library (push) Has been cancelled
2026-01-16 13:37:58 -05:00
James Brotosky a609a088d5 Merge pull request 'Fixed History Logger' (#58) from fix/HistoryLogging into master
Reviewed-on: brotoskyj/AirlockTools#58
2026-01-08 15:46:57 -05:00
brotoskyj ccfdf4e7ab Refactor master branch to match last tag. There was an issue with formatting for some reason 2026-01-08 15:46:25 -05:00
brotoskyj a860dce421 Fixed History Logger 2026-01-08 15:39:58 -05:00
brotoskyj e19b748bac Closes #56 2026-01-08 15:22:05 -05:00
James Brotosky 01b80429f8 Merge pull request 'Fixed Telemetry Exporter' (#57) from fix/TelemetryExporter into master
Reviewed-on: brotoskyj/AirlockTools#57
2026-01-08 15:21:22 -05:00
brotoskyj 6a76c2ded7 Fixed Telemetry Exporter
Closes #56
2026-01-08 15:20:54 -05:00
brotoskyj f1c5080c97 Merge branch 'fix/loxidelibs' 2026-01-07 17:11:34 -05:00
brotoskyj 72681218e7 Fix for API Data Retrieval
Performance Optimization - History Logging was spawning a new tokio runtime every function call, it now uses the global run time
Documentation - Added a lot more span events for better logging
2026-01-07 17:01:33 -05:00
James Brotosky ededef6d30 Merge pull request 'RustLinting' (#54) from RustLinting into master
Reviewed-on: brotoskyj/AirlockTools#54
2026-01-05 10:18:38 -05:00
brotoskyj 5555747422 Styling - Progress Bar
Build Library / Build Library (push) Successful in 4m55s
Changed glyphs in progress bar for better printing to console
closes #51
2025-12-18 12:58:51 -05:00
brotoskyj 729b45f52a Features - Optional Policy Name in Execution Histories
Build Library / Build Library (push) Successful in 4m51s
closes #48
2025-12-18 10:14:58 -05:00
brotoskyj 66bb21ed88 Styling - Progress Bar
Build Library / Build Library (push) Successful in 5m21s
Changed progress bar indicators and added policy name to the progress bar
closes #50
2025-12-17 16:38:53 -05:00
5 changed files with 72 additions and 16 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ dependencies = [
[[package]]
name = "airlock_libs"
version = "7.2.0"
version = "7.4.1"
dependencies = [
"chrono",
"crossbeam",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "airlock_libs"
version = "7.2.0"
version = "7.4.1"
edition = "2024"
[dependencies]
+1 -1
View File
@@ -4,7 +4,7 @@ build-backend = "maturin"
[project]
name = "airlock_libs"
version = "7.2.0"
version = "7.4.1"
description = "Airlock Digital API Wrapper"
readme = "README.md"
license = { text = "AGPL-3.0-only" }
+68 -12
View File
@@ -1,6 +1,6 @@
use crate::modules::datatypes::*;
use crate::prelude::*;
use opentelemetry::trace::SpanContext;
#[pyfunction]
pub fn pull_policy_exec_histories(
@@ -107,9 +107,10 @@ pub fn pull_policy_exec_histories(
});
let cutoff: chrono::NaiveDateTime =
Local::now().naive_local() - chrono::Duration::days(days);
let (tx, rx) = unbounded::<Vec<Group>>();
let (tx, rx) = unbounded::<(SpanContext, Vec<Group>)>();
let pb_clone = progress_bar.clone();
thread::spawn(move || {
let tracer = global::tracer("loxide");
let mut seen: HashMap<(String, String, String), Group> = if writeable_filepath.exists()
{
let contents: String = fs::read_to_string(&writeable_filepath).unwrap_or_default();
@@ -138,7 +139,22 @@ pub fn pull_policy_exec_histories(
} else {
HashMap::new()
};
while let Ok(parsed_responses) = rx.recv() {
while let Ok((parent_spancontext, parsed_responses)) = rx.recv() {
let parent_ctx = Context::new().with_remote_span_context(parent_spancontext);
let span = tracer.build_with_context(
tracer
.span_builder("Deduplicate and Write")
.with_kind(trace::SpanKind::Consumer),
&parent_ctx,
);
let cx = Context::current_with_span(span);
cx.span().add_event(
"Received Data from Producer",
vec![KeyValue::new(
"Items to Process",
parsed_responses.len().to_string(),
)],
);
for executions in parsed_responses {
if executions.checkpoint.is_empty() || executions.datetime.is_empty() {
continue;
@@ -167,11 +183,28 @@ pub fn pull_policy_exec_histories(
};
let data_write: String = serde_json::to_string_pretty(&final_response).unwrap();
match fs::write(&writeable_filepath, data_write) {
Ok(_) => {}
Ok(_) => {
cx.span().add_event(
"Writing Data to File",
vec![KeyValue::new("Success", "Ok".to_string())],
);
}
Err(e) => {
println!("Failed to write to: {:?}: {}", &writeable_filepath, e);
cx.span().add_event(
"Writing Data to File",
vec![KeyValue::new("Failed", e.to_string())],
);
cx.span()
.set_status(Status::error("Failed to Write to File"));
}
}
cx.span().add_event(
"Finished Deduplicating Data",
vec![KeyValue::new(
"Items Successfully Processed",
seen.len().to_string(),
)],
);
}
});
let mut first_date: Option<NaiveDate> = None;
@@ -194,13 +227,28 @@ pub fn pull_policy_exec_histories(
));
loop {
let execution_histories = tracer.in_span(checkpoint_number.to_string(), |cx| {
let results: ApiResponse = history_logging(
cx.span().add_event(
"Retrieving Responses from API",
vec![KeyValue::new(
"Checkpoint Number",
checkpoint_number.to_string(),
)],
);
let results: ApiResponse = rt.block_on(history_logging(
&base_url,
&exec_types,
&checkpoint_number,
&policy_names,
&client,
));
cx.span().add_event(
"Got Responses from API",
vec![KeyValue::new(
"Items in Response",
results.response.exechistories.len().to_string(),
)],
);
cx.span().set_status(Status::Ok);
cx.span().set_attribute(KeyValue::new(
"items_in_response",
results.response.exechistories.len().to_string(),
@@ -211,7 +259,16 @@ pub fn pull_policy_exec_histories(
if parsed_responses.is_empty() {
break;
}
tx.send(parsed_responses.clone()).unwrap();
match tx.send((cx.span().span_context().clone(), parsed_responses.clone())) {
Ok(_) => {}
Err(e) => {
cx.span().add_event(
"Failed to Send Items to Processor",
vec![KeyValue::new("Response from Processor", e.to_string())],
);
cx.span().set_status(Status::error("Processor Failed"))
}
}
checkpoint_number = parsed_responses.last().unwrap().checkpoint.clone();
if let Some(last_item) = parsed_responses.last()
&& let Ok(last_date) = NaiveDate::parse_from_str(
@@ -260,11 +317,10 @@ fn build_client(headers: HeaderMap) -> Result<reqwest::Client, reqwest::Error> {
Client::builder()
.danger_accept_invalid_certs(true)
.default_headers(headers)
.timeout(std::time::Duration::from_secs(300))
.build()
}
#[tokio::main]
#[tracing::instrument(name = "history_logging")]
async fn history_logging(
base_url: &String,
exec_types: &String,
@@ -286,14 +342,14 @@ async fn history_logging(
);
let res: Result<reqwest::Response, reqwest::Error> = client
.post(format!("{}/v1/logging/exechistories", base_url))
.json(&payload)
.body(payload)
.send()
.await;
match res {
Ok(res) => {
let first_response: ApiResponse = serde_json::from_str(&res.text().await.unwrap())
.expect("Failed to retrieve response from API");
return first_response;
first_response
}
Err(_res) => {
let failed_response: ApiResponse = ApiResponse {
@@ -302,7 +358,7 @@ async fn history_logging(
exechistories: vec![],
},
};
return failed_response;
failed_response
}
}
}
+1 -1
View File
@@ -23,4 +23,4 @@ pyperclip==1.11.0
# Custom/Private packages
--extra-index-url https://git.racooncity.org/api/packages/brotoskyj/pypi/simple/
airlock_libs==7.2.0
airlock_libs==7.4.1