refactor(time): Introduce typed clock sources for compile-time safety

This change replaces runtime `ClockId` parameters with distinct types to ensure correct clock usage at compile time.
This commit is contained in:
Nils Andreas Svee committed 2026-09-30 12:05:42 +07:00
1 parent e27bab1944
commit 817cc304e6
6 files changed
+46 -26

No files matched your search

+3 -3
View File
@@ -4,7 +4,7 @@
use crate::settings::Settings;
use crate::settings::{MeasurementType, ObservabilityProtocol};
use crate::time::Time;
use crate::time::{ClockSample, Realtime};
use flume::{Receiver, RecvTimeoutError, Sender};
use log::{error, info, warn};
use rustix::time::ClockId;
@@ -148,7 +148,7 @@ impl MetricsSender {
pub fn send(&self, metric: Metric) {
if let Some(ref tx) = self.tx {
let ts = Time::new(ClockId::Realtime).as_nanos();
let ts = ClockSample::<Realtime>::now().as_nanos();
if tx.try_send((metric, ts)).is_err() {
self.dropped.fetch_add(1, Ordering::Relaxed);
}
@@ -197,7 +197,7 @@ impl Metrics {
Err(RecvTimeoutError::Timeout) => {
let dropped = self.metrics_dropped.swap(0, Ordering::Relaxed);
if dropped > 0 {
let ts = Time::new(ClockId::Realtime).as_nanos();
let ts = ClockSample::<Realtime>::now().as_nanos();
batch.push((Metric::Dropped { count: dropped }, ts));
}
if !batch.is_empty() {