Skip to content

Commit 82a39a1

Browse files
authored
Merge pull request #7 from c-git/develop
0.3.4
2 parents 1c15568 + 7c366a5 commit 82a39a1

11 files changed

+510
-331
lines changed

Cargo.lock

Lines changed: 202 additions & 309 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "log_viewer"
3-
version = "0.3.3"
3+
version = "0.3.4"
44
edition = "2021"
55

66
[dependencies]

src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use anyhow::{bail, Context};
44
use data::filter::{Comparator, FieldSpecifier, FilterConfig, FilterOn};
55
use egui::{
66
text::{CCursor, CCursorRange},
7-
Align, KeyboardShortcut,
7+
Align, KeyboardShortcut, Label,
88
};
99
use egui_extras::{Column, TableBuilder};
1010
use shortcut::Shortcuts;
@@ -200,7 +200,7 @@ impl LogViewerApp {
200200
.unwrap_or(&default_text_color);
201201
ui.colored_label(*color, display_value);
202202
} else {
203-
ui.label(display_value);
203+
ui.add(Label::new(display_value).truncate());
204204
}
205205
}
206206
});

src/app/data.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
use std::{
2-
borrow::Cow,
3-
collections::{BTreeMap, BTreeSet},
1+
use super::{
2+
calculate_hash,
3+
data_display_options::{DataDisplayOptions, LevelConversion, RowParseErrorHandling},
44
};
5-
65
use anyhow::Context;
76
use data_iter::DataIter;
87
use filter::{FieldSpecifier, FilterConfig};
98
use serde_json::Value;
9+
use std::{
10+
borrow::Cow,
11+
collections::{BTreeMap, BTreeSet},
12+
};
1013
use tracing::warn;
1114

12-
use super::{
13-
calculate_hash,
14-
data_display_options::{DataDisplayOptions, LevelConversion, RowParseErrorHandling},
15-
};
1615
mod data_iter;
1716
pub mod filter;
1817

@@ -367,6 +366,7 @@ impl TryFrom<(&DataDisplayOptions, usize, &str)> for LogRow {
367366
fn try_from(
368367
(data_display_options, row_idx_val, value): (&DataDisplayOptions, usize, &str),
369368
) -> Result<Self, Self::Error> {
369+
let row_size_in_bytes = value.len();
370370
let data = match serde_json::from_str::<BTreeMap<String, Value>>(value) {
371371
Ok(data) => data,
372372
Err(e) => match &data_display_options.row_parse_error_handling {
@@ -398,6 +398,12 @@ impl TryFrom<(&DataDisplayOptions, usize, &str)> for LogRow {
398398
result.or_insert(key, value);
399399
}
400400
}
401+
if let Some(config) = data_display_options.row_size_config.as_ref() {
402+
result.or_insert(
403+
config.field_name.clone(),
404+
config.units.convert(row_size_in_bytes),
405+
);
406+
}
401407
Ok(result)
402408
}
403409
}

src/app/data_display_options.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ pub struct DataDisplayOptions {
2626

2727
/// Used for optionally converting message levels to strings
2828
pub level_conversion: Option<LevelConversion>,
29+
30+
/// Used for optionally including the size of messages
31+
pub row_size_config: Option<RowSizeConfig>,
2932
}
3033

31-
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
34+
#[derive(Default, serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
35+
#[serde(default)]
3236
pub struct FieldColoringRules {
3337
/// Matches a field value to color
3438
pub value_color_map: BTreeMap<String, Color32>,
@@ -45,6 +49,7 @@ pub enum RowParseErrorHandling {
4549
}
4650

4751
#[derive(serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
52+
#[serde(default)]
4853
pub struct LevelConversion {
4954
/// Skips record if field name already exists
5055
pub display_field_name: String,
@@ -53,6 +58,37 @@ pub struct LevelConversion {
5358
pub convert_map: BTreeMap<i64, String>,
5459
}
5560

61+
#[derive(Default, serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
62+
#[serde(default)]
63+
pub struct RowSizeConfig {
64+
pub field_name: String,
65+
pub units: SizeUnits,
66+
}
67+
68+
#[derive(Default, serde::Deserialize, serde::Serialize, Debug, PartialEq, Eq)]
69+
pub enum SizeUnits {
70+
Bytes,
71+
#[default]
72+
KB,
73+
MB,
74+
GB,
75+
TB,
76+
// TODO 5: Add an auto option to use smallest non fractional (would need to use str instead of f32)
77+
}
78+
impl SizeUnits {
79+
pub(crate) fn convert(&self, row_size_in_bytes: usize) -> serde_json::Value {
80+
let scalar = match self {
81+
SizeUnits::Bytes => 1.0,
82+
SizeUnits::KB => 1024.0,
83+
SizeUnits::MB => 1024.0 * 1024.0,
84+
SizeUnits::GB => 1024.0 * 1024.0 * 1024.0,
85+
SizeUnits::TB => 1024.0 * 1024.0 * 1024.0 * 1024.0,
86+
};
87+
let result = row_size_in_bytes as f64 / scalar;
88+
result.into()
89+
}
90+
}
91+
5692
impl DataDisplayOptions {
5793
pub fn main_list_fields(&self) -> &[String] {
5894
&self.main_list_fields
@@ -72,6 +108,7 @@ impl Default for DataDisplayOptions {
72108
main_list_fields: [
73109
"row#",
74110
"level_str",
111+
"row_size",
75112
"time",
76113
"request_id",
77114
"otel.name",
@@ -108,6 +145,10 @@ impl Default for DataDisplayOptions {
108145
.collect(),
109146
emphasize_if_matching_field_idx: Some(3),
110147
row_idx_field_name: Some("row#".to_string()),
148+
row_size_config: Some(RowSizeConfig {
149+
field_name: "row_size".to_string(),
150+
units: SizeUnits::Bytes,
151+
}),
111152
row_parse_error_handling: Default::default(),
112153
level_conversion: Some(Default::default()),
113154
colored_fields: [(

0 commit comments

Comments
 (0)