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:
parent
aec9d8bf2f
commit
cd87525f54
|
@ -1,8 +1,13 @@
|
||||||
use crate::metrics::submit_counter;
|
use {
|
||||||
use log::*;
|
crate::metrics::submit_counter,
|
||||||
use solana_sdk::timing;
|
log::*,
|
||||||
use std::env;
|
solana_sdk::timing,
|
||||||
use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
|
std::{
|
||||||
|
env,
|
||||||
|
sync::atomic::{AtomicU64, AtomicUsize, Ordering},
|
||||||
|
time::SystemTime,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const DEFAULT_LOG_RATE: usize = 1000;
|
const DEFAULT_LOG_RATE: usize = 1000;
|
||||||
// Submit a datapoint every second by default
|
// Submit a datapoint every second by default
|
||||||
|
@ -23,7 +28,7 @@ pub struct Counter {
|
||||||
pub struct CounterPoint {
|
pub struct CounterPoint {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub count: i64,
|
pub count: i64,
|
||||||
pub timestamp: u64,
|
pub timestamp: SystemTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CounterPoint {
|
impl CounterPoint {
|
||||||
|
@ -32,7 +37,7 @@ impl CounterPoint {
|
||||||
CounterPoint {
|
CounterPoint {
|
||||||
name,
|
name,
|
||||||
count: 0,
|
count: 0,
|
||||||
timestamp: 0,
|
timestamp: std::time::UNIX_EPOCH,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,7 +203,7 @@ impl Counter {
|
||||||
let counter = CounterPoint {
|
let counter = CounterPoint {
|
||||||
name: self.name,
|
name: self.name,
|
||||||
count: counts as i64 - lastlog as i64,
|
count: counts as i64 - lastlog as i64,
|
||||||
timestamp: now,
|
timestamp: SystemTime::now(),
|
||||||
};
|
};
|
||||||
submit_counter(counter, level, bucket);
|
submit_counter(counter, level, bucket);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use std::fmt;
|
use std::{fmt, time::SystemTime};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct DataPoint {
|
pub struct DataPoint {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub timestamp: u64,
|
pub timestamp: SystemTime,
|
||||||
pub fields: Vec<(&'static str, String)>,
|
pub fields: Vec<(&'static str, String)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ impl DataPoint {
|
||||||
pub fn new(name: &'static str) -> Self {
|
pub fn new(name: &'static str) -> Self {
|
||||||
DataPoint {
|
DataPoint {
|
||||||
name,
|
name,
|
||||||
timestamp: solana_sdk::timing::timestamp(),
|
timestamp: SystemTime::now(),
|
||||||
fields: vec![],
|
fields: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
//! The `metrics` module enables sending measurements to an `InfluxDB` instance
|
//! The `metrics` module enables sending measurements to an `InfluxDB` instance
|
||||||
|
|
||||||
use crate::{counter::CounterPoint, datapoint::DataPoint};
|
use {
|
||||||
use gethostname::gethostname;
|
crate::{counter::CounterPoint, datapoint::DataPoint},
|
||||||
use lazy_static::lazy_static;
|
gethostname::gethostname,
|
||||||
use log::*;
|
lazy_static::lazy_static,
|
||||||
use solana_sdk::hash::hash;
|
log::*,
|
||||||
use std::{
|
solana_sdk::hash::hash,
|
||||||
|
std::{
|
||||||
|
cmp,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
convert::Into,
|
convert::Into,
|
||||||
|
env,
|
||||||
sync::{
|
sync::{
|
||||||
mpsc::{channel, Receiver, RecvTimeoutError, Sender},
|
mpsc::{channel, Receiver, RecvTimeoutError, Sender},
|
||||||
Arc, Barrier, Mutex, Once, RwLock,
|
Arc, Barrier, Mutex, Once, RwLock,
|
||||||
},
|
},
|
||||||
thread,
|
thread,
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant, UNIX_EPOCH},
|
||||||
{cmp, env},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
type CounterMap = HashMap<(&'static str, u64), CounterPoint>;
|
type CounterMap = HashMap<(&'static str, u64), CounterPoint>;
|
||||||
|
@ -68,7 +71,7 @@ impl InfluxDbMetricsWriter {
|
||||||
);
|
);
|
||||||
|
|
||||||
let write_url = format!(
|
let write_url = format!(
|
||||||
"{}/write?db={}&u={}&p={}&precision=ms",
|
"{}/write?db={}&u={}&p={}&precision=n",
|
||||||
&config.host, &config.db, &config.username, &config.password
|
&config.host, &config.db, &config.username, &config.password
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -97,8 +100,9 @@ impl MetricsWriter for InfluxDbMetricsWriter {
|
||||||
));
|
));
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
let timestamp = point.timestamp.duration_since(UNIX_EPOCH);
|
||||||
line.push_str(&format!(" {}\n", &point.timestamp));
|
let nanos = timestamp.unwrap().as_nanos();
|
||||||
|
line.push_str(&format!(" {}\n", nanos));
|
||||||
}
|
}
|
||||||
|
|
||||||
let client = reqwest::blocking::Client::builder()
|
let client = reqwest::blocking::Client::builder()
|
||||||
|
@ -537,7 +541,7 @@ mod test {
|
||||||
CounterPoint {
|
CounterPoint {
|
||||||
name: "counter",
|
name: "counter",
|
||||||
count: 10,
|
count: 10,
|
||||||
timestamp: 0,
|
timestamp: UNIX_EPOCH,
|
||||||
},
|
},
|
||||||
Level::Info,
|
Level::Info,
|
||||||
0, // use the same bucket
|
0, // use the same bucket
|
||||||
|
|
Loading…
Reference in New Issue