swarm-controller: move the review concern into its own module
Refs #6897
This commit is contained in:
parent
b52fc0ec8e
commit
237cdaffaa
13 changed files with 24 additions and 12 deletions
|
|
@ -499,7 +499,7 @@ let
|
||||||
) exprs
|
) exprs
|
||||||
);
|
);
|
||||||
recorded =
|
recorded =
|
||||||
builtins.readFile ../../swarm-controller/src/review_classifier/metrics.rs
|
builtins.readFile ../../swarm-controller/src/review/review_classifier/metrics.rs
|
||||||
+ builtins.readFile ../../swarm-review-classifier/src/cost.rs;
|
+ builtins.readFile ../../swarm-review-classifier/src/cost.rs;
|
||||||
in
|
in
|
||||||
lib.elem "review-classifier.json" shipped
|
lib.elem "review-classifier.json" shipped
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,6 @@ mod message_stream;
|
||||||
mod meta_build;
|
mod meta_build;
|
||||||
mod meta_fanout;
|
mod meta_fanout;
|
||||||
mod meta_flake;
|
mod meta_flake;
|
||||||
mod notify_flows;
|
|
||||||
mod notify_router_api;
|
|
||||||
mod observability_grant;
|
mod observability_grant;
|
||||||
mod otel_http_client;
|
mod otel_http_client;
|
||||||
mod pause_hold;
|
mod pause_hold;
|
||||||
|
|
@ -87,8 +85,7 @@ mod proxy_credential;
|
||||||
mod pulls;
|
mod pulls;
|
||||||
mod queue_identity;
|
mod queue_identity;
|
||||||
mod read_policy;
|
mod read_policy;
|
||||||
mod request_reviewer;
|
mod review;
|
||||||
mod review_classifier;
|
|
||||||
mod routes;
|
mod routes;
|
||||||
mod schedules;
|
mod schedules;
|
||||||
mod ssh_connections;
|
mod ssh_connections;
|
||||||
|
|
@ -105,6 +102,8 @@ mod wanted;
|
||||||
mod webhook;
|
mod webhook;
|
||||||
|
|
||||||
use jobq::{Late, WorkerDeps, spawn_jobq_worker};
|
use jobq::{Late, WorkerDeps, spawn_jobq_worker};
|
||||||
|
// The review modules keep their crate-root paths (`crate::review_classifier::…`).
|
||||||
|
use review::{notify_flows, notify_router_api, request_reviewer, review_classifier};
|
||||||
use routes::AppState;
|
use routes::AppState;
|
||||||
use startup::{
|
use startup::{
|
||||||
agent_icon_reader, agent_status_reader, agents_md_reader, build_app,
|
agent_icon_reader, agent_status_reader, agents_md_reader, build_app,
|
||||||
|
|
|
||||||
7
swarm-controller/src/review/mod.rs
Normal file
7
swarm-controller/src/review/mod.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
//! The review concern: the review classifier, requested reviews and the
|
||||||
|
//! notification flows, with their routes.
|
||||||
|
|
||||||
|
pub(crate) mod notify_flows;
|
||||||
|
pub(crate) mod notify_router_api;
|
||||||
|
pub(crate) mod request_reviewer;
|
||||||
|
pub(crate) mod review_classifier;
|
||||||
|
|
@ -1406,7 +1406,7 @@ classifications:
|
||||||
let [yml_path, _] = RULES_PATHS;
|
let [yml_path, _] = RULES_PATHS;
|
||||||
let rules = parse_rules(
|
let rules = parse_rules(
|
||||||
yml_path,
|
yml_path,
|
||||||
include_str!("../../.hyperhive/review-classifier.yml").as_bytes(),
|
include_str!("../../../.hyperhive/review-classifier.yml").as_bytes(),
|
||||||
)
|
)
|
||||||
.expect("the repo's rules file parses");
|
.expect("the repo's rules file parses");
|
||||||
let names: Vec<_> = rules.iter().map(|c| c.name.as_str()).collect();
|
let names: Vec<_> = rules.iter().map(|c| c.name.as_str()).collect();
|
||||||
|
|
@ -214,14 +214,14 @@ pub(super) mod testing {
|
||||||
use super::{Metrics, SdkMeterProvider};
|
use super::{Metrics, SdkMeterProvider};
|
||||||
|
|
||||||
/// Instruments on a provider that exports to memory.
|
/// Instruments on a provider that exports to memory.
|
||||||
pub(in crate::review_classifier) struct Recorder {
|
pub(in crate::review::review_classifier) struct Recorder {
|
||||||
pub(in crate::review_classifier) metrics: Metrics,
|
pub(in crate::review::review_classifier) metrics: Metrics,
|
||||||
provider: SdkMeterProvider,
|
provider: SdkMeterProvider,
|
||||||
exporter: InMemoryMetricExporter,
|
exporter: InMemoryMetricExporter,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Recorder {
|
impl Recorder {
|
||||||
pub(in crate::review_classifier) fn new() -> Self {
|
pub(in crate::review::review_classifier) fn new() -> Self {
|
||||||
let exporter = InMemoryMetricExporter::default();
|
let exporter = InMemoryMetricExporter::default();
|
||||||
let reader = PeriodicReader::builder(exporter.clone()).build();
|
let reader = PeriodicReader::builder(exporter.clone()).build();
|
||||||
let provider = SdkMeterProvider::builder().with_reader(reader).build();
|
let provider = SdkMeterProvider::builder().with_reader(reader).build();
|
||||||
|
|
@ -246,7 +246,10 @@ pub(super) mod testing {
|
||||||
|
|
||||||
/// The counter `name`'s value per label set, each set as
|
/// The counter `name`'s value per label set, each set as
|
||||||
/// `key=value,key=value` in key order. Empty when nothing was added.
|
/// `key=value,key=value` in key order. Empty when nothing was added.
|
||||||
pub(in crate::review_classifier) fn counter(&self, name: &str) -> BTreeMap<String, u64> {
|
pub(in crate::review::review_classifier) fn counter(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
) -> BTreeMap<String, u64> {
|
||||||
self.export(name, |data| {
|
self.export(name, |data| {
|
||||||
let AggregatedMetrics::U64(MetricData::Sum(sum)) = data else {
|
let AggregatedMetrics::U64(MetricData::Sum(sum)) = data else {
|
||||||
panic!("not a u64 sum: {data:?}");
|
panic!("not a u64 sum: {data:?}");
|
||||||
|
|
@ -260,7 +263,10 @@ pub(super) mod testing {
|
||||||
|
|
||||||
/// The histogram `name`'s sample count per label set, as
|
/// The histogram `name`'s sample count per label set, as
|
||||||
/// [`Self::counter`] writes them.
|
/// [`Self::counter`] writes them.
|
||||||
pub(in crate::review_classifier) fn histogram(&self, name: &str) -> BTreeMap<String, u64> {
|
pub(in crate::review::review_classifier) fn histogram(
|
||||||
|
&self,
|
||||||
|
name: &str,
|
||||||
|
) -> BTreeMap<String, u64> {
|
||||||
self.export(name, |data| {
|
self.export(name, |data| {
|
||||||
let AggregatedMetrics::F64(MetricData::Histogram(h)) = data else {
|
let AggregatedMetrics::F64(MetricData::Histogram(h)) = data else {
|
||||||
panic!("not an f64 histogram: {data:?}");
|
panic!("not an f64 histogram: {data:?}");
|
||||||
|
|
@ -533,7 +533,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const OWN: &str = include_str!("../../../.hyperhive/review-classifier.yml");
|
const OWN: &str = include_str!("../../../../.hyperhive/review-classifier.yml");
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_new_rule_leaves_every_existing_entry_as_it_was_written() {
|
fn a_new_rule_leaves_every_existing_entry_as_it_was_written() {
|
||||||
Loading…
Reference in a new issue