Move embedder stats out of progress

This commit is contained in:
Mubelotix 2025-06-23 15:24:14 +02:00
parent 4cadc8113b
commit 4925b30196
No known key found for this signature in database
GPG key ID: 89F391DBCC8CE7F0
30 changed files with 255 additions and 69 deletions

View file

@ -20,7 +20,6 @@ pub trait Step: 'static + Send + Sync {
#[derive(Clone, Default)]
pub struct Progress {
steps: Arc<RwLock<InnerProgress>>,
pub embedder_stats: Arc<EmbedderStats>,
}
#[derive(Default)]
@ -29,6 +28,17 @@ pub struct EmbedderStats {
pub total_requests: AtomicUsize
}
impl std::fmt::Debug for EmbedderStats {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let (error, count) = self.errors.read().unwrap().clone();
f.debug_struct("EmbedderStats")
.field("errors", &error)
.field("total_requests", &self.total_requests.load(Ordering::Relaxed))
.field("error_count", &count)
.finish()
}
}
#[derive(Default)]
struct InnerProgress {
/// The hierarchy of steps.
@ -72,19 +82,7 @@ impl Progress {
});
}
let embedder_view = {
let (last_error, error_count) = match self.embedder_stats.errors.read() {
Ok(guard) => (guard.0.clone(), guard.1),
Err(_) => (None, 0),
};
EmbedderStatsView {
last_error,
request_count: self.embedder_stats.total_requests.load(Ordering::Relaxed) as u32,
error_count,
}
};
ProgressView { steps: step_view, percentage: percentage * 100.0, embedder: embedder_view }
ProgressView { steps: step_view, percentage: percentage * 100.0 }
}
pub fn accumulated_durations(&self) -> IndexMap<String, String> {
@ -228,7 +226,6 @@ make_enum_progress! {
pub struct ProgressView {
pub steps: Vec<ProgressStepView>,
pub percentage: f32,
pub embedder: EmbedderStatsView,
}
#[derive(Debug, Serialize, Clone, ToSchema)]
@ -240,16 +237,6 @@ pub struct ProgressStepView {
pub total: u32,
}
#[derive(Debug, Serialize, Clone, ToSchema)]
#[serde(rename_all = "camelCase")]
#[schema(rename_all = "camelCase")]
pub struct EmbedderStatsView {
#[serde(skip_serializing_if = "Option::is_none")]
pub last_error: Option<String>,
pub request_count: u32,
pub error_count: u32,
}
/// Used when the name can change but it's still the same step.
/// To avoid conflicts on the `TypeId`, create a unique type every time you use this step:
/// ```text