mirror of
https://github.com/openobserve/openobserve.git
synced 2026-11-05 16:10:43 +00:00
fix: dashboard path & histogram (#344)
* fix: dashboard path * feat: auto caculate interval for histogram * feat: support fix number of histogram
This commit is contained in:
@@ -22,12 +22,15 @@ use rust_embed_for_web::RustEmbed;
|
||||
#[folder = "web/dist/"]
|
||||
struct WebAssets;
|
||||
|
||||
pub const UI_PAGES: [&str; 13] = [
|
||||
pub const UI_PAGES: [&str; 16] = [
|
||||
"login",
|
||||
"logout",
|
||||
"about",
|
||||
"users",
|
||||
"logs",
|
||||
"dashboards",
|
||||
"viewDashboard",
|
||||
"addPanel",
|
||||
"logstreams",
|
||||
"functions",
|
||||
"alerts",
|
||||
|
||||
+3
-1
@@ -37,7 +37,9 @@ pub async fn run() -> Result<(), anyhow::Error> {
|
||||
for item in leaders.iter() {
|
||||
let result = db::set_prom_cluster_leader(item.key(), item.value()).await;
|
||||
match result {
|
||||
Ok(_) => log::info!("Successfully updated leader to db "),
|
||||
Ok(_) => {
|
||||
// log::info!("Successfully updated leader to db ")
|
||||
}
|
||||
Err(err) => log::error!("error updating leader to db {}", err),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ impl Sql {
|
||||
#[tracing::instrument(name = "service:search:sql:new", skip(req))]
|
||||
pub async fn new(req: &cluster_rpc::SearchRequest) -> Result<Sql, Error> {
|
||||
let req_query = req.query.as_ref().unwrap();
|
||||
let req_time_range = (req_query.start_time, req_query.end_time);
|
||||
let mut req_time_range = (req_query.start_time, req_query.end_time);
|
||||
let org_id = req.org_id.clone();
|
||||
let stream_type: StreamType = StreamType::from(req.stream_type.as_str());
|
||||
|
||||
@@ -217,7 +217,10 @@ impl Sql {
|
||||
let meta_time_range_is_empty =
|
||||
meta.time_range.is_none() || meta.time_range.unwrap() == (0, 0);
|
||||
if meta_time_range_is_empty && (req_time_range.0 > 0 || req_time_range.1 > 0) {
|
||||
meta.time_range = Some(req_time_range)
|
||||
if req_time_range.1 == 0 {
|
||||
req_time_range.1 = chrono::Utc::now().timestamp_micros();
|
||||
}
|
||||
meta.time_range = Some(req_time_range); // update meta
|
||||
};
|
||||
if let Some(time_range) = meta.time_range {
|
||||
let time_range_sql = if time_range.0 > 0 && time_range.1 > 0 {
|
||||
@@ -403,7 +406,13 @@ impl Sql {
|
||||
.map(|v| v.trim().trim_matches(|v| v == '\'' || v == '"'))
|
||||
.collect::<Vec<&str>>();
|
||||
let field = attrs.first().unwrap();
|
||||
let interval = attrs.get(1).unwrap();
|
||||
let interval = match attrs.get(1) {
|
||||
Some(v) => match v.parse::<u16>() {
|
||||
Ok(v) => generate_histogram_interval(meta.time_range, v),
|
||||
Err(_) => v.to_string(),
|
||||
},
|
||||
None => generate_histogram_interval(meta.time_range, 0),
|
||||
};
|
||||
origin_sql = origin_sql.replace(
|
||||
cap.get(0).unwrap().as_str(),
|
||||
format!(
|
||||
@@ -616,6 +625,58 @@ fn check_field_in_use(sql: &Sql, field: &str) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn generate_histogram_interval(time_range: Option<(i64, i64)>, num: u16) -> String {
|
||||
if time_range.is_none() || time_range.unwrap().eq(&(0, 0)) {
|
||||
return "1 hour".to_string();
|
||||
}
|
||||
let time_range = time_range.unwrap();
|
||||
if num > 0 {
|
||||
return format!(
|
||||
"{} second",
|
||||
std::cmp::max(
|
||||
(time_range.1 - time_range.0)
|
||||
/ Duration::seconds(1).num_microseconds().unwrap()
|
||||
/ num as i64,
|
||||
1
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
let intervals = [
|
||||
(
|
||||
Duration::hours(24 * 30).num_microseconds().unwrap(),
|
||||
"1 day",
|
||||
),
|
||||
(
|
||||
Duration::hours(24 * 7).num_microseconds().unwrap(),
|
||||
"1 hour",
|
||||
),
|
||||
(Duration::hours(24).num_microseconds().unwrap(), "30 minute"),
|
||||
(Duration::hours(6).num_microseconds().unwrap(), "5 minute"),
|
||||
(Duration::hours(2).num_microseconds().unwrap(), "1 minute"),
|
||||
(Duration::hours(1).num_microseconds().unwrap(), "30 second"),
|
||||
(
|
||||
Duration::minutes(30).num_microseconds().unwrap(),
|
||||
"15 second",
|
||||
),
|
||||
(
|
||||
Duration::minutes(20).num_microseconds().unwrap(),
|
||||
"10 second",
|
||||
),
|
||||
(
|
||||
Duration::minutes(10).num_microseconds().unwrap(),
|
||||
"5 second",
|
||||
),
|
||||
(Duration::minutes(5).num_microseconds().unwrap(), "2 second"),
|
||||
];
|
||||
for interval in intervals.iter() {
|
||||
if (time_range.1 - time_range.0) >= interval.0 {
|
||||
return interval.1.to_string();
|
||||
}
|
||||
}
|
||||
"1 second".to_string()
|
||||
}
|
||||
|
||||
fn split_sql_token(text: &str) -> Vec<String> {
|
||||
let mut tokens = Vec::new();
|
||||
let text_chars = text.chars().collect::<Vec<char>>();
|
||||
|
||||
@@ -336,6 +336,7 @@ export default defineComponent({
|
||||
}
|
||||
.search-time {
|
||||
// width: 120px;
|
||||
margin-right: 10px;
|
||||
.q-btn-group {
|
||||
border-radius: 3px;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user