Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/node/src/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ pub async fn run<T: Transport + 'static>(
guard: &up.guard,
keys: &up.keys,
api: apis.as_ref(),
admin: admin.as_ref(),
};
let publishing = scrape::publishing(metrics, index, sources);
let stopping = stop(watched, &orders, &peers, cores);
Expand Down
16 changes: 16 additions & 0 deletions crates/node/src/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ catalog! {
ApiRefused: Counter, "api_refused", "API connections refused by connection limits";
ApiForwarded: Counter, "api_forwarded", "API requests forwarded to another core";
ApiServed: Counter, "api_served", "API requests served for another core";
AdminAccepted: Counter, "admin_connections_accepted", "Admin connections accepted";
AdminRefused: Counter, "admin_connections_refused", "Admin connections refused by the peer list";
AdminFull: Counter, "admin_connections_full", "Admin connections refused because the session limit was reached";
AdminRequests: Counter, "admin_requests", "Admin requests answered";
AdminMalformed: Counter, "admin_requests_malformed", "Admin requests that could not be decoded";
AdminSessions: Gauge, "admin_sessions", "Open admin sessions";
GuardSessions: Gauge, "guard_sessions", "Sessions held by the connection guard";
GuardReservedBytes: Gauge, "guard_reserved_bytes", "Memory reserved by sessions";
GuardPeakReservedBytes: Gauge, "guard_peak_reserved_bytes", "Highest memory reserved by sessions since start";
Expand Down Expand Up @@ -151,6 +157,7 @@ pub(crate) struct Sources<'a, T> {
pub guard: &'a Guard,
pub keys: &'a Keyring,
pub api: Option<&'a api::Api>,
pub admin: Option<&'a admin::Admin>,
}

impl<T: Transport + 'static> Sources<'_, T> {
Expand Down Expand Up @@ -201,6 +208,15 @@ impl<T: Transport + 'static> Sources<'_, T> {
set(Id::ApiForwarded, api.forwarded());
set(Id::ApiServed, api.served());
}
if let Some(admin) = self.admin {
let stats = admin.stats();
set(Id::AdminAccepted, stats.accepted);
set(Id::AdminRefused, stats.refused);
set(Id::AdminFull, stats.full);
set(Id::AdminRequests, stats.requests);
set(Id::AdminMalformed, stats.malformed);
set(Id::AdminSessions, wide(admin.sessions()));
}
let guard = self.guard.stats();
set(Id::GuardSessions, wide(guard.sessions));
set(Id::GuardReservedBytes, wide(guard.reserved));
Expand Down
73 changes: 73 additions & 0 deletions crates/node/tests/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,3 +946,76 @@ fn admin_creates_suspends_and_resumes_tenants() {
assert_eq!(tenants, [5, 6]);
});
}

#[test]
fn the_admin_simulation_runs_every_command_and_stops() {
use admin::Code::{NotFound, Ok};
use admin::Request::{
KeyCreate, KeyList, KeyRevoke, PoolList, PoolSet, QueueList, QueueRebind, QueueRetry,
Status, TenantList, TenantResume, TenantSuspend,
};
let driver = created(24);
let extra = format!("[admin]\nsocket = \"{ADMIN}\"\n");
let node = booted(&driver, config_with(7, &extra), CORES);
let machine = &node.machine;
machine.block_on(0, async {
drop(serving().await);
assert_eq!(ask(Status).await.0, Ok);
let pool = admin::PoolSpec {
id: 1,
addresses: vec![("192.0.2.1".parse().expect("ip"), 1)],
};
assert_eq!(ask(PoolSet(pool)).await.0, Ok);
assert_eq!(ask(PoolList(0)).await.0, Ok);
assert_eq!(ask(tenant(5, &[1])).await.0, Ok);
assert_eq!(ask(TenantList(0)).await.0, Ok);
assert_eq!(ask(TenantSuspend(5)).await.0, Ok);
assert_eq!(ask(TenantResume(5)).await.0, Ok);
let key = KeyCreate {
tenant: 5,
smtp: true,
api: false,
hooks: false,
pool: 1,
};
assert_eq!(ask(key).await.0, Ok);
assert_eq!(ask(KeyList { tenant: 5, from: 0 }).await.0, Ok);
assert_eq!(ask(KeyRevoke { tenant: 5, id: 1 }).await.0, Ok);
assert_eq!(ask(QueueList { tenant: 5, from: 0 }).await.0, Ok);
assert_eq!(
ask(QueueRetry {
tenant: 5,
queue: 1
})
.await
.0,
NotFound
);
let rebind = QueueRebind {
tenant: 5,
queue: 1,
pool: 1,
};
assert_eq!(ask(rebind).await.0, NotFound);

sleep(Duration::from_secs(2)).await;
let text = scrape("GET /metrics HTTP/1.1\r\nHost: x\r\nConnection: close\r\n\r\n").await;
let total = |family: &str| -> u64 {
text.lines()
.filter_map(|line| line.strip_prefix(family)?.strip_prefix('{'))
.filter_map(|rest| rest.split(' ').nth(1)?.parse::<u64>().ok())
.sum()
};
assert_eq!(total("bunzzle_admin_requests_total"), 13, "{text}");
assert_eq!(total("bunzzle_admin_requests_malformed_total"), 0);
assert_eq!(total("bunzzle_admin_connections_accepted_total"), 13);
assert_eq!(total("bunzzle_admin_connections_refused_total"), 0);
assert_eq!(total("bunzzle_admin_connections_full_total"), 0);
});
stopped(&driver, node);
let machine = Machine::new(Rc::clone(&driver), 1, Stalls::default());
machine.block_on(0, async {
let refused = rt::UnixStream::connect(Path::new(ADMIN)).await;
assert!(refused.is_err());
});
}
Loading