Skip to content

Commit

Permalink
retire vergen
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Nov 16, 2024
1 parent bc769e1 commit 689d3a7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 92 deletions.
30 changes: 0 additions & 30 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ authors = ["Niklas Fiekas <[email protected]>"]
categories = ["games"]
keywords = ["chess", "lichess"]
edition = "2021"
build = "build.rs"

[dependencies]
axum = { version = "0.7", features = ["macros", "multipart"] }
Expand Down Expand Up @@ -54,8 +53,5 @@ lto = true
name = "benches"
harness = false

[build-dependencies]
vergen = { version = "8.2.4", features = ["git", "gitcl"] }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(tokio_unstable)"] }
11 changes: 0 additions & 11 deletions build.rs

This file was deleted.

74 changes: 33 additions & 41 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,49 +364,41 @@ async fn monitor(
State(db): State<Arc<Database>>,
State(semaphore): State<&'static Semaphore>,
) -> String {
if metrics.fetch_set_deploy_event_sent() {
spawn_blocking(semaphore, move || {
format!(
"opening_explorer {}",
[
// Cache entries
format!("lichess_cache={}u", lichess_cache.entry_count()),
format!("masters_cache={}u", masters_cache.entry_count()),
// Request metrics
metrics.to_influx_string(),
// Block cache
db.metrics().expect("db metrics").to_influx_string(),
// Indexer
format!("indexing={}u", player_indexer.num_indexing()),
// Blacklist
format!(
"blacklist={}u",
blacklist.read().expect("read blacklist").len()
),
// Column families
db.masters()
.estimate_metrics()
.expect("masters metrics")
.to_influx_string(),
db.lichess()
.estimate_metrics()
.expect("lichess metrics")
.to_influx_string(),
// Tokio
#[cfg(tokio_unstable)]
tokio_metrics_to_influx_string(),
]
.join(",")
)
})
.await
} else {
spawn_blocking(semaphore, move || {
format!(
"event,program=lila-openingexplorer commit={:?},text={:?}",
env!("VERGEN_GIT_SHA"),
env!("VERGEN_GIT_COMMIT_MESSAGE")
"opening_explorer {}",
[
// Cache entries
format!("lichess_cache={}u", lichess_cache.entry_count()),
format!("masters_cache={}u", masters_cache.entry_count()),
// Request metrics
metrics.to_influx_string(),
// Block cache
db.metrics().expect("db metrics").to_influx_string(),
// Indexer
format!("indexing={}u", player_indexer.num_indexing()),
// Blacklist
format!(
"blacklist={}u",
blacklist.read().expect("read blacklist").len()
),
// Column families
db.masters()
.estimate_metrics()
.expect("masters metrics")
.to_influx_string(),
db.lichess()
.estimate_metrics()
.expect("lichess metrics")
.to_influx_string(),
// Tokio
#[cfg(tokio_unstable)]
tokio_metrics_to_influx_string(),
]
.join(",")
)
}
})
.await
}

#[axum::debug_handler(state = AppState)]
Expand Down
7 changes: 1 addition & 6 deletions src/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
use std::{
sync::atomic::{AtomicBool, AtomicU64, Ordering},
sync::atomic::{AtomicU64, Ordering},
time::Duration,
};

use crate::api::Source;

#[derive(Default)]
pub struct Metrics {
deploy_event_sent: AtomicBool,
hit: HitMetrics,
slow_hit: HitMetrics,
}

impl Metrics {
const SLOW_DURATION: Duration = Duration::from_millis(500);

pub fn fetch_set_deploy_event_sent(&self) -> bool {
self.deploy_event_sent.fetch_or(true, Ordering::Relaxed)
}

pub fn to_influx_string(&self) -> String {
[
self.hit.to_influx_string(""),
Expand Down

0 comments on commit 689d3a7

Please sign in to comment.