Skip to content

Commit be4df6e

Browse files
authored
Merge pull request #142 from Thaumy/main
Add OTLP export interval config
2 parents bcfcd46 + 2b6824a commit be4df6e

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

doc/config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ buf_watermark = 2048
2626
[remote.otlp]
2727
enable = false
2828
addr = "https://otel-col.optimatist.com"
29+
interval = 10

src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub struct RpcConfig {
6262
pub struct OtlpConfig {
6363
pub enable: bool,
6464
pub addr: String,
65+
/// in seconds
66+
pub interval: u64,
6567
}
6668

6769
#[derive(Deserialize)]

src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,11 @@ async fn async_tasks(remote_cfg: RemoteConfig, mut task_rt: TaskRuntime) -> Resu
173173
endpoint: Some(remote_cfg.otlp.addr),
174174
..Default::default()
175175
};
176-
let otlp = otlp::Otlp::new(remote_cfg.token, Duration::from_secs(1), export_conf)?;
176+
let otlp = otlp::Otlp::new(
177+
remote_cfg.token,
178+
Duration::from_secs(remote_cfg.otlp.interval),
179+
export_conf,
180+
)?;
177181

178182
otlp.otlp_tasks().await?;
179183
Ok::<(), Error>(())

src/otlp/mod.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct Otlp {
4444

4545
impl Otlp {
4646
pub fn new(token: String, interval: Duration, export_config: ExportConfig) -> Result<Self> {
47-
let provider = meter_provider(export_config, token.clone())?;
47+
let provider = meter_provider(export_config, token.clone(), interval)?;
4848
let meter = provider.meter("SystemProfile");
4949
Ok(Self {
5050
token,
@@ -93,7 +93,11 @@ impl Otlp {
9393
}
9494
}
9595

96-
fn meter_provider(export_config: ExportConfig, token: String) -> Result<SdkMeterProvider> {
96+
fn meter_provider(
97+
export_config: ExportConfig,
98+
token: String,
99+
interval: Duration,
100+
) -> Result<SdkMeterProvider> {
97101
let mut meta = MetadataMap::new();
98102
meta.insert("authorization", format!("Bearer {}", token).parse()?);
99103
let otlp_exporter = MetricExporter::builder()
@@ -104,7 +108,7 @@ fn meter_provider(export_config: ExportConfig, token: String) -> Result<SdkMeter
104108
.with_export_config(export_config)
105109
.build()?;
106110
let reader = PeriodicReader::builder(otlp_exporter, runtime::Tokio)
107-
.with_interval(Duration::from_secs(1))
111+
.with_interval(interval)
108112
.build();
109113

110114
let a = SdkMeterProvider::builder()

0 commit comments

Comments
 (0)