uses nanos precision for timestamp when submitting metrics to influxdb (#20623)
Current datapoint_info! is apparently overwriting itself when run inside a loop. For example in https://github.com/solana-labs/solana/blob/005d6863f/core/src/window_service.rs#L101-L107 only one of the slots will show up in influxdb. This is apparently because of metrics code using milliseconds as the timestamp, as mentioned here: https://github.com/solana-labs/solana/issues/19789#issuecomment-922482013
This commit is contained in:
@@ -1,20 +1,23 @@
|
||||
//! The `metrics` module enables sending measurements to an `InfluxDB` instance
|
||||
|
||||
use crate::{counter::CounterPoint, datapoint::DataPoint};
|
||||
use gethostname::gethostname;
|
||||
use lazy_static::lazy_static;
|
||||
use log::*;
|
||||
use solana_sdk::hash::hash;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
convert::Into,
|
||||
sync::{
|
||||
mpsc::{channel, Receiver, RecvTimeoutError, Sender},
|
||||
Arc, Barrier, Mutex, Once, RwLock,
|
||||
use {
|
||||
crate::{counter::CounterPoint, datapoint::DataPoint},
|
||||
gethostname::gethostname,
|
||||
lazy_static::lazy_static,
|
||||
log::*,
|
||||
solana_sdk::hash::hash,
|
||||
std::{
|
||||
cmp,
|
||||
collections::HashMap,
|
||||
convert::Into,
|
||||
env,
|
||||
sync::{
|
||||
mpsc::{channel, Receiver, RecvTimeoutError, Sender},
|
||||
Arc, Barrier, Mutex, Once, RwLock,
|
||||
},
|
||||
thread,
|
||||
time::{Duration, Instant, UNIX_EPOCH},
|
||||
},
|
||||
thread,
|
||||
time::{Duration, Instant},
|
||||
{cmp, env},
|
||||
};
|
||||
|
||||
type CounterMap = HashMap<(&'static str, u64), CounterPoint>;
|
||||
@@ -68,7 +71,7 @@ impl InfluxDbMetricsWriter {
|
||||
);
|
||||
|
||||
let write_url = format!(
|
||||
"{}/write?db={}&u={}&p={}&precision=ms",
|
||||
"{}/write?db={}&u={}&p={}&precision=n",
|
||||
&config.host, &config.db, &config.username, &config.password
|
||||
);
|
||||
|
||||
@@ -97,8 +100,9 @@ impl MetricsWriter for InfluxDbMetricsWriter {
|
||||
));
|
||||
first = false;
|
||||
}
|
||||
|
||||
line.push_str(&format!(" {}\n", &point.timestamp));
|
||||
let timestamp = point.timestamp.duration_since(UNIX_EPOCH);
|
||||
let nanos = timestamp.unwrap().as_nanos();
|
||||
line.push_str(&format!(" {}\n", nanos));
|
||||
}
|
||||
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
@@ -537,7 +541,7 @@ mod test {
|
||||
CounterPoint {
|
||||
name: "counter",
|
||||
count: 10,
|
||||
timestamp: 0,
|
||||
timestamp: UNIX_EPOCH,
|
||||
},
|
||||
Level::Info,
|
||||
0, // use the same bucket
|
||||
|
Reference in New Issue
Block a user