Skip to content

Commit

Permalink
Refactor snapshot handling and add detailed procdump functionality (#…
Browse files Browse the repository at this point in the history
…1497)

This commit refactors the snapshot handling system to improve modularity
and efficiency. The snapshot functionality has been moved to a dedicated
module, and temporary files are now used for command outputs.

Additionally, a new procdump module has been introduced to provide
detailed process information, parsing /proc data into a human-readable format.
This enhancement allows for more comprehensive system diagnostics and better
resource management. The changes also include updates to the Cargo.toml
files to reflect version increments and new dependencies.
  • Loading branch information
hubcio authored Feb 9, 2025
1 parent 9956282 commit aa17d53
Show file tree
Hide file tree
Showing 11 changed files with 530 additions and 131 deletions.
76 changes: 72 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iggy-cli"
version = "0.8.7"
version = "0.8.8"
edition = "2021"
authors = ["[email protected]"]
repository = "https://github.com/iggy-rs/iggy"
Expand All @@ -21,13 +21,19 @@ clap = { version = "4.5.28", features = ["derive"] }
clap_complete = "4.5.44"
figlet-rs = "0.1.5"
iggy = { path = "../sdk", features = ["iggy-cli"], version = "0.6.90" }
keyring = { version = "3.6.1", features = ["sync-secret-service", "vendored"], optional = true }
keyring = { version = "3.6.1", features = [
"sync-secret-service",
"vendored",
], optional = true }
passterm = "=2.0.1"
thiserror = "2.0.11"
tokio = { version = "1.43.0", features = ["full"] }
tracing = "0.1.41"
tracing-appender = "0.2.3"
tracing-subscriber = { version = "0.3.19", default-features = false, features = ["fmt", "env-filter"] }
tracing-subscriber = { version = "0.3.19", default-features = false, features = [
"fmt",
"env-filter",
] }

[[bin]]
name = "iggy"
Expand Down
2 changes: 2 additions & 0 deletions cli/src/args/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub(crate) struct SnapshotArgs {
/// - `resource_usage`: Monitors CPU, memory, and other system resources.
/// - `test`: Used for testing purposes.
/// - `server_logs`: Server logs from the specified logging directory, useful for system diagnostics.
/// - `server_config`: Server configuration.
/// - `all`: Take all available snapshots.
///
/// Examples:
/// - `--snapshot-types filesystem_overview process_list`
Expand Down
29 changes: 15 additions & 14 deletions integration/tests/cli/system/test_snapshot_cmd.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use std::{
fs::{self, File},
io::Read,
};

use crate::cli::common::CLAP_INDENT;
use crate::cli::common::{IggyCmdCommand, IggyCmdTest, IggyCmdTestCase, TestHelpCmd, USAGE_PREFIX};
use assert_cmd::assert::Assert;
use async_trait::async_trait;
use iggy::client::Client;
use predicates::str::starts_with;
use serial_test::parallel;
use std::{
fs::{self, File},
io::Read,
};
use tempfile::tempdir;
use zip::ZipArchive;

use crate::cli::common::{IggyCmdCommand, IggyCmdTest, IggyCmdTestCase, TestHelpCmd, USAGE_PREFIX};

struct TestSnapshotCmd {
temp_out_dir: String,
}
Expand Down Expand Up @@ -110,39 +109,41 @@ pub async fn should_help_match() {
Options:
-c, --compression <COMPRESSION>
Specify snapshot compression method.
{CLAP_INDENT}
Available options:
{CLAP_INDENT}
- `stored`: No compression
- `deflated`: Standard deflate compression
- `bzip2`: Higher compression ratio but slower
- `zstd`: Fast compression and decompression
- `lzma`: High compression, suitable for large files
- `xz`: Similar to `lzma` but often faster in decompression
{CLAP_INDENT}
Examples:
- `--compression bzip2` for higher compression.
- `--compression none` to store without compression.
-s, --snapshot-types <SNAPSHOT_TYPES>...
Specify types of snapshots to include.
{CLAP_INDENT}
Available snapshot types:
- `filesystem_overview`: Provides an overview of the filesystem structure.
- `process_list`: Captures the list of active processes.
- `resource_usage`: Monitors CPU, memory, and other system resources.
- `test`: Used for testing purposes.
- `server_logs`: Server logs from the specified logging directory, useful for system diagnostics.
- `server_config`: Server configuration.
- `all`: Take all available snapshots.
{CLAP_INDENT}
Examples:
- `--snapshot-types filesystem_overview process_list`
- `--snapshot-types resource_usage`
-o, --out-dir <OUT_DIR>
Define the output directory for the snapshot file.
{CLAP_INDENT}
This directory will contain the snapshot files generated by the command.
{CLAP_INDENT}
Examples:
- `--out-dir /var/snapshots`
- `--out-dir ./snapshots`
Expand Down
2 changes: 1 addition & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iggy"
version = "0.6.101"
version = "0.6.102"
description = "Iggy is the persistent message streaming platform written in Rust, supporting QUIC, TCP and HTTP transport protocols, capable of processing millions of messages per second."
edition = "2021"
license = "Apache-2.0"
Expand Down
26 changes: 26 additions & 0 deletions sdk/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ pub enum SystemSnapshotType {
Test,
/// Server logs
ServerLogs,
/// Server configuration
ServerConfig,
/// Everything
All,
}

/// Enum representing the various compression methods available for snapshots.
Expand Down Expand Up @@ -45,6 +49,8 @@ impl SystemSnapshotType {
SystemSnapshotType::ResourceUsage => 3,
SystemSnapshotType::Test => 4,
SystemSnapshotType::ServerLogs => 5,
SystemSnapshotType::ServerConfig => 6,
SystemSnapshotType::All => 100,
}
}

Expand All @@ -55,9 +61,25 @@ impl SystemSnapshotType {
3 => Ok(SystemSnapshotType::ResourceUsage),
4 => Ok(SystemSnapshotType::Test),
5 => Ok(SystemSnapshotType::ServerLogs),
6 => Ok(SystemSnapshotType::ServerConfig),
100 => Ok(SystemSnapshotType::All),
_ => Err(IggyError::InvalidCommand),
}
}

pub fn all_snapshot_types() -> Vec<SystemSnapshotType> {
vec![
SystemSnapshotType::FilesystemOverview,
SystemSnapshotType::ProcessList,
SystemSnapshotType::ResourceUsage,
SystemSnapshotType::ServerLogs,
SystemSnapshotType::ServerConfig,
]
}

pub fn code(&self) -> u8 {
self.as_code()
}
}

impl fmt::Display for SystemSnapshotType {
Expand All @@ -68,6 +90,8 @@ impl fmt::Display for SystemSnapshotType {
SystemSnapshotType::ResourceUsage => write!(f, "resource_usage"),
SystemSnapshotType::Test => write!(f, "test"),
SystemSnapshotType::ServerLogs => write!(f, "server_logs"),
SystemSnapshotType::ServerConfig => write!(f, "server_config"),
SystemSnapshotType::All => write!(f, "all"),
}
}
}
Expand All @@ -82,6 +106,8 @@ impl FromStr for SystemSnapshotType {
"resource_usage" => Ok(SystemSnapshotType::ResourceUsage),
"test" => Ok(SystemSnapshotType::Test),
"server_logs" => Ok(SystemSnapshotType::ServerLogs),
"server_config" => Ok(SystemSnapshotType::ServerConfig),
"all" => Ok(SystemSnapshotType::All),
_ => Err(format!("Invalid snapshot type: {}", s)),
}
}
Expand Down
5 changes: 5 additions & 0 deletions sdk/src/system/get_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::validatable::Validatable;
use bytes::{BufMut, Bytes, BytesMut};
use serde::{Deserialize, Serialize};
use std::fmt::Display;
use tracing::error;

/// `GetSnapshot` command is used to get snapshot information.
#[derive(Debug, Serialize, Deserialize, PartialEq)]
Expand Down Expand Up @@ -37,6 +38,10 @@ impl Command for GetSnapshot {

impl Validatable<IggyError> for GetSnapshot {
fn validate(&self) -> Result<(), IggyError> {
if self.snapshot_types.contains(&SystemSnapshotType::All) && self.snapshot_types.len() > 1 {
error!("When using 'All' snapshot type, no other types can be specified");
return Err(IggyError::InvalidCommand);
}
Ok(())
}
}
Expand Down
Loading

0 comments on commit aa17d53

Please sign in to comment.