Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose get stats endpoint #1357

Merged
merged 1 commit into from
Nov 26, 2024
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
6 changes: 3 additions & 3 deletions Cargo.lock

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

4 changes: 2 additions & 2 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.2"
version = "0.8.3"
edition = "2021"
authors = ["bartosz.ciesla@gmail.com"]
repository = "https://github.com/iggy-rs/iggy"
Expand All @@ -20,7 +20,7 @@ anyhow = "1.0.86"
clap = { version = "4.5.17", features = ["derive"] }
clap_complete = "4.5.26"
figlet-rs = "0.1.5"
iggy = { path = "../sdk", features = ["iggy-cli"], version = "0.6.19" }
iggy = { path = "../sdk", features = ["iggy-cli"], version = "0.6.50" }
keyring = { version = "3.2.0", features = ["sync-secret-service", "vendored"], optional = true }
passterm = "2.0.1"
thiserror = "1.0.61"
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.40"
version = "0.6.50"
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 = "MIT"
Expand Down
1 change: 0 additions & 1 deletion sdk/src/binary/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::utils::duration::IggyDuration;
#[async_trait::async_trait]
impl<B: BinaryClient> SystemClient for B {
async fn get_stats(&self) -> Result<Stats, IggyError> {
fail_if_not_authenticated(self).await?;
let response = self.send_with_response(&GetStats {}).await?;
mapper::map_stats(response)
}
Expand Down
1 change: 1 addition & 0 deletions sdk/src/http/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const UNAUTHORIZED_PATHS: &[&str] = &[
"/",
"/metrics",
"/ping",
"/stats",
"/users/login",
"/users/refresh-token",
"/personal-access-tokens/login",
Expand Down
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "server"
version = "0.4.72"
version = "0.4.80"
edition = "2021"
build = "src/build.rs"

Expand Down
1 change: 0 additions & 1 deletion server/server.http
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ GET {{url}}/metrics

###
GET {{url}}/stats
Authorization: Bearer {{access_token}}

###
GET {{url}}/clients
Expand Down
2 changes: 1 addition & 1 deletion server/src/binary/handlers/system/get_stats_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub async fn handle(
) -> Result<(), IggyError> {
debug!("session: {session}, command: {command}");
let system = system.read().await;
let stats = system.get_stats(session).await?;
let stats = system.get_stats().await?;
let bytes = mapper::map_stats(&stats);
sender.send_ok_response(&bytes).await?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion server/src/channels/commands/print_sysinfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl SysInfoPrinter {
#[async_trait]
impl ServerCommand<SysInfoPrintCommand> for SysInfoPrintExecutor {
async fn execute(&mut self, system: &SharedSystem, _command: SysInfoPrintCommand) {
let stats = match system.read().await.get_stats_bypass_auth().await {
let stats = match system.read().await.get_stats().await {
Ok(stats) => stats,
Err(e) => {
error!("Failed to get system information. Error: {e}");
Expand Down
1 change: 1 addition & 0 deletions server/src/http/jwt/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const UNAUTHORIZED_PATHS: &[&str] = &[
"/",
"/metrics",
"/ping",
"/stats",
"/users/login",
"/users/refresh-token",
"/personal-access-tokens/login",
Expand Down
9 changes: 2 additions & 7 deletions server/src/http/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,9 @@ async fn get_metrics(State(state): State<Arc<AppState>>) -> Result<String, Custo
Ok(system.metrics.get_formatted_output())
}

async fn get_stats(
State(state): State<Arc<AppState>>,
Extension(identity): Extension<Identity>,
) -> Result<Json<Stats>, CustomError> {
async fn get_stats(State(state): State<Arc<AppState>>) -> Result<Json<Stats>, CustomError> {
let system = state.system.read().await;
let stats = system
.get_stats(&Session::stateless(identity.user_id, identity.ip_address))
.await?;
let stats = system.get_stats().await?;
Ok(Json(stats))
}

Expand Down
2 changes: 1 addition & 1 deletion server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ async fn main() -> Result<(), ServerError> {
// Workaround to ensure that the statistics are initialized before the server
// loads streams and starts accepting connections. This is necessary to
// have the correct statistics when the server starts.
system.write().await.get_stats_bypass_auth().await?;
system.write().await.get_stats().await?;
system.write().await.init().await?;

let _command_handler = ServerCommandHandler::new(system.clone(), &config)
Expand Down
9 changes: 1 addition & 8 deletions server/src/streaming/systems/stats.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use crate::streaming::session::Session;
use crate::streaming::systems::system::System;
use iggy::locking::IggySharedMutFn;
use iggy::models::stats::Stats;
Expand All @@ -17,13 +16,7 @@ fn sysinfo() -> &'static Mutex<SysinfoSystem> {
}

impl System {
pub async fn get_stats(&self, session: &Session) -> Result<Stats, IggyError> {
self.ensure_authenticated(session)?;
self.permissioner.get_stats(session.get_user_id())?;
self.get_stats_bypass_auth().await
}

pub async fn get_stats_bypass_auth(&self) -> Result<Stats, IggyError> {
pub async fn get_stats(&self) -> Result<Stats, IggyError> {
let mut sys = sysinfo().lock().await;
let process_id = std::process::id();
sys.refresh_cpu_all();
Expand Down