Skip to content

Commit

Permalink
move structures to a different module
Browse files Browse the repository at this point in the history
  • Loading branch information
mihirn committed Aug 5, 2023
1 parent 3cec100 commit cd47c2b
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 76 deletions.
77 changes: 77 additions & 0 deletions src/dataspec/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
use serde::{Deserialize, Serialize};

use histogram::CompactHistogram;

#[derive(Serialize, Deserialize)]
pub struct Connections {
/// number of current connections (gauge)
pub current: i64,
/// number of total connect attempts
pub total: u64,
/// number of connections established
pub opened: u64,
/// number of connect attempts that failed
pub error: u64,
/// number of connect attempts that hit timeout
pub timeout: u64,
}

#[derive(Copy, Clone, Serialize, Deserialize)]
pub struct Requests {
pub total: u64,
pub ok: u64,
pub reconnect: u64,
pub unsupported: u64,
}

#[derive(Serialize, Deserialize)]
pub struct Responses {
/// total number of responses
pub total: u64,
/// number of responses that were successful
pub ok: u64,
/// number of responses that were unsuccessful
pub error: u64,
/// number of responses that were missed due to timeout
pub timeout: u64,
/// number of read requests with a hit response
pub hit: u64,
/// number of read requests with a miss response
pub miss: u64,
}

#[derive(Serialize, Deserialize)]
pub struct Client {
pub connections: Connections,
pub requests: Requests,
pub responses: Responses,
pub request_latency: CompactHistogram,
}

#[derive(Serialize, Deserialize)]
pub struct Pubsub {
pub publishers: Publishers,
pub subscribers: Subscribers,
}

#[derive(Serialize, Deserialize)]
pub struct Publishers {
// current number of publishers
pub current: i64,
}

#[derive(Serialize, Deserialize)]
pub struct Subscribers {
// current number of subscribers
pub current: i64,
}

#[derive(Serialize, Deserialize)]
pub struct RpcPerfSnapshot {
pub window: u64,
pub elapsed: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub target_qps: Option<f64>,
pub client: Client,
pub pubsub: Pubsub,
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod dataspec;
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use warp::Filter;
mod admin;
mod clients;
mod config;
mod dataspec;
mod metrics;
mod net;
mod output;
Expand Down
81 changes: 5 additions & 76 deletions src/output/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
use crate::dataspec::{
Client, Connections, Publishers, Pubsub, Requests, Responses, RpcPerfSnapshot, Subscribers,
};
use crate::*;

use ahash::{HashMap, HashMapExt};
use ratelimit::Ratelimiter;
use serde::Serialize;
use std::io::{BufWriter, Write};

use histogram::CompactHistogram;
Expand Down Expand Up @@ -219,80 +222,6 @@ fn pubsub_stats(snapshot: &mut Snapshot, elapsed: f64) -> u64 {
pubsub_tx_ok
}

#[derive(Serialize)]
struct Connections {
/// number of current connections (gauge)
current: i64,
/// number of total connect attempts
total: u64,
/// number of connections established
opened: u64,
/// number of connect attempts that failed
error: u64,
/// number of connect attempts that hit timeout
timeout: u64,
}

#[derive(Serialize, Copy, Clone)]
struct Requests {
total: u64,
ok: u64,
reconnect: u64,
unsupported: u64,
}

#[derive(Serialize)]
struct Responses {
/// total number of responses
total: u64,
/// number of responses that were successful
ok: u64,
/// number of responses that were unsuccessful
error: u64,
/// number of responses that were missed due to timeout
timeout: u64,
/// number of read requests with a hit response
hit: u64,
/// number of read requests with a miss response
miss: u64,
}

#[derive(Serialize)]
struct Client {
connections: Connections,
requests: Requests,
responses: Responses,
request_latency: CompactHistogram,
}

#[derive(Serialize)]
struct Pubsub {
publishers: Publishers,
subscribers: Subscribers,
}

#[derive(Serialize)]
struct Publishers {
// current number of publishers
current: i64,
}

#[derive(Serialize)]
struct Subscribers {
// current number of subscribers
current: i64,
}

#[derive(Serialize)]
struct JsonSnapshot {
window: u64,
elapsed: f64,
#[serde(skip_serializing_if = "Option::is_none")]
target_qps: Option<f64>,
client: Client,
pubsub: Pubsub,
}

// gets the non-zero buckets for the most recent window in the heatmap
fn heatmap_to_buckets(heatmap: &Heatmap) -> CompactHistogram {
// XXX: The heatmap corrects for wraparound and fixes indices once
Expand Down Expand Up @@ -376,7 +305,7 @@ pub fn json(config: Config, ratelimit: Option<&Ratelimiter>) {
miss: response_miss,
};

let json = JsonSnapshot {
let json = RpcPerfSnapshot {
window: window_id,
elapsed,
target_qps: ratelimit.as_ref().map(|ratelimit| ratelimit.rate()),
Expand Down

0 comments on commit cd47c2b

Please sign in to comment.