fix: for enrichment tables values api should use the ingested timerange (#4554)

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

- **New Features**
- Enhanced time value determination for enrichment tables by sourcing
from statistics instead of user input.
- Expanded the `AddSettingVariable` component to support an additional
stream type: "enrichment_tables."
- **Bug Fixes**
- Improved control flow to ensure correct application behavior based on
stream type.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: ktx-abhay <abhay.padamani@kiara.tech>
This commit is contained in:
Subhra264
2024-09-16 14:09:08 +05:30
committed by GitHub
co-authored by ktx-abhay
parent 97f8b674ea
commit b972ff00f4
2 changed files with 54 additions and 14 deletions
+53 -13
View File
@@ -29,7 +29,7 @@ use config::{
utils::{base64, json},
DISTINCT_FIELDS,
};
use infra::errors;
use infra::{cache::stats, errors};
use tracing::{Instrument, Span};
use crate::{
@@ -810,18 +810,38 @@ async fn values_v1(
let size = query
.get("size")
.map_or(10, |v| v.parse::<i64>().unwrap_or(10));
let start_time = query
.get("start_time")
.map_or(0, |v| v.parse::<i64>().unwrap_or(0));
// If this is a enrichment table, we need to get the start_time and end_time from the stats
let stats = if stream_type.eq(&StreamType::EnrichmentTables) {
Some(stats::get_stream_stats(org_id, stream_name, stream_type))
} else {
None
};
let start_time = if stream_type.eq(&StreamType::EnrichmentTables) {
stats.as_ref().unwrap().doc_time_min
} else {
query
.get("start_time")
.map_or(0, |v| v.parse::<i64>().unwrap_or(0))
};
if start_time == 0 {
return Ok(MetaHttpResponse::bad_request("start_time is empty"));
}
let end_time = query
.get("end_time")
.map_or(0, |v| v.parse::<i64>().unwrap_or(0));
let end_time = if stream_type.eq(&StreamType::EnrichmentTables) {
stats.as_ref().unwrap().doc_time_max
} else {
query
.get("end_time")
.map_or(0, |v| v.parse::<i64>().unwrap_or(0))
};
if end_time == 0 {
return Ok(MetaHttpResponse::bad_request("end_time is empty"));
}
let (start_time, end_time) = if start_time == end_time {
(start_time - 1, end_time + 1)
} else {
(start_time, end_time)
};
let regions = query.get("regions").map_or(vec![], |regions| {
regions
@@ -1074,18 +1094,38 @@ async fn values_v2(
let size = query
.get("size")
.map_or(10, |v| v.parse::<i64>().unwrap_or(10));
let start_time = query
.get("start_time")
.map_or(0, |v| v.parse::<i64>().unwrap_or(0));
// If this is a enrichment table, we need to get the start_time and end_time from the stats
let stats = if stream_type.eq(&StreamType::EnrichmentTables) {
Some(stats::get_stream_stats(org_id, stream_name, stream_type))
} else {
None
};
let start_time = if stream_type.eq(&StreamType::EnrichmentTables) {
stats.as_ref().unwrap().doc_time_min
} else {
query
.get("start_time")
.map_or(0, |v| v.parse::<i64>().unwrap_or(0))
};
if start_time == 0 {
return Ok(MetaHttpResponse::bad_request("start_time is empty"));
}
let end_time = query
.get("end_time")
.map_or(0, |v| v.parse::<i64>().unwrap_or(0));
let end_time = if stream_type.eq(&StreamType::EnrichmentTables) {
stats.as_ref().unwrap().doc_time_max
} else {
query
.get("end_time")
.map_or(0, |v| v.parse::<i64>().unwrap_or(0))
};
if end_time == 0 {
return Ok(MetaHttpResponse::bad_request("end_time is empty"));
}
let (start_time, end_time) = if start_time == end_time {
(start_time - 1, end_time + 1)
} else {
(start_time, end_time)
};
if no_count {
query_sql = format!("{query_sql} GROUP BY zo_sql_key ORDER BY zo_sql_key ASC LIMIT {size}")
} else {
@@ -614,7 +614,7 @@ export default defineComponent({
const addVariableForm: Ref<any> = ref(null);
const data: any = reactive({
schemaResponse: [],
streamType: ["logs", "metrics", "traces"],
streamType: ["logs", "metrics", "traces", "enrichment_tables"],
streams: [],
currentFieldsList: [],