statserv: persist per-channel activity across restart too
All checks were successful
CI / check (push) Successful in 3m49s

The earlier StatsSet fix persisted only the shared namespaced counters. The
per-channel BOTSTATS view (lines seen + top talkers, from /statserv #chan) lived
on the LiveChannel struct, which is rebuilt from each burst — so it reset to zero
on restart. Move it to a name-keyed Network.chan_activity map (independent of live
membership, seedable before the burst) and carry it in the StatsSet snapshot
(new serde-default `channels` field) alongside the counters. Reworded the
notice from 'seen this session' now that it persists.
This commit is contained in:
Jean Chevronnet 2026-07-16 17:50:11 +00:00
parent 8a9b6a37ca
commit 1f6a11dba2
No known key found for this signature in database
8 changed files with 91 additions and 26 deletions

View file

@ -282,6 +282,9 @@ pub struct Report {
// The network-wide lists that aren't accounts/channels/grouped/bots: the network
// bans and the news items. Bundled so `apply` threads one parameter for them
// (and stays within its argument budget as more are added).
// Persisted per-channel BOTSTATS activity: (channel, line count, top talkers).
pub type ChanStats = Vec<(String, u64, Vec<(String, u64)>)>;
#[derive(Debug, Clone, Default)]
pub struct NetData {
pub akills: Vec<Akill>,
@ -310,6 +313,8 @@ pub struct NetData {
// Persisted shared stat counters (StatServ / gRPC Stats), snapshotted so they
// survive a restart (live gauges are re-derived, not stored here).
pub stats: std::collections::BTreeMap<String, u64>,
// Persisted per-channel BOTSTATS activity: (channel, lines, top talkers).
pub chan_stats: ChanStats,
}
// A session-limit exception: an IP-mask glob and the session allowance for IPs
@ -1168,8 +1173,11 @@ impl Db {
if self.net.default_bot.is_some() {
snapshot.push(Event::DefaultBotSet { bot: self.net.default_bot.clone() });
}
if !self.net.stats.is_empty() {
snapshot.push(Event::StatsSet { counters: self.net.stats.iter().map(|(k, v)| (k.clone(), *v)).collect() });
if !self.net.stats.is_empty() || !self.net.chan_stats.is_empty() {
snapshot.push(Event::StatsSet {
counters: self.net.stats.iter().map(|(k, v)| (k.clone(), *v)).collect(),
channels: self.net.chan_stats.clone(),
});
}
for host in &self.host_cfg.offers {
snapshot.push(Event::VhostOfferAdded { host: host.clone() });