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:
@@ -31,6 +31,10 @@ pub struct TelemetrySubscriber {
|
||||
pub interests: Interests,
|
||||
pub typ: TelemetrySubscriberType,
|
||||
pub lossy: bool,
|
||||
/// inbuxa: a hash of the settings the running tracer is built from
|
||||
/// (everything but its events, level and lossiness, which change in
|
||||
/// place), so a reload can tell which tracers to start over.
|
||||
pub settings: u64,
|
||||
}
|
||||
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
@@ -167,6 +171,7 @@ impl Tracers {
|
||||
for tracer in bp.list_infallible::<Tracer>().await {
|
||||
let id = tracer.id;
|
||||
let tracer = tracer.object;
|
||||
let settings = tracer_settings(&tracer);
|
||||
let level;
|
||||
let lossy;
|
||||
let events;
|
||||
@@ -379,6 +384,7 @@ impl Tracers {
|
||||
interests: Default::default(),
|
||||
lossy,
|
||||
typ,
|
||||
settings,
|
||||
};
|
||||
|
||||
// Parse disabled events
|
||||
@@ -426,6 +432,7 @@ impl Tracers {
|
||||
for hook in bp.list_infallible::<WebHook>().await {
|
||||
let id = hook.id;
|
||||
let hook = hook.object;
|
||||
let settings = webhook_settings(&hook);
|
||||
|
||||
if !hook.enable {
|
||||
continue;
|
||||
@@ -448,6 +455,7 @@ impl Tracers {
|
||||
id: format!("w_{}", id.id()),
|
||||
interests: Default::default(),
|
||||
lossy: hook.lossy,
|
||||
settings,
|
||||
typ: TelemetrySubscriberType::Webhook(WebhookTracer {
|
||||
url: hook.url,
|
||||
timeout: hook.timeout.into_inner(),
|
||||
@@ -516,6 +524,8 @@ impl Tracers {
|
||||
data: storage.data.clone(),
|
||||
}),
|
||||
lossy: true,
|
||||
// Stores take a restart
|
||||
settings: 0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -541,6 +551,7 @@ impl Tracers {
|
||||
buffered: true,
|
||||
}),
|
||||
lossy: false,
|
||||
settings: 0,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
@@ -568,6 +579,7 @@ impl Tracers {
|
||||
buffered: true,
|
||||
}),
|
||||
lossy: false,
|
||||
settings: 0,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -701,6 +713,42 @@ impl Metrics {
|
||||
}
|
||||
}
|
||||
|
||||
// inbuxa: what a tracer is built from, less what changes in place
|
||||
macro_rules! in_place_reset {
|
||||
($tracer:expr) => {{
|
||||
$tracer.enable = true;
|
||||
$tracer.level = Default::default();
|
||||
$tracer.lossy = false;
|
||||
$tracer.events = Default::default();
|
||||
$tracer.events_policy = Default::default();
|
||||
}};
|
||||
}
|
||||
|
||||
fn settings_hash(settings: &impl std::fmt::Debug) -> u64 {
|
||||
use std::hash::{Hash, Hasher};
|
||||
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||
format!("{settings:?}").hash(&mut hasher);
|
||||
hasher.finish()
|
||||
}
|
||||
|
||||
fn tracer_settings(tracer: &Tracer) -> u64 {
|
||||
let mut tracer = tracer.clone();
|
||||
match &mut tracer {
|
||||
Tracer::Log(tracer) => in_place_reset!(tracer),
|
||||
Tracer::Stdout(tracer) => in_place_reset!(tracer),
|
||||
Tracer::Journal(tracer) => in_place_reset!(tracer),
|
||||
Tracer::OtelHttp(tracer) => in_place_reset!(tracer),
|
||||
Tracer::OtelGrpc(tracer) => in_place_reset!(tracer),
|
||||
}
|
||||
settings_hash(&tracer)
|
||||
}
|
||||
|
||||
fn webhook_settings(hook: &WebHook) -> u64 {
|
||||
let mut hook = hook.clone();
|
||||
in_place_reset!(hook);
|
||||
settings_hash(&hook)
|
||||
}
|
||||
|
||||
fn apply_events(
|
||||
event_types: impl IntoIterator<Item = EventType>,
|
||||
policy: EventPolicy,
|
||||
|
||||
Reference in New Issue
Block a user