Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat: add broker run ID to log messages related to a specific CI run
Lars Wirzenius committed 1 year ago
commit e431a10f359e03e117c7ccf549f07c74551b4713
parent 162d80347c6be8bdbe858e24af100194ac897e17
4 files changed +28 -6
modified src/adapter.rs
@@ -271,7 +271,7 @@ mod test {
    use super::{Adapter, Db, Run};
    use crate::{
        adapter::AdapterError,
-
        msg::{MessageError, Response, RunResult},
+
        msg::{MessageError, Response, RunId, RunResult},
        notif::NotificationChannel,
        run::Whence,
        test::{mock_adapter, trigger_request, TestResult},
@@ -287,6 +287,7 @@ mod test {

    fn run() -> anyhow::Result<Run> {
        Ok(Run::new(
+
            RunId::default(),
            RepoId::from_urn("rad:zwTxygwuz5LDGBq255RA2CbNGrz8")?,
            "test.repo",
            Whence::branch(
modified src/bin/cibtoolcmd/run.rs
@@ -63,7 +63,7 @@ impl Leaf for AddRun {
            commit: oid,
            who: self.who.clone(),
        };
-
        let mut run = Run::new(rid, &repo_name, whence, ts);
+
        let mut run = Run::new(RunId::default(), rid, &repo_name, whence, ts);

        let id = self.id.clone().unwrap_or_default();
        run.set_adapter_run_id(id);
modified src/broker.rs
@@ -10,6 +10,7 @@ use std::{
};

use time::{macros::format_description, OffsetDateTime};
+
use tracing::{span, Level};

use radicle::prelude::RepoId;

@@ -17,7 +18,7 @@ use crate::{
    adapter::Adapter,
    db::{Db, DbError},
    logger,
-
    msg::{PatchEvent, PushEvent, Request},
+
    msg::{PatchEvent, PushEvent, Request, RunId},
    notif::NotificationSender,
    run::{Run, Whence},
};
@@ -73,6 +74,19 @@ impl Broker {
        trigger: &Request,
        run_notification: &NotificationSender,
    ) -> Result<Run, BrokerError> {
+
        let broker_run_id = RunId::default();
+
        let span = span!(Level::TRACE, "execute_ci_run", %broker_run_id,).entered();
+
        let run =
+
            span.in_scope(|| self.execute_helper(broker_run_id, trigger, run_notification))?;
+
        Ok(run)
+
    }
+

+
    fn execute_helper(
+
        &self,
+
        broker_run_id: RunId,
+
        trigger: &Request,
+
        run_notification: &NotificationSender,
+
    ) -> Result<Run, BrokerError> {
        logger::broker_start_run(trigger);
        let run = match trigger {
            Request::Trigger {
@@ -104,7 +118,8 @@ impl Broker {
                        panic!("neither push not patch event");
                    };

-
                    let mut run = Run::new(*rid, &common.repository.name, whence, now()?);
+
                    let mut run =
+
                        Run::new(broker_run_id, *rid, &common.repository.name, whence, now()?);
                    self.db.push_run(&run)?;

                    // We run the adapter, but if that fails, we just
modified src/run.rs
@@ -23,9 +23,15 @@ pub struct Run {

impl Run {
    /// Create a new run.
-
    pub fn new(repo_id: RepoId, name: &str, whence: Whence, timestamp: String) -> Self {
+
    pub fn new(
+
        broker_run_id: RunId,
+
        repo_id: RepoId,
+
        name: &str,
+
        whence: Whence,
+
        timestamp: String,
+
    ) -> Self {
        Self {
-
            broker_run_id: RunId::default(),
+
            broker_run_id,
            adapter_run_id: None,
            adapter_info_url: None,
            repo_id,