Commit Graph
161 Commits
Author SHA1 Message Date
Lars Wirzenius 62faeeec02 refactor: drop now-unnecessary pragma to allow unused imports
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-05-14 08:00:21 +03:00
Lars Wirzenius 06449445ec feat: enable adapter concurrency in cib
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-05-13 09:02:12 +03:00
Lars Wirzenius 55023f2e4f refactor: rewrite the timeoutcmd module for simplicity
Feed child process stdin via a temporary file. This is simpler than
opening a pipe and spawning a thread that feeds the pipe, when it's
not full.

Capture child stderr into a buffer without trying to let the
caller (another thread) process it line by line. We don't seem to have
use for that, and this simplifies things a fair bit.

Simplify the capture of child stdout to use a simpler thread and data
structure, compared to the previous multi-thread setup. Splitting
stdout into lines is now done by the thread that consumes the lines,
making the code that captures it simpler.

Also update the timeout subcommand to work with the changes. Other
callers of this code aren't yet updated.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-05-13 09:02:12 +03:00
Tshepang Mbambo 0e746060fe process-events help: add missing space 2025-05-13 08:59:38 +03:00
Lars Wirzenius 8d7989cc6a Revert "fix: "cibtool run list" shows ids without loading run info"
This reverts commit 900a457157.
2025-04-17 17:04:46 +03:00
Lars Wirzenius 765e6b606c fix: "cibtool run remove" removed only by broker run id by default
We need to parse the run info in the database as JSON to get at the
adapter run info. This fails if the run info can't be parsed. That can
happen if the database has run info from a development version. Change
`cibtool run remove` so that it takes only broker run ids by default
so that we can delete using those even if the run info is broken.
Allow removing by adapter run id with the `--adapter` option.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-04-07 15:35:47 +03:00
Lars Wirzenius 900a457157 fix: "cibtool run list" shows ids without loading run info
If the run info can't be parsed as JSON, loading it will fail. Change
`cibtool run list` so that it only lists the run ids by default.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-04-07 15:34:57 +03:00
Lars Wirzenius 7cab201b41 feat: version number now includes Git commit short id
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-03-31 15:04:06 +03:00
Lars Wirzenius 88d819d556 fix(src/bin/cib.rs): log failure of page updater thread
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-03-24 18:07:38 +02:00
Lars Wirzenius 0d1d3291cc fix: use new Git refs module, fix bugs found
This is a huge change, but it's mostly a few kinds of similar changes
in a lot of places. Unfortunately, they were not easy to tease apart
into small, easily reviewed commits.

Use the Git ref types created by the new refs module. Fix problems
this exposes.

The CiEvent enum variants for branch events now use the BranchName
type for branch names. In other words, they have a plain branch name.
The CiEvent::from_node_event constructor also always sets the branch
name to a plain branch name, instead of a name spaced ref for updated
or deleted branches. The ci_event.rs module's unit tests have been
fixed to use the correct kind of Git ref in each test. (It used to be
a mess.)

The CI event filter "Branch" now contains a BranchName, previously a
RefString. This should not break anything, as a RefString will always
work as a BranchName.

The DefaultBranch filter now works, because it compares plain branch
names, where it previously would compare a plain and a name spaced
branch name, and those are never equal.

"cibtool trigger" and "cibtool event add" now add branch events with a plain
branch instead of a name spaced ref.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-03-20 18:33:39 +02:00
Lars Wirzenius 746445cb86 feat: "event filter --explain" shows why an event was allowed or not
Also refactor the code that makes the decision for simplicity and
clarity.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-03-10 19:42:27 +02:00
Lars Wirzenius 43306e1513 feat: output trigger event to stdout, file
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-03-04 18:43:57 +02:00
Lars Wirzenius fe9ffca3d2 feat: cibool run remove
Also fix Db::remove_run, which has never actually worked, because the
run id column was named wrongly. Oops.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-03-04 17:43:05 +02:00
Lars Wirzenius c45291bc6a feat: use the same Oid type everywhere
Previously we imported the Oid type (for Git object identifiers)
different places. This was confusing, and also meant that upgrading a
dependency (radicle-git-ext) broke, because two types with the same
name imported from different versions of the same crate are different
types.

Change this so that radicle::git::Oid is the one true Oid type we use.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-02-26 17:41:08 +02:00
Lars Wirzenius 08bcf70308 refactor: simplify patch related constructors for CiEvent
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-02-18 16:34:58 +02:00
Lars Wirzenius 94b3de7385 fix: DefaultBranch event filter didn't work with namespaced refs
The CI event contains a namespaced ref. The default branch we get
also. The CI broker filter configuration does not. Fix
src/filter.rs::is_default_branch to compare only the un-namespaced
branch names.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-02-17 12:25:36 +02:00
Lars Wirzenius 59deeed8c1 test(ci-broker.md): verify event filter Node
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-29 17:41:37 +02:00
Lars Wirzenius 3da72805e9 feat! drop Db::queued_events
For several releases already, `cib` has refused to start if the
database has any "broker events". Broker events were a predecessor for
CI events, and they haven't been supported by the CI broker since
0.7.0, from October 2024.

Drop the Db method to query the database for queued broker events.
Also drop the creation of a table for that queue.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-27 17:41:02 +02:00
Lars Wirzenius 9af108485d feat: add optional "triggers" to config
A trigger is a condition (filter) when to run CI using a specific
adapter. Change the configuration to allow them, and make the old list
of filters and default adapter be optional. This way, the user can use
either or both.

CI is run for each of:

- top level filter matches, using default adapter
- trigger filter matches, using the adapter specified in the trigger

To be clear, this can mean that CI is run many times for one CI event.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-21 19:07:07 +02:00
Lars Wirzenius ee34af59f1 feat: construct a collection of all adapters that knows the default
Construct the collection, and give it to the queue processor, which is
the only part that needs to know what adapters there are.

For now, only the default adapter is used, but this makes a space from
which to pick a different for each CI run.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-21 17:01:34 +02:00
Lars Wirzenius ba644e14d6 feat: filter queued events when they are processed
Move CI event filtering from the queue adder to the queue processor.
This is ground work for supporting different adapters for different
runs.

Later, each "trigger" will have a separate filter, and if the filter
allows an event, the adapter for that trigger is run. However, we have
no way to communicate the chosen adapter via the event queue in the
database, without making a breaking database schema, which I would
prefer to avoid.

Instead, we add all events into the queue, and filter when we remove
them from the queue. This may be a little wasteful in terms of disk
space and I/O, if there are very large numbers of events. If this
turns out to be too expensive, we'll revert this change and do a
breaking schema change.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-21 17:00:19 +02:00
Lars Wirzenius 73c533580a refactor: Broker::execute_ci is given adapter to use
Remove the default adapter from Broker, and make callers give the
adapter to use to the Broker::execute_ci method each time. This is
ground work for allowing different adapters for different CI runs.

There's no need for Broker to know about any adapters, except the one
it is currently running.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-21 17:00:16 +02:00
Lars Wirzenius e55a7de242 refactor: Config::default_adapter returns an adapter, not its config
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-20 17:57:19 +02:00
Lars Wirzenius 2a7ddc303a refactor: can't create a Broker without setting default adapter
There's no point in making it optional at this stage.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-20 17:34:40 +02:00
Lars Wirzenius b8171031f6 refactor(src/config.rs): rename Adapter to AdapterConfig
This makes it less likely to be confused with create::adapter::Adapter.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-20 17:15:41 +02:00
Lars Wirzenius 07d9db2018 refactor: Config::default_adapter returns an error if no default set
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-20 17:15:41 +02:00
Lars Wirzenius 47f776392e refactor: prevent direct access to struct Config fields
Make struct Config fields private and introduces getter methods to
access them. This will make it easier to change the CI broker to be
able to run different adapters for different changes.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-20 14:14:18 +02:00
Lars Wirzenius daed76ff4d feat: cibtool trigger --ref defaults to main, --commit to HEAD
This simplifies using "cibtool trigger" a tiny bit.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-14 19:16:13 +02:00
Lars Wirzenius f814880aeb feat: make cibool trigger --ref be preferred over --name
Either will continue to work.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-14 19:11:34 +02:00
Lars Wirzenius b33aae598c fix: actually set the log interval from the config
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2025-01-14 18:08:31 +02:00
Lars Wirzenius 9f5fff09b0 feat: subcommand "log" to format and filter cib logs from journald
Add subcommand "cibtool log" to extract cib log messages from journald
logs, and pretty print them. Optionally with some very rudimentary
filtering based on log level, message kind, or broker run id.

Example:

    sudo journalctl -S today -u radicle-ci-broker -o json | cibtool log --log-level info

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-12-12 17:35:22 +02:00
Lars Wirzenius f42ea5cb9c refactor: add RunBuilder to build a Run
This is a nicer interface than the old Run::new, with many arguments.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-12-05 15:43:58 +02:00
Lars Wirzenius e431a10f35 feat: add broker run ID to log messages related to a specific CI run
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-12-05 15:22:47 +02:00
Lars Wirzenius 1bc0ad40dc feat: cibtool can add every type of CI event to event queue
Add support to "cibtool event add" for branch deletion, and patch
creation and update events. Use this in a scenario that adds every
type of event to the queue and processes them. This ensures the CI
broker can actually handle any kind of CI event.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-12-05 08:20:04 +02:00
Lars Wirzenius ac3fcf28a3 doc: add help texts to cib options and subcommands
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-12-04 11:01:49 +02:00
Lars Wirzenius ee177c8f20 chore: drop unnecessary Logger
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-11-27 13:23:32 +02:00
Lars Wirzenius cf395350ea feat: use the tracing crate for structured logging
Switch from the "slog" family of crates for structured logging to the
"tracing" family. There should be no significant changes to the log
messages, so I don't consider this to be a breaking change.

The benefit of this change is that it opens up the possibility to add
extra fields to the log messages as JSON values, instead of strings
that contain the values as JSON.

With slog we currently have this message::

  {"msg":"broker database: /home/_rad/ci-broker.db"}

With slog or tracing we can change this to:

  {"msg":"open database", "filename": "/home/_rad/ci-broker.db"}

With tracing we can have this:

  {"msg":"open database","db":{"type":"sqlite","filename":"/home/_rad/ci-broker.db","size":12765}}

which would be, formatted prettily

  {
    "msg": "open database",
    "db": {
      "type": "sqlite",
      "filename": "/home/_rad/ci-broker.db",
      "size": 12765
    }
  }

Such extra fields can then be easily queried or otherwise processed
with programs, much more easily than having such programs parse text
fields as JSON before they can be processed.

Doing this with slog is supposed to be possible, but I have failed to
get it to work. The slog and tracing families of libraries seem
otherwise similar for our purposes.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-11-26 18:57:25 +02:00
Lars Wirzenius 43c076c22e feat: generate sample adapter messages with cibtool
This is meant only for generating documentation, but might be useful
for others.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-11-13 09:45:29 +02:00
Lars Wirzenius 5aea92df7b feat: make it harder to leak sensitive environment variables
Add a new type for sensitive values, for `sensitive_envs`.

The CI broker can define sensitive environment variables for each
adapter, in the `sensitive_envs` field in the configuration file. The
idea is the this can be used to configure, say, API keys that the CI
run needs. To avoid them leaking accidentally, the code tries to
prevent the sensitive value from being printed. However, there have
been case where this has failed to be done correctly. The problem is
that each place where the `Config` value is used needs to be careful
to avoid leaking sensitive data.

The new type provides the protection in a more concentrated location.
The value can be created via serde de-serialization, but can't be
printed using normal formatting, debug formatting, or serde
serialization. This doesn't protect against the sensitive value
leaking via a core dump, or direct memory reading.

None of this makes it a good idea to use environment variables to
convey sensitive values. They're a bad idea and one should find a
better way to achieve the same thing. However, as long as the CI
broker provides the `sensitive_envs` configuration variable the least
it can do is try to make it hard to accidentally leak the values.

This is not a breaking change.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-11-12 08:17:43 +02:00
Lars Wirzenius 55e1e7dba5 feat: add optional max_run_time field to configuration file
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-11-06 18:52:30 +02:00
Lars Wirzenius 0e78c6a8d8 feat: add a "cibtool timeout" subcommand
This lets us use the previously added code to run a sub-process with a
time limit. This is only meant for experimentation.
2024-11-06 16:30:42 +02:00
Lars Wirzenius 10ee855966 refactor: store timeout in receiver, separate event/run senders
Add new NotificationChannel constructors, for different kinds of
channels. Store the receive timeout in the receiver; it depends on
kind of channel.

Also add methods to send and receive notifications to senders and
receivers. This hides the std::sync::mpsc machinery better, and makes
the types easier to use.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-10-21 16:11:12 +03:00
Lars Wirzenius caf839b592 feat: add cibtool remove event option --all to empty event queue
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-10-21 11:42:04 +03:00
Lars Wirzenius 938f627443 feat: cibtool event add --base value is not rev-parsed
This allows a value of, say, HEAD, which is convenient.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-10-11 08:58:21 +03:00
Lars Wirzenius 320c426904 refactor: make BrokerError::NotTrigger not be so large
It's awkward if enum variants have wildly different sizes. Change
BrokerError::NotTrigger to store the Request value in a Box, so that
it's not in the enum directly. This makes all variants about the same
size, and thus the decorators that allow the
clippy::large_enum_variant can be dropped.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-10-10 18:44:11 +03:00
Lars Wirzenius 145e061aff feat: make CI events versioned
This will help us avoid breaking changes in the future, when CI events
need to be modified, and CI broker instances need to cope with the
event queues in their databases.

Previously we had

    enum CiEvent {
        BranchCreated { ... },
        BranchUpdatee { ... },
        ....
    }

Change that to:

    enum CiEvent {
        V1(CiEventV1),
    }

    enum CiEventV1 {
        BranchCreated { ... },
        BranchUpdatee { ... },
        ....
    }

This will allow us to add new version variants to CiEvent, without
losing access to the already enqueued V1 events.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-10-10 18:11:16 +03:00
Lars Wirzenius 85efaa10d1 feat: allow user to set minimum log level for cib
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-10-10 12:35:51 +03:00
Lars Wirzenius 47064e5785 chore: deny clippy warning about unwrap being used
An unwrap (or unwrap_err, or their expect variants) can result in run
time panics: unwrapping an Option that is None can't return a useful
result, so it panics. Similar for a Result. I've previously tried to
grep for uses of unwrap, but the clippy warning is much more precise.

Add "deny(clippy::unwrap_used)" to the top of src/lib.rs, so it
affects the whole crate. Then fix any places where unwrap is used.

It's OK to use unwrap in tests: if the value is expected, but isn't
there, the test should fail, and panic is a fine way to fail the test.

Everywhere else it's better to make sure unwrap can't fail, and if it
can, return a Result and have the caller handle that.

Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-10-09 10:16:41 +03:00
Lars Wirzenius a9fea0fdbe Merge branch 'patch/bc2cc00' 2024-10-09 09:32:13 +03:00
Lars Wirzenius feec4a501e fix: remove unnecessary borrows
Signed-off-by: Lars Wirzenius <liw@liw.fi>
2024-10-09 09:24:26 +03:00