Skip to content

Commit

Permalink
Suite results: Include more data
Browse files Browse the repository at this point in the history
The following data will be needed on the server side for computing check
results:
* Timestamp when merged XML (rebot) was created. We explicitly don't use
  timestamps contained in the XML because these timestamps do not
  include timezone information, which can lead to issues if the Checkmk
  server is in a different timezone.
* execution interval
* timeout
* maximum number of attempts
  • Loading branch information
jherbel committed Nov 13, 2023
1 parent a8f9702 commit 2b5c7ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 9 additions & 0 deletions v2/robotmk/src/bin/scheduler/results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub enum ExecutionReport {
pub struct AttemptsOutcome {
pub attempts: Vec<AttemptOutcome>,
pub rebot: Option<RebotOutcome>,
pub config: AttemptsConfig,
}

#[derive(Serialize)]
Expand All @@ -138,4 +139,12 @@ pub enum RebotOutcome {
pub struct RebotResult {
pub xml: String,
pub html_base64: String,
pub timestamp: i64,
}

#[derive(Serialize)]
pub struct AttemptsConfig {
pub interval: u32,
pub timeout: u64,
pub n_attempts_max: usize,
}
9 changes: 6 additions & 3 deletions v2/robotmk/src/bin/scheduler/rf/rebot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::results::{RebotOutcome, RebotResult};
use anyhow::{Context, Result};
use base64::{engine::general_purpose, Engine};
use camino::{Utf8Path, Utf8PathBuf};
use chrono::Utc;
use log::debug;
use log::error;
use std::fs::{read, read_to_string};
Expand All @@ -20,13 +21,14 @@ pub struct Rebot<'a> {

impl Rebot<'_> {
pub fn rebot(&self) -> RebotOutcome {
let timestamp = Utc::now().timestamp();
match self.run() {
Ok(output) => match output.status.code() {
Some(exit_code) => match self.environment.create_result_code(exit_code) {
ResultCode::AllTestsPassed => self.process_successful_run(),
ResultCode::AllTestsPassed => self.process_successful_run(timestamp),
ResultCode::RobotCommandFailed => {
if self.path_xml.exists() {
self.process_successful_run()
self.process_successful_run(timestamp)
} else {
Self::process_failure(&output, "Rebot run failed (no merged XML found)")
}
Expand Down Expand Up @@ -67,12 +69,13 @@ impl Rebot<'_> {
rebot_command_spec
}

fn process_successful_run(&self) -> RebotOutcome {
fn process_successful_run(&self, timestamp: i64) -> RebotOutcome {
match read_to_string(self.path_xml) {
Ok(merged_xml) => match read(self.path_html) {
Ok(merged_html) => RebotOutcome::Ok(RebotResult {
xml: merged_xml,
html_base64: general_purpose::STANDARD.encode(merged_html),
timestamp,
}),
Err(error) => {
let error_message = format!(
Expand Down
9 changes: 8 additions & 1 deletion v2/robotmk/src/bin/scheduler/scheduling/suites.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::environment::ResultCode;
use crate::internal_config::Suite;
use crate::results::{AttemptOutcome, AttemptsOutcome, ExecutionReport, SuiteExecutionReport};
use crate::results::{
AttemptOutcome, AttemptsConfig, AttemptsOutcome, ExecutionReport, SuiteExecutionReport,
};
use crate::rf::{rebot::Rebot, robot::Attempt};
use crate::sessions::session::{RunOutcome, RunSpec};

Expand Down Expand Up @@ -92,6 +94,11 @@ fn produce_suite_results(suite: &Suite) -> Result<AttemptsOutcome> {
.rebot(),
)
},
config: AttemptsConfig {
interval: suite.execution_interval_seconds,
timeout: suite.timeout,
n_attempts_max: suite.robot.n_attempts_max,
},
})
}

Expand Down

0 comments on commit 2b5c7ee

Please sign in to comment.