Skip to content

Commit

Permalink
address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
brayniac committed Sep 18, 2024
1 parent 17a4f92 commit b0896a7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion src/server/pingserver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,4 @@ tonic = { version = "0.12" }
warp = "0.3.6"

[build-dependencies]
criterion = "*"
tonic-build = "0.12"
55 changes: 54 additions & 1 deletion src/server/pingserver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use config::{Config, Engine};
use entrystore::Noop;
use logger::{configure_logging, Drain};
use protocol_ping::{Request, RequestParser, Response};
use server::ProcessBuilder;
use server::{PERCENTILES, ProcessBuilder};

use backtrace::Backtrace;
use clap::{Arg, Command};
use metriken::*;

use std::sync::atomic::{AtomicBool, Ordering};
use std::time::Duration;
Expand All @@ -33,14 +34,66 @@ fn main() {
// parse command line options
let matches = Command::new(env!("CARGO_BIN_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.long_about(
"A rust implementation of, arguably, the most over-engineered ping \
server.\n\n\
The purpose is to demonstrate how to create an otherwise minimal \
service with the libraries and modules provied by Pelikan, which \
meets stringent requirements on latencies, observability, \
configurability, and other valuable traits in a typical production \
environment.",
)
.arg(
Arg::new("CONFIG")
.help("Server configuration file")
.action(clap::ArgAction::Set)
.index(1),
)
.arg(
Arg::new("stats")
.short('s')
.long("stats")
.help("List all metrics in stats")
.action(clap::ArgAction::SetTrue),
)
.get_matches();

if matches.get_flag("stats") {
println!("{:<31} {:<15} DESCRIPTION", "NAME", "TYPE");

let mut metrics = Vec::new();

for metric in &metriken::metrics() {
let any = match metric.as_any() {
Some(any) => any,
None => {
continue;
}
};

if any.downcast_ref::<Counter>().is_some() {
metrics.push(format!("{:<31} counter", metric.name()));
} else if any.downcast_ref::<Gauge>().is_some() {
metrics.push(format!("{:<31} gauge", metric.name()));
} else if any.downcast_ref::<AtomicHistogram>().is_some()
|| any.downcast_ref::<RwLockHistogram>().is_some()
{
for (label, _) in PERCENTILES {
let name = format!("{}_{}", metric.name(), label);
metrics.push(format!("{name:<31} percentile"));
}
} else {
continue;
}
}

metrics.sort();
for metric in metrics {
println!("{metric}");
}
std::process::exit(0);
}

// load config from file
let config = if let Some(file) = matches.get_one::<String>("CONFIG") {
debug!("loading config: {}", file);
Expand Down

0 comments on commit b0896a7

Please sign in to comment.