8000 Move exporter config loading out of agent by mheffner · Pull Request #130 · streamfold/rotel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Move exporter config loading out of agent #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 7 additions & 36 deletions src/exporters/blackhole.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
// SPDX-License-Identifier: Apache-2.0

use crate::bounded_channel::BoundedReceiver;
use opentelemetry_proto::tonic::logs::v1::ResourceLogs;
use opentelemetry_proto::tonic::metrics::v1::ResourceMetrics;
use opentelemetry_proto::tonic::trace::v1::ResourceSpans;
use tokio::select;
use tokio_util::sync::CancellationToken;
use tracing::debug;

pub struct BlackholeExporter {
traces_rx: BoundedReceiver<Vec<ResourceSpans>>,
metrics_rx: BoundedReceiver<Vec<ResourceMetrics>>,
logs_rx: BoundedReceiver<Vec<ResourceLogs>>,
pub struct BlackholeExporter<Resource> {
rx: BoundedReceiver<Vec<Resource>>,
}

impl BlackholeExporter {
pub fn new(
traces_rx: BoundedReceiver<Vec<ResourceSpans>>,
metrics_rx: BoundedReceiver<Vec<ResourceMetrics>>,
logs_rx: BoundedReceiver<Vec<ResourceLogs>>,
) -> Self {
BlackholeExporter {
traces_rx,
metrics_rx,
logs_rx,
}
impl<Resource> BlackholeExporter<Resource> {
pub fn new(rx: BoundedReceiver<Vec<Resource>>) -> Self {
BlackholeExporter { rx }
}

pub async fn start(&mut self, cancel_token: CancellationToken) {
loop {
select! {
m = self.traces_rx.next() => if m.is_none() { break },
m = self.metrics_rx.next() => if m.is_none() { break },
m = self.logs_rx.next() => if m.is_none() { break },
m = self.rx.next() => if m.is_none() { break },
_ = cancel_token.cancelled() => break,
}
}
Expand All @@ -51,10 +36,8 @@ mod tests {
#[tokio::test]
async fn send_request() {
let (tr_tx, tr_rx) = bounded(1);
let (met_tx, met_rx) = bounded(1);
let (logs_tx, logs_rx) = bounded(1);

let mut exp = BlackholeExporter::new(tr_rx, met_rx, logs_rx);
let mut exp = BlackholeExporter::new(tr_rx);

let cancel_token = CancellationToken::new();
let shut_token = cancel_token.clone();
Expand All @@ -65,18 +48,6 @@ mod tests {
.await;
assert!(&res.is_ok());

let res = met_tx
.send(From::from(
FakeOTLP::metrics_service_request().resource_metrics,
))
.await;
assert!(&res.is_ok());

let res = logs_tx
.send(From::from(FakeOTLP::logs_service_request().resource_logs))
.await;
assert!(&res.is_ok());

cancel_token.cancel();
let _ = join!(jh);
}
Expand Down
4 changes: 2 additions & 2 deletions src/exporters/clickhouse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub enum Compression {
Lz4,
}

#[derive(Default)]
#[derive(Clone, Default)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for the Clone, just a config builder but wasn't sure if that slipped in on accident?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because we now need to duplicate the config for each of the metrics, traces and logs pipelines. Before we'd just initialize the exporters from the shared config. Cloning happens here:

rotel/src/init/config.rs

Lines 133 to 136 in e6aca68

cfg.traces = Some(ExporterConfig::Clickhouse(cfg_builder.clone()));
cfg.metrics = Some(ExporterConfig::Clickhouse(cfg_builder.clone()));
cfg.logs = Some(ExporterConfig::Clickhouse(cfg_builder));

pub struct ClickhouseExporterConfigBuilder {
retry_config: RetryConfig,
compression: Compression,
Expand All @@ -72,7 +72,7 @@ pub struct ClickhouseExporterConfigBuilder {
type SvcType =
TowerRetry<RetryPolicy<()>, Timeout<HttpClient<ClickhousePayload, (), ClickhouseRespDecoder>>>;

type ExporterType<'a, Resource> = Exporter<
pub type ExporterType<'a, Resource> = Exporter<
RequestIterator<
RequestBuilderMapper<
RecvStream<'a, Vec<Resource>>,
Expand Down
33 changes: 28 additions & 5 deletions src/exporters/datadog/mod.rs
8000
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Region {
}
}

pub struct DatadogTraceExporterBuilder {
pub struct DatadogExporterConfigBuilder {
region: Region,
custom_endpoint: Option<String>,
api_token: String,
Expand All @@ -80,7 +80,16 @@ pub struct DatadogTraceExporterBuilder {
retry_config: RetryConfig,
}

impl Default for DatadogTraceExporterBuilder {
pub struct DatadogExporterBuilder {
region: Region,
custom_endpoint: Option<String>,
api_token: String,
environment: String,
hostname: String,
retry_config: RetryConfig,
}

impl Default for DatadogExporterConfigBuilder {
fn default() -> Self {
Self {
region: Region::US1,
Expand All @@ -93,7 +102,7 @@ impl Default for DatadogTraceExporterBuilder {
}
}

impl DatadogTraceExporterBuilder {
impl DatadogExporterConfigBuilder {
pub fn new(region: Region, custom_endpoint: Option<String>, api_key: String) -> Self {
Self {
region,
Expand All @@ -119,6 +128,19 @@ impl DatadogTraceExporterBuilder {
self
}

pub fn build(self) -> DatadogExporterBuilder {
DatadogExporterBuilder {
region: self.region,
custom_endpoint: self.custom_endpoint,
api_token: self.api_token,
environment: self.environment,
hostname: self.hostname,
retry_config: self.retry_config,
}
}
}

impl DatadogExporterBuilder {
pub fn build<'a>(
self,
rx: BoundedReceiver<Vec<ResourceSpans>>,
Expand Down Expand Up @@ -168,7 +190,7 @@ mod tests {

use crate::bounded_channel::{BoundedReceiver, bounded};
use crate::exporters::crypto_init_tests::init_crypto;
use crate::exporters::datadog::{DatadogTraceExporterBuilder, ExporterType, Region};
use crate::exporters::datadog::{DatadogExporterConfigBuilder, ExporterType, Region};
use crate::exporters::http::retry::RetryConfig;
use httpmock::prelude::*;
use opentelemetry_proto::tonic::trace::v1::ResourceSpans;
Expand Down Expand Up @@ -238,12 +260,13 @@ mod tests {
addr: String,
brx: BoundedReceiver<Vec<ResourceSpans>>,
) -> ExporterType<'a, ResourceSpans> {
DatadogTraceExporterBuilder::new(Region::US1, Some(addr), "1234".to_string())
DatadogExporterConfigBuilder::new(Region::US1, Some(addr), "1234".to_string())
.with_retry_config(RetryConfig {
initial_backoff: Duration::from_millis(10),
max_backoff: Duration::from_millis(50),
max_elapsed_time: Duration::from_millis(50),
})
.build()
.build(brx, None)
.unwrap()
}
Expand Down
2 changes: 1 addition & 1 deletion src/exporters/otlp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub(crate) mod errors;
mod client;
mod grpc_codec;
mod http_codec;
mod signer;
pub mod signer;

use crate::exporters::otlp::config::OTLPExporterConfig;
use clap::ValueEnum;
Expand Down
27 changes: 22 additions & 5 deletions src/exporters/xray/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ impl From<String> for Region {
}
}

pub struct XRayTraceExporterBuilder {
pub struct XRayExporterConfigBuilder {
region: Region,
custom_endpoint: Option<String>,
retry_config: RetryConfig,
}

impl Default for XRayTraceExporterBuilder {
impl Default for XRayExporterConfigBuilder {
fn default() -> Self {
Self {
region: Region::UsEast1,
Expand All @@ -181,7 +181,7 @@ impl Default for XRayTraceExporterBuilder {
}
}

impl XRayTraceExporterBuilder {
impl XRayExporterConfigBuilder {
pub fn new(region: Region, custom_endpoint: Option<String>) -> Self {
Self {
region,
Expand All @@ -196,6 +196,22 @@ impl XRayTraceExporterBuilder {
self
}

pub fn build(self) -> XRayExporterBuilder {
XRayExporterBuilder {
region: self.region,
custom_endpoint: self.custom_endpoint,
retry_config: self.retry_config,
}
}
}

pub struct XRayExporterBuilder {
region: Region,
custom_endpoint: Option<String>,
retry_config: RetryConfig,
}

impl XRayExporterBuilder {
pub fn build<'a>(
self,
rx: BoundedReceiver<Vec<ResourceSpans>>,
Expand Down Expand Up @@ -273,7 +289,7 @@ mod tests {
use crate::bounded_channel::{BoundedReceiver, bounded};
use crate::exporters::crypto_init_tests::init_crypto;
use crate::exporters::http::retry::RetryConfig;
use crate::exporters::xray::{ExporterType, Region, XRayTraceExporterBuilder};
use crate::exporters::xray::{ExporterType, Region, XRayExporterConfigBuilder};
use httpmock::prelude::*;
use opentelemetry_proto::tonic::trace::v1::ResourceSpans;
use std::time::Duration;
Expand Down Expand Up @@ -345,12 +361,13 @@ mod tests {
brx: BoundedReceiver<Vec<ResourceSpans>>,
config: AwsConfig,
) -> ExporterType<'a, ResourceSpans> {
XRayTraceExporterBuilder::new(Region::UsEast1, Some(addr))
XRayExporterConfigBuilder::new(Region::UsEast1, Some(addr))
.with_retry_config(RetryConfig {
initial_backoff: Duration::from_millis(10),
max_backoff: Duration::from_millis(50),
max_elapsed_time: Duration::from_millis(50),
})
.build()
.build(brx, None, "production".to_string(), config)
.unwrap()
}
Expand Down
Loading
0