Tracers whose settings change start over on reload
A cluster rehearsal moved a Log tracer to another directory: the write was reported x:settingsReload applied:true, but the tracer kept writing to the old file until a restart. Telemetry::update only refreshed each running tracer's events, level and lossiness; a tracer's own settings (path, prefix, rotation, format, endpoint, headers, ...) stayed as built. Each tracer now carries a hash of the registry object it was built from, less the fields that change in place. The reload compares it with the running tracer's: unchanged ones are updated in place as before, changed ones are started over, new ones started and removed ones stopped. Only tracers this server started are removed; upstream removed every subscriber not in the settings, which also cut off live-tracing streams on each reload. Starting over is a swap in the collector, so no event is lost or written twice: a subscriber registered under a running one's id replaces it between two collection passes. The old one's batch is sent first (what its full channel can't take moves to the new one), and dropping it closes its channel, so its task writes what is queued and ends. Per tracer kind: - Log: a tracer started over on the same files (rotation or format changed) waits for the old one to finish, so lines don't interleave. - Webhook: the task held a sender of its own channel for retries, so it never ended; retries now use a weak sender, and pending events are posted when the channel closes. - OpenTelemetry: pending logs and spans are exported when the channel closes instead of dropped, and a span that was open across the swap is exported by the new tracer with the events it saw. - Console and journal: nothing kept between batches. - Trace history: built from the tracing store, which takes a restart, so it is never started over. No kind needs a restart, so x:settingsReload doesn't gain one. system::tracer_reload::tracer_reload_tests (new): a Log tracer created over JMAP writes to its directory; its path is changed over JMAP while 2000 numbered events are emitted; after the reload, events land in the new file and not the old one, each numbered event is in exactly one of the two files, and a destroyed tracer writes nothing. On main the new file never appears.
This commit is contained in:
@@ -14,15 +14,26 @@ pub mod webhooks;
|
||||
use tracers::log::spawn_log_tracer;
|
||||
use tracers::otel::spawn_otel_tracer;
|
||||
use tracers::stdout::spawn_console_tracer;
|
||||
use ahash::AHashMap;
|
||||
use parking_lot::Mutex;
|
||||
use trc::{Collector, ipc::subscriber::SubscriberBuilder};
|
||||
use webhooks::spawn_webhook_tracer;
|
||||
|
||||
use crate::config::telemetry::{Telemetry, TelemetrySubscriberType};
|
||||
|
||||
/// inbuxa: the tracers this server started, by subscriber id, with the
|
||||
/// settings each was built from. Live-tracing streams and other subscribers
|
||||
/// registered elsewhere aren't listed, so a reload leaves them running.
|
||||
static RUNNING_TRACERS: Mutex<Option<AHashMap<String, u64>>> = Mutex::new(None);
|
||||
|
||||
impl Telemetry {
|
||||
pub fn enable(self) {
|
||||
let mut running = RUNNING_TRACERS.lock();
|
||||
let running = running.get_or_insert_with(AHashMap::new);
|
||||
|
||||
// Spawn tracers
|
||||
for tracer in self.tracers.subscribers {
|
||||
running.insert(tracer.id.clone(), tracer.settings);
|
||||
tracer.typ.spawn(
|
||||
SubscriberBuilder::new(tracer.id)
|
||||
.with_interests(tracer.interests)
|
||||
@@ -37,25 +48,39 @@ impl Telemetry {
|
||||
Collector::reload();
|
||||
}
|
||||
|
||||
// inbuxa: upstream only refreshed the events, level and lossiness of a
|
||||
// tracer that was already running, so a Log tracer moved to another
|
||||
// path (or any tracer whose own settings changed) kept going as it was
|
||||
// built until a restart, while the reload reported the change applied.
|
||||
// A tracer whose settings changed is now started over: the new one is
|
||||
// registered under the same id and the collector swaps it in at an
|
||||
// event boundary, so no event is lost or written twice (see
|
||||
// Update::RegisterSubscriber); the old one writes what it has queued
|
||||
// and stops.
|
||||
pub fn update(self) {
|
||||
let mut running = RUNNING_TRACERS.lock();
|
||||
let running = running.get_or_insert_with(AHashMap::new);
|
||||
|
||||
// Remove tracers that are no longer active
|
||||
let active_subscribers = Collector::get_subscribers();
|
||||
for subscribed_id in &active_subscribers {
|
||||
if !self
|
||||
running.retain(|id, _| {
|
||||
let keep = self
|
||||
.tracers
|
||||
.subscribers
|
||||
.iter()
|
||||
.any(|tracer| tracer.id == *subscribed_id)
|
||||
{
|
||||
Collector::remove_subscriber(subscribed_id.clone());
|
||||
.any(|tracer| tracer.id == *id);
|
||||
if !keep {
|
||||
Collector::remove_subscriber(id.clone());
|
||||
}
|
||||
}
|
||||
keep
|
||||
});
|
||||
|
||||
// Activate new tracers or update existing ones
|
||||
// Start new tracers, start over those whose settings changed and
|
||||
// update the rest in place
|
||||
for tracer in self.tracers.subscribers {
|
||||
if active_subscribers.contains(&tracer.id) {
|
||||
if running.get(&tracer.id) == Some(&tracer.settings) {
|
||||
Collector::update_subscriber(tracer.id, tracer.interests, tracer.lossy);
|
||||
} else {
|
||||
running.insert(tracer.id.clone(), tracer.settings);
|
||||
tracer.typ.spawn(
|
||||
SubscriberBuilder::new(tracer.id)
|
||||
.with_interests(tracer.interests)
|
||||
|
||||
Reference in New Issue
Block a user