Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ lto = false
needless_return = "allow"
type_complexity = "allow"
uninlined_format_args = "allow"
too_many_arguments = "allow"

[lints.rust]
elided_lifetimes_in_paths = "deny"
14 changes: 14 additions & 0 deletions src/interpreter/clickhouse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,8 @@ impl ClickHouse {
&self,
query_ids: &Option<Vec<String>>,
logger_names: &Option<Vec<String>>,
message_filter: &Option<String>,
max_level: &Option<String>,
start_microseconds: DateTime<Local>,
end: RelativeDateTime,
) -> Result<Columns> {
Expand Down Expand Up @@ -822,6 +824,8 @@ impl ClickHouse {
AND event_date <= toDate(end_time_) AND event_time <= toDateTime(end_time_) AND event_time_microseconds <= end_time_
{}
{}
{}
{}
// TODO: if query finished, add filter for event_time end range
ORDER BY event_date, event_time, event_time_microseconds
LIMIT {}
Expand All @@ -841,6 +845,16 @@ impl ClickHouse {
} else {
"".into()
},
if let Some(message_filter) = message_filter {
format!("AND message LIKE '%{}%'", message_filter)
} else {
"".into()
},
if let Some(max_level) = max_level {
format!("AND level <= '{}'", max_level)
} else {
"".into()
},
self.options.limit,
)
.as_str(),
Expand Down
23 changes: 20 additions & 3 deletions src/interpreter/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ pub enum Event {
UpdateSlowQueryLog(String, RelativeDateTime, RelativeDateTime, u64),
// [filter, start, end, limit]
UpdateLastQueryLog(String, RelativeDateTime, RelativeDateTime, u64),
// (view_name, [query_ids], [logger_names], start, end)
// (view_name, [query_ids], [logger_names], [message_filter], [max_level], start, end)
GetTextLog(
&'static str,
Option<Vec<String>>,
Option<Vec<String>>,
Option<String>,
Option<String>,
DateTime<Local>,
RelativeDateTime,
),
Expand Down Expand Up @@ -346,9 +348,24 @@ async fn process_event(context: ContextArc, event: Event, need_clear: &mut bool)
}))
.map_err(|_| anyhow!("Cannot send message to UI"))?;
}
Event::GetTextLog(view_name, query_ids, logger_names, start_microseconds, end) => {
Event::GetTextLog(
view_name,
query_ids,
logger_names,
message_filter,
max_level,
start_microseconds,
end,
) => {
let block = clickhouse
.get_query_logs(&query_ids, &logger_names, start_microseconds, end)
.get_query_logs(
&query_ids,
&logger_names,
&message_filter,
&max_level,
start_microseconds,
end,
)
.await?;
cb_sink
.send(Box::new(move |siv: &mut cursive::Cursive| {
Expand Down
66 changes: 57 additions & 9 deletions src/view/navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
view::{self, TextLogView},
};
use anyhow::Result;
use chrono::{DateTime, Local};
use chrono::{DateTime, Duration, Local};
use crossterm::{
execute,
terminal::{disable_raw_mode, enable_raw_mode},
Expand Down Expand Up @@ -158,6 +158,8 @@ fn query_result_show_logs_for_row(
view_options.end,
None,
Some(logger_names),
None,
None,
),
)),
));
Expand Down Expand Up @@ -976,6 +978,8 @@ impl Navigation for Cursive {
map["part"].to_string()
)]),
None,
None,
None,
),
)),
));
Expand Down Expand Up @@ -1236,8 +1240,51 @@ impl Navigation for Cursive {
"arrayStringConcat(arrayMap(addr -> concat(addressToLine(addr), '::', demangle(addressToSymbol(addr))), last_error_trace), '\n') _error_trace",
];

// TODO: on submit show logs from system.query_log/system.text_log, but we need to
// implement wrapping before
let errors_logs_callback =
|siv: &mut Cursive, columns: Vec<&'static str>, row: view::QueryResultRow| {
let row_data = row.0;

let mut map = HashMap::<String, String>::new();
columns.iter().zip(row_data.iter()).for_each(|(c, r)| {
map.insert(c.to_string(), r.to_string());
});

let error_time = map
.get("error_time")
.and_then(|t| t.parse::<DateTime<Local>>().ok())
.unwrap_or_else(Local::now);
let error_name = map.get("name").map(|s| s.to_string()).unwrap_or_default();

let context = siv.user_data::<ContextArc>().unwrap().clone();

// Show logs for 1 minute before and after the error time
// (Note, we need to add at least 1 second to error_time, otherwise it will be
// filtered out by event_time_microseconds condition)
let offset = Duration::try_minutes(1).unwrap_or_default();
let end_time = error_time + offset;
let start_time = error_time - offset;

siv.add_layer(Dialog::around(
LinearLayout::vertical()
.child(TextView::new(format!("Logs for error: {}", error_name)).center())
.child(DummyView.fixed_height(1))
.child(NamedView::new(
"error_logs",
TextLogView::new(
"error_logs",
context,
start_time,
RelativeDateTime::from(end_time),
None,
None,
Some(error_name),
Some("Warning".to_string()),
),
)),
));
siv.focus_name("error_logs").unwrap();
};

self.show_query_result_view(
context,
"errors",
Expand All @@ -1246,12 +1293,7 @@ impl Navigation for Cursive {
"value",
&mut columns,
1,
Some(
|siv: &mut Cursive, _columns: Vec<&'static str>, row: view::QueryResultRow| {
let trace = row.0.iter().last().unwrap();
siv.add_layer(Dialog::info(trace.to_string()).title("Error trace"));
},
),
Some(errors_logs_callback),
&HashMap::from([("allow_introspection_functions", "1")]),
);
}
Expand Down Expand Up @@ -1288,6 +1330,8 @@ impl Navigation for Cursive {
RelativeDateTime::from(map["end_time"].as_datetime()),
Some(vec![map["_query_id"].to_string()]),
None,
None,
None,
),
)),
));
Expand Down Expand Up @@ -1380,6 +1424,8 @@ impl Navigation for Cursive {
view_options.end,
None,
None,
None,
None,
)
.with_name("server_logs")
.full_screen(),
Expand Down Expand Up @@ -1442,6 +1488,8 @@ impl Navigation for Cursive {
view_options.end,
None,
Some(vec![logger_name]),
None,
None,
),
)),
));
Expand Down
2 changes: 2 additions & 0 deletions src/view/processes_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,6 +1065,8 @@ impl ProcessesView {
RelativeDateTime::from(max_query_end_microseconds),
Some(query_ids),
None,
None,
None,
),
)),
));
Expand Down
8 changes: 8 additions & 0 deletions src/view/text_log_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ impl TextLogView {
end: RelativeDateTime,
query_ids: Option<Vec<String>>,
logger_names: Option<Vec<String>>,
message_filter: Option<String>,
max_level: Option<String>,
) -> Self {
let flush_interval_milliseconds =
Duration::try_milliseconds(FLUSH_INTERVAL_MILLISECONDS).unwrap();
Expand Down Expand Up @@ -60,13 +62,17 @@ impl TextLogView {
view_name,
query_ids.clone(),
None,
message_filter.clone(),
max_level.clone(),
start,
RelativeDateTime::from(end),
),
);
} else {
let update_query_ids = query_ids.clone();
let update_logger_names = logger_names.clone();
let update_message_filter = message_filter.clone();
let update_max_level = max_level.clone();
let update_last_event_time_microseconds = last_event_time_microseconds.clone();
let update_callback_context = context.clone();
let update_callback = move |force: bool| {
Expand All @@ -76,6 +82,8 @@ impl TextLogView {
view_name,
update_query_ids.clone(),
update_logger_names.clone(),
update_message_filter.clone(),
update_max_level.clone(),
*update_last_event_time_microseconds.lock().unwrap(),
end.clone(),
),
Expand Down
Loading