Skip to content

Commit db82c07

Browse files
committed
chore: migrate to gasket prometheus exporter
1 parent 79a069c commit db82c07

File tree

7 files changed

+92
-289
lines changed

7 files changed

+92
-289
lines changed

Cargo.lock

+15-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ u5c = ["tonic"]
2626
# pallas = { path = "../pallas/pallas" }
2727
pallas = { git = "https://github.com/txpipe/pallas" }
2828

29-
gasket = { version = "^0.6", features = ["derive"] }
29+
gasket = { version = "^0.7", features = ["derive"] }
30+
gasket-prometheus = { version = "^0.7" }
3031
# gasket = { path = "../../construkts/gasket-rs/gasket", features = ["derive"] }
3132
# gasket = { git = "https://github.com/construkts/gasket-rs.git", features = ["derive"] }
3233

@@ -46,11 +47,9 @@ serde = { version = "1.0.152", features = ["derive"] }
4647
serde_json = { version = "1.0.104", features = ["arbitrary_precision"] }
4748
strum = "0.24"
4849
strum_macros = "0.25"
49-
prometheus_exporter_base = { version = "1.4.0", features = ["hyper", "hyper_server"] }
5050
unicode-truncate = "0.2.0"
5151
thiserror = "1.0.39"
5252
indicatif = "0.17.3"
53-
lazy_static = "1.4.0"
5453
tracing = "0.1.37"
5554
tracing-subscriber = "0.3.17"
5655
anyhow = "1.0.77"

src/bin/oura/console.rs

+9-86
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
1-
use std::{
2-
sync::Mutex,
3-
time::{Duration, Instant},
4-
};
5-
6-
use gasket::{metrics::Reading, runtime::Tether};
7-
use lazy_static::lazy_static;
8-
use tracing::{debug, error, warn};
9-
10-
#[derive(clap::ValueEnum, Clone, Default)]
11-
pub enum Mode {
12-
/// shows progress as a plain sequence of logs
13-
#[default]
14-
Plain,
15-
/// shows aggregated progress and metrics
16-
Tui,
17-
}
1+
use gasket::{daemon::Daemon, metrics::Reading, runtime::Tether};
2+
use std::{sync::Arc, time::Duration};
183

194
struct TuiConsole {
205
chainsync_progress: indicatif::ProgressBar,
@@ -116,77 +101,15 @@ impl TuiConsole {
116101
}
117102
}
118103

119-
struct PlainConsole {
120-
last_report: Mutex<Instant>,
121-
}
122-
123-
impl PlainConsole {
124-
fn new() -> Self {
125-
Self {
126-
last_report: Mutex::new(Instant::now()),
127-
}
104+
pub async fn render(daemon: Arc<Daemon>, tui_enabled: bool) {
105+
if !tui_enabled {
106+
return;
128107
}
129108

130-
fn refresh<'a>(&self, tethers: impl Iterator<Item = &'a Tether>) {
131-
let mut last_report = self.last_report.lock().unwrap();
132-
133-
if last_report.elapsed() <= Duration::from_secs(10) {
134-
return;
135-
}
136-
137-
for tether in tethers {
138-
match tether.check_state() {
139-
gasket::runtime::TetherState::Dropped => {
140-
error!("[{}] stage tether has been dropped", tether.name());
141-
}
142-
gasket::runtime::TetherState::Blocked(_) => {
143-
warn!(
144-
"[{}] stage tehter is blocked or not reporting state",
145-
tether.name()
146-
);
147-
}
148-
gasket::runtime::TetherState::Alive(state) => {
149-
debug!("[{}] stage is alive with state: {:?}", tether.name(), state);
150-
match tether.read_metrics() {
151-
Ok(readings) => {
152-
for (key, value) in readings {
153-
debug!("[{}] metric `{}` = {:?}", tether.name(), key, value);
154-
}
155-
}
156-
Err(err) => {
157-
error!("[{}] error reading metrics: {}", tether.name(), err)
158-
}
159-
}
160-
}
161-
}
162-
}
163-
164-
*last_report = Instant::now();
165-
}
166-
}
167-
168-
lazy_static! {
169-
static ref TUI_CONSOLE: TuiConsole = TuiConsole::new();
170-
}
171-
172-
lazy_static! {
173-
static ref PLAIN_CONSOLE: PlainConsole = PlainConsole::new();
174-
}
175-
176-
pub fn initialize(mode: &Option<Mode>) {
177-
if !matches!(mode, Some(Mode::Tui)) {
178-
tracing::subscriber::set_global_default(
179-
tracing_subscriber::FmtSubscriber::builder()
180-
.with_max_level(tracing::Level::DEBUG)
181-
.finish(),
182-
)
183-
.unwrap();
184-
}
185-
}
109+
let tui = TuiConsole::new();
186110

187-
pub fn refresh<'a>(mode: &Option<Mode>, tethers: impl Iterator<Item = &'a Tether>) {
188-
match mode {
189-
Some(Mode::Tui) => TUI_CONSOLE.refresh(tethers),
190-
_ => PLAIN_CONSOLE.refresh(tethers),
111+
loop {
112+
tui.refresh(daemon.tethers());
113+
tokio::time::sleep(Duration::from_secs(1)).await;
191114
}
192115
}

0 commit comments

Comments
 (0)