Skip to content

Commit 17cb192

Browse files
committed
Write all metrics with the same timestamp
1 parent 73e941e commit 17cb192

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

src/bin/sys-lend.rs

-2
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,13 @@ mod dp {
5757
.tag("address", metrics::dp::pubkey_to_value(address))
5858
.tag("token", maybe_token.name())
5959
.field("amount", ui_amount)
60-
.timestamp(metrics::dp::now())
6160
}
6261

6362
pub fn supply_apy(pool: &str, maybe_token: MaybeToken, apy_bps: u64) -> metrics::Point {
6463
metrics::Point::new("sys_lend::supply_apy")
6564
.tag("pool", pool)
6665
.tag("token", maybe_token.name())
6766
.field("apy_bps", apy_bps as f64)
68-
.timestamp(metrics::dp::now())
6967
}
7068
}
7169

src/metrics.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub use influxdb_client::{Client, Point};
22
use {
3-
influxdb_client::Precision,
3+
chrono::Utc,
4+
influxdb_client::{timestamp, Precision, Timestamp, TimestampOptions},
45
serde::{Deserialize, Serialize},
56
std::{env, sync::Arc},
67
tokio::sync::RwLock,
@@ -37,11 +38,12 @@ pub async fn send(config: Option<MetricsConfig>) {
3738
.with_bucket(config.bucket)
3839
.with_precision(Precision::MS);
3940
//let client = client.insert_to_stdout();
41+
42+
// Write all metrics with the same timestamp to ensure multiple sys-lend APY and balance
43+
// values line up
44+
let timestamp = timestamp!(Utc::now().timestamp_millis());
4045
client
41-
.insert_points(
42-
&*POINTS.write().await,
43-
influxdb_client::TimestampOptions::None,
44-
)
46+
.insert_points(&*POINTS.write().await, timestamp)
4547
.await
4648
.unwrap_or_else(|err| eprintln!("Failed to send metrics: {err:?}"));
4749
}
@@ -53,25 +55,19 @@ pub mod dp {
5355
exchange::{Exchange, OrderSide},
5456
token::MaybeToken,
5557
},
56-
chrono::Utc,
57-
influxdb_client::{Point, Timestamp, Value},
58+
influxdb_client::{Point, Value},
5859
solana_sdk::pubkey::Pubkey,
5960
};
6061

6162
pub fn pubkey_to_value(p: &Pubkey) -> Value {
6263
Value::Str(p.to_string())
6364
}
6465

65-
pub fn now() -> Timestamp {
66-
Timestamp::Int(Utc::now().timestamp_millis())
67-
}
68-
6966
pub fn exchange_deposit(exchange: Exchange, maybe_token: MaybeToken, ui_amount: f64) -> Point {
7067
Point::new("exchange_deposit")
7168
.tag("exchange", exchange.to_string().as_str())
7269
.tag("token", maybe_token.name())
7370
.field("amount", ui_amount)
74-
.timestamp(now())
7571
}
7672

7773
pub fn exchange_withdrawal(
@@ -85,7 +81,6 @@ pub mod dp {
8581
.tag("token", maybe_token.name())
8682
.tag("address", pubkey_to_value(address))
8783
.field("amount", ui_amount)
88-
.timestamp(now())
8984
}
9085

9186
pub fn exchange_fill(
@@ -103,6 +98,5 @@ pub mod dp {
10398
.tag("token", maybe_token.name())
10499
.field("price", price)
105100
.field("amount", amount)
106-
.timestamp(now())
107101
}
108102
}

0 commit comments

Comments
 (0)