Skip to content

Commit

Permalink
Added diagnostic-path command option and improved compatibility with …
Browse files Browse the repository at this point in the history
…older versions
  • Loading branch information
edmocosta committed May 24, 2024
1 parent 1c4b7bb commit ebfe532
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 33 deletions.
11 changes: 3 additions & 8 deletions src/cli/api/stats.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::collections::HashMap;

use serde::{Deserialize, Deserializer};
use serde::Serialize;
use serde::{Deserialize, Deserializer};
use serde_json::{Map, Value};

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand All @@ -25,7 +25,7 @@ pub struct NodeStatsVertex {
pub events_out: i64,
pub events_in: i64,
pub duration_in_millis: u64,
pub queue_push_duration_in_millis: u64
pub queue_push_duration_in_millis: u64,
}

#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
Expand Down Expand Up @@ -362,12 +362,7 @@ pub struct Plugin {
}

impl Plugin {
pub fn get_other<'a, U>(
&'a self,
field: &str,
mapper: fn(&'a Value) -> U,
default: U,
) -> U {
pub fn get_other<'a, U>(&'a self, field: &str, mapper: fn(&'a Value) -> U, default: U) -> U {
let mut split: Vec<&str> = field.split('.').rev().collect();
let mut current: &Map<String, Value> = &self.other;

Expand Down
2 changes: 1 addition & 1 deletion src/cli/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Cli {
pub skip_tls_verification: bool,

/// Read the data from a Logstash diagnostic path
#[arg(long, short='p', global = false)]
#[arg(long, short = 'p', global = false)]
pub diagnostic_path: Option<String>,
}

Expand Down
5 changes: 4 additions & 1 deletion src/cli/commands/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ impl DurationFormatter for u64 {
}

let duration = *self as f64 / events_count as f64;
human_format::Formatter::new().format(duration).trim().to_string()
human_format::Formatter::new()
.format(duration)
.trim()
.to_string()
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/cli/commands/node/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ impl RunnableCommand<NodeArgs> for NodeCommand {
None => OutputFormat::Default,
Some(value) => OutputFormat::try_from(value.as_ref())?,
};

if config.diagnostic_path.is_some() {
return Err(TuiError::from("The --diagnostic-path argument is not supported by the get command").into());
return Err(TuiError::from(
"The --diagnostic-path argument is not supported by the get command",
)
.into());
}

let info_types = &NodeCommand::parse_info_types(&args.types)?;
if output_format == OutputFormat::Raw {
let raw = config.api.get_node_info_as_string(info_types, None)?;
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/tui/data_fetcher.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::fs;
use std::path::Path;

use crate::api::Client;
use crate::api::node::{NodeInfo, NodeInfoType};
use crate::api::stats::NodeStats;
use crate::api::Client;
use crate::errors::{AnyError, TuiError};

pub(crate) trait DataFetcher<'a> {
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/tui/flow_charts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::commands::formatter::NumberFormatter;
use crate::commands::tui::charts::{
create_chart_float_label_spans, create_chart_timestamp_label_spans, ChartDataPoint,
TimestampChartState, DEFAULT_LABELS_COUNT,
Expand All @@ -7,7 +8,6 @@ use ratatui::layout::{Constraint, Rect};
use ratatui::prelude::{Color, Span, Style};
use ratatui::widgets::{Axis, Block, Borders, Chart, Dataset, GraphType};
use ratatui::{symbols, Frame};
use crate::commands::formatter::NumberFormatter;

pub struct PluginFlowMetricDataPoint {
pub timestamp: i64,
Expand Down
5 changes: 2 additions & 3 deletions src/cli/commands/tui/flows/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,13 +270,13 @@ fn draw_pipelines_table(f: &mut Frame, app: &mut App, area: Rect) {
let header = Row::new(header_cells)
.style(TABLE_HEADER_ROW_STYLE)
.height(1);

let widths: Vec<Constraint> = if hide_flow_cells {
vec![
Constraint::Percentage(80), // Name
Constraint::Percentage(20), // Workers
]
}else {
} else {
vec![
Constraint::Percentage(15), // Name
Constraint::Percentage(5), // Workers
Expand All @@ -288,7 +288,6 @@ fn draw_pipelines_table(f: &mut Frame, app: &mut App, area: Rect) {
]
};


let pipelines = Table::new(rows, widths)
.header(header)
.block(Block::default().borders(Borders::ALL).title("Pipelines"))
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/tui/node/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ fn draw_node_charts(f: &mut Frame, app: &mut App, area: Rect) {
None,
&app.node_state.chart_flow_queue_backpressure,
flow_chart_chunks[2],
false
false,
);

let node_chart_chunks = Layout::default()
Expand Down
23 changes: 11 additions & 12 deletions src/cli/commands/tui/pipelines/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::vec;

use humansize::{DECIMAL, format_size_i};
use ratatui::Frame;
use humansize::{format_size_i, DECIMAL};
use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect};
use ratatui::style::{Color, Style};
use ratatui::text::{Line, Span, Text};
use ratatui::widgets::{Block, Borders, Cell, Paragraph, Row, Table, Wrap};
use ratatui::Frame;
use serde_json::Value;

use crate::api::node::Vertex;
Expand Down Expand Up @@ -207,7 +207,7 @@ fn draw_selected_pipeline_flow_charts(f: &mut Frame, app: &mut App, area: Rect)
None,
&selected_pipeline_state.queue_backpressure,
pipeline_flow_chunks[1],
false
false,
);
}
}
Expand Down Expand Up @@ -450,7 +450,7 @@ fn create_pipeline_vertex_plugin_row<'a>(
plugin_throughput.current.format_number().trim()
),
Style::default().fg(Color::Blue),
)])));
)])));
}
}
}
Expand All @@ -469,7 +469,7 @@ fn create_pipeline_vertex_plugin_row<'a>(
Ordering::Less => {
let drop_percentage = 100.00
- ((vertex_stats.events_out as f64 / vertex_stats.events_in as f64)
* 100.0);
* 100.0);
let drop_percentage_text = if drop_percentage > 0.01 {
format!(" {}% ↓", drop_percentage.strip_number_decimals(2))
} else {
Expand Down Expand Up @@ -498,9 +498,8 @@ fn create_pipeline_vertex_plugin_row<'a>(
duration_in_millis.format_duration_per_event(events_count as u64),
)];

let mut duration_percentage = (duration_in_millis as f64
/ stats.events.duration_in_millis as f64)
* 100.0;
let mut duration_percentage =
(duration_in_millis as f64 / stats.events.duration_in_millis as f64) * 100.0;
if duration_percentage.is_nan() {
duration_percentage = 0.0
}
Expand Down Expand Up @@ -701,7 +700,7 @@ fn draw_selected_pipeline_queue_vertex_details(f: &mut Frame, app: &App, area: R
Some("bytes"),
&selected_pipeline_state.queue_persisted_growth_bytes,
chart_chunks[0],
false
false,
);
}

Expand All @@ -715,7 +714,7 @@ fn draw_selected_pipeline_queue_vertex_details(f: &mut Frame, app: &App, area: R
Some("events"),
&selected_pipeline_state.queue_persisted_growth_events,
chart_chunks[1],
false
false,
);
}
}
Expand Down Expand Up @@ -824,7 +823,7 @@ fn draw_selected_pipeline_plugin_vertex_charts(
None,
worker_utilization_state,
chunks[0],
false
false,
);
}
}
Expand All @@ -837,7 +836,7 @@ fn draw_selected_pipeline_plugin_vertex_charts(
None,
worker_millis_per_event_state,
chunks[1],
false
false,
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ impl Display for TuiError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.message)
}
}
}
2 changes: 1 addition & 1 deletion src/cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fn run() -> Result<ExitCode, AnyError> {
let api = api::Client::new(&cli.host, username, password, cli.skip_tls_verification).unwrap();
let config = Config {
api: &api,
diagnostic_path: cli.diagnostic_path
diagnostic_path: cli.diagnostic_path,
};

let stdout = std::io::stdout();
Expand Down

0 comments on commit ebfe532

Please sign in to comment.