mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
Instrument the loaded plugin cache (#41231)
## What changed - Count loaded-plugin cache requests by `hit`, `hit_after_wait`, or `load` outcome. - Record time spent waiting for the load semaphore and loading plugins. - Count cache clears and capacity evictions. - Remove the unused force-reload path from `PluginsManager::plugins_for_config`. GitOrigin-RevId: db7829e7bd9b1414a263d9a7100c05dfdd832777
This commit is contained in:
committed by
copyberry
parent
e9a6d731b7
commit
91c66024c7
@@ -0,0 +1,49 @@
|
||||
//! Request counts exclude disabled plugins, account-switch discards, and cancellations.
|
||||
//! Auth retries keep the furthest request outcome reached; each completed wait/load is timed.
|
||||
//! Skill-snapshot lookups are not requests. Clear events include already-empty caches.
|
||||
//! Tags never contain configuration data.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
pub(crate) const LOAD_DURATION: &str = "codex.plugins.loaded_cache.load.duration_ms";
|
||||
pub(crate) const WAIT_DURATION: &str = "codex.plugins.loaded_cache.wait.duration_ms";
|
||||
|
||||
pub(crate) enum RequestOutcome {
|
||||
Hit,
|
||||
HitAfterWait,
|
||||
Load,
|
||||
}
|
||||
|
||||
impl RequestOutcome {
|
||||
pub(crate) fn record(self) {
|
||||
let Some(metrics) = codex_otel::global() else {
|
||||
return;
|
||||
};
|
||||
let outcome = match self {
|
||||
Self::Hit => "hit",
|
||||
Self::HitAfterWait => "hit_after_wait",
|
||||
Self::Load => "load",
|
||||
};
|
||||
let _ = metrics.counter(
|
||||
"codex.plugins.loaded_cache.request",
|
||||
/*inc*/ 1,
|
||||
&[("outcome", outcome)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn record_duration(name: &'static str, duration: Duration) {
|
||||
if let Some(metrics) = codex_otel::global() {
|
||||
let _ = metrics.record_duration(name, duration, &[]);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn record_event(event: &'static str) {
|
||||
if let Some(metrics) = codex_otel::global() {
|
||||
let _ = metrics.counter(
|
||||
"codex.plugins.loaded_cache.event",
|
||||
/*inc*/ 1,
|
||||
&[("event", event)],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user