mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-05-15 16:53:57 +02:00
fix the stats and stop sending events when no request happened
This commit is contained in:
parent
40eabd50d1
commit
5395041dcb
@ -143,19 +143,32 @@ mod segment {
|
|||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
}
|
}
|
||||||
let get_search = std::mem::take(&mut *self.get_search_batcher.lock().await)
|
println!("ANALYTICS: taking the lock on the search batcher");
|
||||||
.into_event(self.user.clone(), "Documents Searched GET".to_string());
|
let get_search = std::mem::take(&mut *self.get_search_batcher.lock().await);
|
||||||
let post_search = std::mem::take(&mut *self.post_search_batcher.lock().await)
|
let get_search = (get_search.total_received != 0).then(|| {
|
||||||
.into_event(self.user.clone(), "Documents Searched POST".to_string());
|
get_search
|
||||||
|
.into_event(self.user.clone(), "Document Searched GET".to_string())
|
||||||
|
});
|
||||||
|
let post_search = std::mem::take(&mut *self.post_search_batcher.lock().await);
|
||||||
|
let post_search = (post_search.total_received != 0).then(|| {
|
||||||
|
post_search
|
||||||
|
.into_event(self.user.clone(), "Document Searched POST".to_string())
|
||||||
|
});
|
||||||
// keep the lock on the batcher just for these three operations
|
// keep the lock on the batcher just for these three operations
|
||||||
{
|
{
|
||||||
|
println!("ANALYTICS: taking the lock on the batcher");
|
||||||
let mut batcher = self.batcher.lock().await;
|
let mut batcher = self.batcher.lock().await;
|
||||||
let _ = batcher.push(get_search).await;
|
if let Some(get_search) = get_search {
|
||||||
let _ = batcher.push(post_search).await;
|
let _ = batcher.push(get_search).await;
|
||||||
let _ = self.batcher.lock().await.flush().await;
|
}
|
||||||
|
if let Some(post_search) = post_search {
|
||||||
|
let _ = batcher.push(post_search).await;
|
||||||
|
}
|
||||||
|
println!("ANALYTICS: Sending the batch");
|
||||||
|
let _ = batcher.flush().await;
|
||||||
}
|
}
|
||||||
println!("ANALYTICS: sent the batch");
|
println!("ANALYTICS: sent the batch");
|
||||||
tokio::time::sleep(Duration::from_secs(60 * 5)).await; // 5 minutes
|
tokio::time::sleep(Duration::from_secs(60 * 2)).await; // 2 minutes
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -291,7 +304,7 @@ mod segment {
|
|||||||
|
|
||||||
fn end_post_search(&'static self, process_time: usize) {
|
fn end_post_search(&'static self, process_time: usize) {
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let mut search_batcher = self.get_search_batcher.lock().await;
|
let mut search_batcher = self.post_search_batcher.lock().await;
|
||||||
search_batcher.total_succeeded += 1;
|
search_batcher.total_succeeded += 1;
|
||||||
search_batcher.time_spent.push(process_time);
|
search_batcher.time_spent.push(process_time);
|
||||||
});
|
});
|
||||||
@ -361,22 +374,22 @@ mod segment {
|
|||||||
|
|
||||||
let properties = json!({
|
let properties = json!({
|
||||||
"requests": {
|
"requests": {
|
||||||
"99th_response_time": self.time_spent.len() as f64 / self.time_spent.iter().sum::<usize>() as f64,
|
"99th_response_time": format!("{:.2}", self.time_spent.iter().sum::<usize>() as f64 / self.time_spent.len() as f64),
|
||||||
"total_succeeded": self.total_succeeded,
|
"total_succeeded": self.total_succeeded,
|
||||||
"total_failed": self.total_received.saturating_sub(self.total_succeeded), // just to be sure we never panics
|
"total_failed": self.total_received.saturating_sub(self.total_succeeded), // just to be sure we never panics
|
||||||
"total_received": self.total_received,
|
"total_received": self.total_received,
|
||||||
},
|
},
|
||||||
"sort": {
|
"sort": {
|
||||||
"with_geoPoint": self.sort_with_geo_point,
|
"with_geoPoint": self.sort_with_geo_point,
|
||||||
"avg_criteria_number": self.sort_total_number_of_criteria as f64 / self.sort_sum_of_criteria_terms as f64,
|
"avg_criteria_number": format!("{:.2}", self.sort_sum_of_criteria_terms as f64 / self.sort_total_number_of_criteria as f64),
|
||||||
},
|
},
|
||||||
"filter": {
|
"filter": {
|
||||||
"with_geoRadius": self.filter_with_geo_radius,
|
"with_geoRadius": self.filter_with_geo_radius,
|
||||||
"avg_criteria_number": self.filter_total_number_of_criteria as f64 / self.filter_sum_of_criteria_terms as f64,
|
"avg_criteria_number": format!("{:.2}", self.filter_sum_of_criteria_terms as f64 / self.filter_total_number_of_criteria as f64),
|
||||||
"most_used_syntax": self.used_syntax.iter().max_by_key(|(_, v)| *v).map(|(k, _)| json!(k)).unwrap_or_else(|| json!(null)),
|
"most_used_syntax": self.used_syntax.iter().max_by_key(|(_, v)| *v).map(|(k, _)| json!(k)).unwrap_or_else(|| json!(null)),
|
||||||
},
|
},
|
||||||
"q": {
|
"q": {
|
||||||
"avg_terms_number": self.total_number_of_q as f64 / self.sum_of_terms_count as f64,
|
"avg_terms_number": format!("{:.2}", self.sum_of_terms_count as f64 / self.total_number_of_q as f64),
|
||||||
},
|
},
|
||||||
"pagination": {
|
"pagination": {
|
||||||
"max_limit": self.max_limit,
|
"max_limit": self.max_limit,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user