fix: histogram interval (#4417)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **New Features**
- Introduced a `histogram_interval` field to enhance query response
capabilities, allowing for more detailed data representation.
- Enhanced caching logic to set the `histogram_interval` based on the
`discard_interval`, improving the handling of cached query responses.

- **Improvements**
- Added conditional logic in response handling to include
`histogram_interval` when specific criteria are met, improving response
accuracy and robustness.
- Refined checks for empty responses, enhancing the robustness of the
merging process for query responses.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Ashish Kolhe
2024-09-01 12:54:38 +05:30
committed by GitHub
parent df0647709f
commit b0d0302428
3 changed files with 15 additions and 3 deletions
+1
View File
@@ -58,6 +58,7 @@ pub struct MultiCachedQueryResponse {
pub is_descending: bool,
pub limit: i64,
pub took: usize,
pub histogram_interval: i64,
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]
+3
View File
@@ -143,6 +143,9 @@ pub async fn check_cache(
return MultiCachedQueryResponse::default();
}
let mut multi_resp = MultiCachedQueryResponse::default();
if discard_interval > -1 {
multi_resp.histogram_interval = discard_interval / 1000 / 1000;
}
if get_config().common.use_multi_result_cache {
let mut multi_res = crate::service::search::cluster::cache_multi::get_cached_results(
query_key.to_owned(),
+11 -3
View File
@@ -256,6 +256,9 @@ pub async fn search(
res.set_trace_id(trace_id.to_string());
res.set_local_took(start.elapsed().as_millis() as usize, ext_took_wait);
if is_aggregate && c_resp.histogram_interval > -1 {
res.histogram_interval = Some(c_resp.histogram_interval);
}
let req_stats = RequestStats {
records: res.hits.len() as i64,
response_time: time,
@@ -353,14 +356,19 @@ fn merge_response(
};
if cache_response.hits.is_empty()
&& search_response.is_empty()
&& search_response.first().unwrap().hits.is_empty()
&& search_response.last().unwrap().hits.is_empty()
&& !search_response.is_empty()
&& search_response
.first()
.map_or(true, |res| res.hits.is_empty())
&& search_response
.last()
.map_or(true, |res| res.hits.is_empty())
{
for res in search_response {
cache_response.total += res.total;
cache_response.scan_size += res.scan_size;
cache_response.took += res.took;
cache_response.histogram_interval = res.histogram_interval;
}
return cache_response;
}