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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>