Skip to content

Commit

Permalink
Fix status endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
the2pizza committed Oct 28, 2024
1 parent 00ca136 commit 4335970
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pony"
version = "0.0.13"
version = "0.0.14"
edition = "2021"

[dependencies]
Expand Down
14 changes: 8 additions & 6 deletions src/web.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ pub async fn status(req: Path<Params>, ch_client: Data<Arc<Client>>) -> impl Res

for (metric, value) in metrics_value_connections {
if let Some(stripped_metric) = metric.strip_prefix(format!("{}.", req.env).as_str()) {
let parts: Vec<&str> = stripped_metric.split(".connections.").collect();
if parts.len() == 2 {
let key = format!("connections.{}.{}", parts[0], parts[1]);
let parts: Vec<&str> = stripped_metric.split(".").collect();
if parts.len() == 3 {
let key = format!("connections.{}.{}", parts[0], parts[2]);
metrics_map_result.insert(key, value);

let prefix = parts[0].to_string();
Expand Down Expand Up @@ -75,19 +75,21 @@ pub async fn status(req: Path<Params>, ch_client: Data<Arc<Client>>) -> impl Res
}
}

for (prefix, sum) in prefix_sums_connections {
for (prefix, sum) in prefix_sums_connections.clone() {
metrics_map_result.insert(format!("connections.{}.total", prefix), sum);
}

debug!("Metrics Result {:?}", metrics_map_result);
metrics_map_result.insert(
format!("connections.total"),
prefix_sums_connections.values().sum(),
);

HttpResponse::Ok().json(metrics_map_result)
}

#[get("/status/clickhouse")]
async fn status_ch(ch_client: Data<Arc<Client>>) -> impl Responder {
let query = "SELECT toUInt32(1)";
debug!("Req /status/clickhouse");
match ch_client.query(query).fetch_all::<u32>().await {
Ok(_) => HttpResponse::Ok().body("Ok"),
Err(e) => HttpResponse::InternalServerError().body(format!("Error: {:?}", e)),
Expand Down

0 comments on commit 4335970

Please sign in to comment.