Skip to content

Commit

Permalink
Add ability to start from different views via subcommands
Browse files Browse the repository at this point in the history
The following views are supported:
- queries             Show now running queries (from system.processes)
- last-queries        Show last running queries (from system.query_log)
- slow-queries        Show slow (slower then 1 second, ordered by duration) queries (from system.query_log)
- merges              Show merges for MergeTree engine (system.merges)
- mutations           Show mutations for MergeTree engine (system.mutations)
- replication-queue   Show replication queue for ReplicatedMergeTree engine (system.replication_queue)
- replicated-fetches  Show fetches for ReplicatedMergeTree engine (system.replicated_fetches)
- replicas            Show information about replicas (system.replicas)
- errors              Show all errors that happend in a server since start (system.errors)
- backups             Show information about backups (system.backups)
  • Loading branch information
azat committed Sep 23, 2023
1 parent 8ca6f41 commit 0d713ed
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
28 changes: 27 additions & 1 deletion src/interpreter/options.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{builder::ArgPredicate, ArgAction, Args, CommandFactory, Parser};
use clap::{builder::ArgPredicate, ArgAction, Args, CommandFactory, Parser, Subcommand};
use clap_complete::{generate, Shell};
use quick_xml::de::Deserializer;
use serde::Deserialize;
Expand Down Expand Up @@ -31,6 +31,30 @@ struct ClickHouseClientConfig {
connections_credentials: Option<ClickHouseClientConfigConnectionsCredentialsConnection>,
}

#[derive(Debug, Clone, Subcommand)]
pub enum ChDigViews {
/// Show now running queries (from system.processes)
Queries,
/// Show last running queries (from system.query_log)
LastQueries,
/// Show slow (slower then 1 second, ordered by duration) queries (from system.query_log)
SlowQueries,
/// Show merges for MergeTree engine (system.merges)
Merges,
/// Show mutations for MergeTree engine (system.mutations)
Mutations,
/// Show replication queue for ReplicatedMergeTree engine (system.replication_queue)
ReplicationQueue,
/// Show fetches for ReplicatedMergeTree engine (system.replicated_fetches)
ReplicatedFetches,
/// Show information about replicas (system.replicas)
Replicas,
/// Show all errors that happend in a server since start (system.errors)
Errors,
/// Show information about backups (system.backups)
Backups,
}

#[derive(Parser, Clone)]
#[command(name = "chdig")]
#[command(author, version, about, long_about = None)]
Expand All @@ -39,6 +63,8 @@ pub struct ChDigOptions {
pub clickhouse: ClickHouseOptions,
#[command(flatten)]
pub view: ViewOptions,
#[command(subcommand)]
pub start_view: Option<ChDigViews>,
#[command(flatten)]
internal: InternalOptions,
}
Expand Down
24 changes: 22 additions & 2 deletions src/view/navigation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
interpreter::{clickhouse::TraceType, ContextArc, WorkerEvent},
interpreter::{clickhouse::TraceType, options::ChDigViews, ContextArc, WorkerEvent},
view,
};
use anyhow::Result;
Expand Down Expand Up @@ -135,7 +135,27 @@ impl Navigation for Cursive {
),
);

self.show_clickhouse_processes(context.clone());
let start_view = context
.lock()
.unwrap()
.options
.start_view
.clone()
.unwrap_or(ChDigViews::Queries);
match start_view {
ChDigViews::Queries => self.show_clickhouse_processes(context.clone()),
ChDigViews::LastQueries => self.show_clickhouse_last_query_log(context.clone()),
ChDigViews::SlowQueries => self.show_clickhouse_slow_query_log(context.clone()),
ChDigViews::Merges => self.show_clickhouse_merges(context.clone()),
ChDigViews::Mutations => self.show_clickhouse_mutations(context.clone()),
ChDigViews::ReplicationQueue => self.show_clickhouse_replication_queue(context.clone()),
ChDigViews::ReplicatedFetches => {
self.show_clickhouse_replicated_fetches(context.clone())
}
ChDigViews::Replicas => self.show_clickhouse_replicas(context.clone()),
ChDigViews::Errors => self.show_clickhouse_errors(context.clone()),
ChDigViews::Backups => self.show_clickhouse_backups(context.clone()),
}
}

fn initialize_global_shortcuts(&mut self, context: ContextArc) {
Expand Down

0 comments on commit 0d713ed

Please sign in to comment.