Skip to content

Commit 583f715

Browse files
committed
set HealthStatus enum invariant integer values;
1 parent fe4a81b commit 583f715

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

core/src/metrics.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use tower_http::cors::CorsLayer;
1919
use crate::box_kind::PoolBox;
2020
use crate::monitor::check_oracle_health;
2121
use crate::monitor::check_pool_health;
22-
use crate::monitor::HealthStatus;
2322
use crate::monitor::OracleHealth;
2423
use crate::monitor::PoolHealth;
2524
use crate::node_interface::node_api::NodeApi;
@@ -214,11 +213,7 @@ fn update_pool_health(pool_health: &PoolHealth) {
214213
POOL_BOX_HEIGHT.set(pool_health.details.pool_box_height.into());
215214
CURRENT_HEIGHT.set(pool_health.details.current_height.into());
216215
EPOCH_LENGTH.set(pool_health.details.epoch_length.into());
217-
let health = match pool_health.status {
218-
HealthStatus::Ok => 1,
219-
HealthStatus::Down => 0,
220-
};
221-
POOL_IS_HEALTHY.set(health);
216+
POOL_IS_HEALTHY.set(pool_health.status as i64);
222217
for oracle in &pool_health.details.all_oracles {
223218
let box_type = oracle.box_height.label_name();
224219
let box_height = oracle.box_height.oracle_box_height().into();
@@ -242,12 +237,7 @@ fn update_oracle_health(oracle_health: &OracleHealth) {
242237
MY_ORACLE_BOX_HEIGHT
243238
.with_label_values(&[box_type])
244239
.set(oracle_health.details.box_details.oracle_box_height().into());
245-
246-
let health = match oracle_health.status {
247-
HealthStatus::Ok => 1,
248-
HealthStatus::Down => 0,
249-
};
250-
ORACLE_IS_HEALTHY.set(health);
240+
ORACLE_IS_HEALTHY.set(oracle_health.status as i64);
251241
}
252242

253243
fn update_reward_tokens_in_buyback_box(oracle_pool: Arc<OraclePool>) {

core/src/monitor.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,16 @@ use crate::oracle_types::EpochLength;
1414
use crate::oracle_types::MinDatapoints;
1515
use crate::pool_config::POOL_CONFIG;
1616

17-
#[derive(Debug, serde::Serialize)]
17+
#[derive(Debug, serde::Serialize, Copy, Clone)]
1818
pub enum HealthStatus {
19-
Ok,
20-
Down,
19+
Ok = 1,
20+
Down = 0,
21+
}
22+
23+
impl HealthStatus {
24+
pub fn get_integer_value(&self) -> i32 {
25+
*self as i32
26+
}
2127
}
2228

2329
#[derive(Debug, serde::Serialize)]

0 commit comments

Comments
 (0)