Skip to content

Commit c63c08a

Browse files
committed
tests(telemetry): flush metrics with heartbeats if the interval is small
# Motivation Tests usually set the telemetry hearbeat interval to a small value to not have to wait to get data. For these tests also want to get telemetry metrics fast. This PR changes the metics flush interval to the heartbeat value if the hearbeat interval is set to a shorter duration than the default metrics flush interval.
1 parent 13970ff commit c63c08a

File tree

1 file changed

+9
-7
lines changed
  • libdd-telemetry/src/worker

1 file changed

+9
-7
lines changed

libdd-telemetry/src/worker/mod.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use crate::{
1313
use libdd_common::Endpoint;
1414
use libdd_common::{hyper_migration, tag::Tag, worker::Worker};
1515

16-
use std::fmt::Debug;
1716
use std::iter::Sum;
1817
use std::ops::Add;
1918
use std::{
@@ -26,6 +25,7 @@ use std::{
2625
},
2726
time,
2827
};
28+
use std::{fmt::Debug, time::Duration};
2929

3030
use crate::metrics::MetricBucketStats;
3131
use futures::{
@@ -135,6 +135,7 @@ pub struct TelemetryWorker {
135135
seq_id: AtomicU64,
136136
runtime_id: String,
137137
client: Box<dyn http_client::HttpClient + Sync + Send>,
138+
metrics_flush_interval: Duration,
138139
deadlines: scheduler::Scheduler<LifecycleAction>,
139140
data: TelemetryWorkerData,
140141
}
@@ -595,7 +596,7 @@ impl TelemetryWorker {
595596
},
596597
common: context.common,
597598
_type: context.metric_type,
598-
interval: MetricBuckets::METRICS_FLUSH_INTERVAL.as_secs(),
599+
interval: self.metrics_flush_interval.as_secs(),
599600
});
600601
}
601602
data::Distributions { series }
@@ -619,7 +620,7 @@ impl TelemetryWorker {
619620
points,
620621
common: context.common,
621622
_type: context.metric_type,
622-
interval: MetricBuckets::METRICS_FLUSH_INTERVAL.as_secs(),
623+
interval: self.metrics_flush_interval.as_secs(),
623624
});
624625
}
625626

@@ -1087,6 +1088,9 @@ impl TelemetryWorkerBuilder {
10871088
let telemetry_heartbeat_interval = config.telemetry_heartbeat_interval;
10881089
let client = http_client::from_config(&config);
10891090

1091+
let metrics_flush_interval =
1092+
telemetry_heartbeat_interval.min(MetricBuckets::METRICS_FLUSH_INTERVAL);
1093+
10901094
#[allow(clippy::unwrap_used)]
10911095
let worker = TelemetryWorker {
10921096
flavor: self.flavor,
@@ -1108,11 +1112,9 @@ impl TelemetryWorkerBuilder {
11081112
.runtime_id
11091113
.unwrap_or_else(|| uuid::Uuid::new_v4().to_string()),
11101114
client,
1115+
metrics_flush_interval,
11111116
deadlines: scheduler::Scheduler::new(vec![
1112-
(
1113-
MetricBuckets::METRICS_FLUSH_INTERVAL,
1114-
LifecycleAction::FlushMetricAggr,
1115-
),
1117+
(metrics_flush_interval, LifecycleAction::FlushMetricAggr),
11161118
(telemetry_heartbeat_interval, LifecycleAction::FlushData),
11171119
(
11181120
time::Duration::from_secs(60 * 60 * 24),

0 commit comments

Comments
 (0)