Radish alpha
r
rad:zwTxygwuz5LDGBq255RA2CbNGrz8
Radicle CI broker
Radicle
Git
feat: add length of event queue to status.json
Merged liw opened 1 year ago

Signed-off-by: Lars Wirzenius liw@liw.fi

3 files changed +56 -1 85414e86 1da13086
modified ci-broker.md
@@ -21,6 +21,8 @@ be named in one place:
  - Lars Wirzenius
  - Michalis
  - Yorgos Saslis
+
* `node-ops` – the people operating a Radicle node, when they
+
  also run Radicle CI on it

Some stakeholders are named explicitly so that it will be easier to
ask them more information that is captured in this document. Note that
@@ -694,6 +696,7 @@ when I run bash radenv.sh cibtool --db ci-broker.db event add --repo testy --ref
when I run cibtool --db ci-broker.db event shutdown

given file broker.yaml
+
given a directory reports
when I run ls -l adapter.sh
when I run bash radenv.sh cib --config broker.yaml queued
then stderr contains "Action: run:"
@@ -1068,6 +1071,7 @@ when I run chmod +x adapter.sh
given an installed cib

given file broker.yaml
+
given a directory reports
when I run bash radenv.sh cib --config broker.yaml queued

then stderr contains "CI broker starts"
@@ -1096,3 +1100,35 @@ when I try to run cib --config broker.yaml queued
then stderr contains "CI broker starts"
then stderr contains "CI broker ends in unrecoverable error"
~~~
+

+
# Acceptance criteria for reports
+

+
The CI broker creates HTML and JSON reports on a schedule, as well as
+
when CI runs end. The scenarios in this chapter verify that those
+
reports are as wanted.
+

+
## Produces a JSON status file
+

+
_What:_ `cib` produces a JSON status file with information about the
+
current state of the CI broker.
+

+
_Why:_ This makes it easy to monitor the CI broker using an automated
+
monitoring system.
+

+
_Who:_ `node-ops`
+

+
~~~scenario
+
given file radenv.sh
+
given file setup-node.sh
+
when I run bash radenv.sh bash setup-node.sh
+

+
given an installed cib
+
given file broker.yaml
+
given a directory reports
+

+
when I run bash radenv.sh cib --config broker.yaml queued
+
then file reports/status.json exists
+

+
when I run jq .event_queue_length reports/status.json
+
then stdout is exactly "0\n"
+
~~~
modified src/bin/cib.rs
@@ -129,7 +129,7 @@ struct QueuedCmd {}

impl QueuedCmd {
    fn run(&self, args: &Args, config: &Config) -> Result<(), CibError> {
-
        let db = args.open_db(config)?;
+
        let profile = Profile::load().map_err(CibError::profile)?;

        let mut broker = Broker::new(config.db()).map_err(CibError::new_broker)?;
        let spec =
@@ -149,6 +149,7 @@ impl QueuedCmd {

        let mut run_notifications = NotificationChannel::default();

+
        let db = args.open_db(config)?;
        let processor = QueueProcessorBuilder::default()
            .events_rx(event_notifications.rx())
            .run_tx(run_notifications.tx())
@@ -162,6 +163,22 @@ impl QueuedCmd {
            .expect("wait for thread to finish")
            .map_err(CibError::process_queue)?;

+
        let db = args.open_db(config)?;
+
        let mut page = PageBuilder::default()
+
            .node_alias(&profile.config.node.alias)
+
            .runs(db.get_all_runs().map_err(CibError::db)?)
+
            .build()
+
            .map_err(CibError::page_updater)?;
+

+
        if let Some(dirname) = &config.report_dir {
+
            page.set_output_dir(dirname);
+
        }
+
        let page_updater = page.update_in_thread(run_notifications.rx(), profile, db, true);
+
        page_updater
+
            .join()
+
            .expect("wait for page updater thread to finish")
+
            .expect("page updater thread succeeded");
+

        Ok(())
    }
}
modified src/pages.rs
@@ -659,6 +659,7 @@ struct StatusData {
    ci_broker_git_commit: &'static str,
    latest_broker_event: Option<BrokerEvent>,
    latest_ci_run: Option<Run>,
+
    event_queue_length: usize,
}

impl StatusData {
@@ -676,6 +677,7 @@ impl From<&PageData> for StatusData {
            ci_broker_git_commit: page.ci_broker_git_commit,
            latest_broker_event: page.latest_broker_event.clone(),
            latest_ci_run: page.latest_ci_run.clone(),
+
            event_queue_length: page.events.len(),
        }
    }
}