Skip to content
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

chore(sources): Add SourceContext #4685

Closed
wants to merge 2 commits into from
Closed
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
16 changes: 16 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ pub trait SourceConfig: core::fmt::Debug + Send + Sync {
async fn build(
&self,
name: &str,
cx: SourceContext,
globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand All @@ -163,6 +164,21 @@ pub trait SourceConfig: core::fmt::Debug + Send + Sync {
fn source_type(&self) -> &'static str;
}

#[derive(Debug, Clone)]
pub struct SourceContext {
pub(super) resolver: Resolver,
}

impl SourceContext {
pub fn new_test() -> Self {
Self { resolver: Resolver }
}

pub fn resolver(&self) -> Resolver {
self.resolver
}
}

pub type SourceDescription = ComponentDescription<Box<dyn SourceConfig>>;

inventory::collect!(SourceDescription);
Expand Down
6 changes: 5 additions & 1 deletion src/sources/apache_metrics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
config::{self, GenerateConfig, GlobalOptions, SourceConfig, SourceDescription},
config::{self, GenerateConfig, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
event::metric::{Metric, MetricKind, MetricValue},
internal_events::{
ApacheMetricsErrorResponse, ApacheMetricsEventReceived, ApacheMetricsHttpError,
Expand Down Expand Up @@ -52,6 +52,7 @@ impl SourceConfig for ApacheMetricsConfig {
async fn build(
&self,
_name: &str,
_cx: SourceContext,
_globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down Expand Up @@ -326,6 +327,7 @@ Scoreboard: ____S_____I______R____I_______KK___D__C__G_L____________W___________
}
.build(
"default",
SourceContext::new_test(),
&GlobalOptions::default(),
ShutdownSignal::noop(),
tx,
Expand Down Expand Up @@ -394,6 +396,7 @@ Scoreboard: ____S_____I______R____I_______KK___D__C__G_L____________W___________
}
.build(
"default",
SourceContext::new_test(),
&GlobalOptions::default(),
ShutdownSignal::noop(),
tx,
Expand Down Expand Up @@ -435,6 +438,7 @@ Scoreboard: ____S_____I______R____I_______KK___D__C__G_L____________W___________
}
.build(
"default",
SourceContext::new_test(),
&GlobalOptions::default(),
ShutdownSignal::noop(),
tx,
Expand Down
6 changes: 5 additions & 1 deletion src/sources/aws_kinesis_firehose/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::{
config::{DataType, GenerateConfig, GlobalOptions, SourceConfig, SourceDescription},
config::{
DataType, GenerateConfig, GlobalOptions, SourceConfig, SourceContext, SourceDescription,
},
shutdown::ShutdownSignal,
tls::{MaybeTlsSettings, TlsConfig},
Pipeline,
Expand All @@ -26,6 +28,7 @@ impl SourceConfig for AwsKinesisFirehoseConfig {
async fn build(
&self,
_: &str,
_cx: SourceContext,
_: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down Expand Up @@ -93,6 +96,7 @@ mod tests {
}
.build(
"default",
SourceContext::new_test(),
&GlobalOptions::default(),
ShutdownSignal::noop(),
sender,
Expand Down
3 changes: 2 additions & 1 deletion src/sources/docker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::util::MultilineConfig;
use crate::{
config::{log_schema, DataType, GlobalOptions, SourceConfig, SourceDescription},
config::{log_schema, DataType, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
event::merge_state::LogEventMergeState,
event::{self, Event, LogEvent, Value},
internal_events::{
Expand Down Expand Up @@ -117,6 +117,7 @@ impl SourceConfig for DockerConfig {
async fn build(
&self,
_name: &str,
_cx: SourceContext,
_globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
3 changes: 2 additions & 1 deletion src/sources/file.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::util::MultilineConfig;
use crate::{
config::{log_schema, DataType, GlobalOptions, SourceConfig, SourceDescription},
config::{log_schema, DataType, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
event::Event,
internal_events::{FileEventReceived, FileSourceInternalEventsEmitter},
line_agg::{self, LineAgg},
Expand Down Expand Up @@ -150,6 +150,7 @@ impl SourceConfig for FileConfig {
async fn build(
&self,
name: &str,
_cx: SourceContext,
globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
3 changes: 2 additions & 1 deletion src/sources/generator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
config::{DataType, GlobalOptions, SourceConfig, SourceDescription},
config::{DataType, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
event::Event,
internal_events::GeneratorEventProcessed,
shutdown::ShutdownSignal,
Expand Down Expand Up @@ -51,6 +51,7 @@ impl SourceConfig for GeneratorConfig {
async fn build(
&self,
_name: &str,
_cx: SourceContext,
_globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
3 changes: 2 additions & 1 deletion src/sources/host_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
config::{DataType, GlobalOptions, SourceConfig, SourceDescription},
config::{DataType, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
event::{
metric::{Metric, MetricKind, MetricValue},
Event,
Expand Down Expand Up @@ -133,6 +133,7 @@ impl SourceConfig for HostMetricsConfig {
async fn build(
&self,
_name: &str,
_cx: SourceContext,
_globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
7 changes: 5 additions & 2 deletions src/sources/http.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
config::{
log_schema, DataType, GenerateConfig, GlobalOptions, SourceConfig, SourceDescription,
log_schema, DataType, GenerateConfig, GlobalOptions, SourceConfig, SourceContext,
SourceDescription,
},
event::{Event, Value},
shutdown::ShutdownSignal,
Expand Down Expand Up @@ -72,6 +73,7 @@ impl SourceConfig for SimpleHttpConfig {
async fn build(
&self,
_: &str,
_cx: SourceContext,
_: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down Expand Up @@ -211,7 +213,7 @@ mod tests {

use crate::shutdown::ShutdownSignal;
use crate::{
config::{log_schema, GlobalOptions, SourceConfig},
config::{log_schema, GlobalOptions, SourceConfig, SourceContext},
event::{Event, Value},
test_util::{collect_n, next_addr, trace_init, wait_for_tcp},
Pipeline,
Expand Down Expand Up @@ -239,6 +241,7 @@ mod tests {
}
.build(
"default",
SourceContext::new_test(),
&GlobalOptions::default(),
ShutdownSignal::noop(),
sender,
Expand Down
3 changes: 2 additions & 1 deletion src/sources/internal_metrics.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
config::{DataType, GlobalOptions, SourceConfig, SourceDescription},
config::{DataType, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
metrics::Controller,
metrics::{capture_metrics, get_controller},
shutdown::ShutdownSignal,
Expand Down Expand Up @@ -30,6 +30,7 @@ impl SourceConfig for InternalMetricsConfig {
async fn build(
&self,
_name: &str,
_cx: SourceContext,
_globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
3 changes: 2 additions & 1 deletion src/sources/journald.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
config::{log_schema, DataType, GlobalOptions, SourceConfig, SourceDescription},
config::{log_schema, DataType, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
event::{Event, LogEvent, Value},
internal_events::{JournaldEventReceived, JournaldInvalidRecord},
shutdown::ShutdownSignal,
Expand Down Expand Up @@ -90,6 +90,7 @@ impl SourceConfig for JournaldConfig {
async fn build(
&self,
name: &str,
_cx: SourceContext,
globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
3 changes: 2 additions & 1 deletion src/sources/kafka.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
config::{log_schema, DataType, GlobalOptions, SourceConfig, SourceDescription},
config::{log_schema, DataType, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
event::{Event, Value},
internal_events::{KafkaEventFailed, KafkaEventReceived, KafkaOffsetUpdateFailed},
kafka::KafkaAuthConfig,
Expand Down Expand Up @@ -84,6 +84,7 @@ impl SourceConfig for KafkaSourceConfig {
async fn build(
&self,
_name: &str,
_cx: SourceContext,
_globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
5 changes: 4 additions & 1 deletion src/sources/kubernetes_logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use crate::internal_events::{
};
use crate::kubernetes as k8s;
use crate::{
config::{DataType, GenerateConfig, GlobalOptions, SourceConfig, SourceDescription},
config::{
DataType, GenerateConfig, GlobalOptions, SourceConfig, SourceContext, SourceDescription,
},
dns::Resolver,
shutdown::ShutdownSignal,
sources,
Expand Down Expand Up @@ -98,6 +100,7 @@ impl SourceConfig for Config {
async fn build(
&self,
name: &str,
_cx: SourceContext,
globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
7 changes: 5 additions & 2 deletions src/sources/logplex.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::{
config::{
log_schema, DataType, GenerateConfig, GlobalOptions, SourceConfig, SourceDescription,
log_schema, DataType, GenerateConfig, GlobalOptions, SourceConfig, SourceContext,
SourceDescription,
},
event::Event,
internal_events::{HerokuLogplexRequestReadError, HerokuLogplexRequestReceived},
Expand Down Expand Up @@ -48,6 +49,7 @@ impl SourceConfig for LogplexConfig {
async fn build(
&self,
_: &str,
_cx: SourceContext,
_: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down Expand Up @@ -173,7 +175,7 @@ mod tests {
use super::{HttpSourceAuthConfig, LogplexConfig};
use crate::shutdown::ShutdownSignal;
use crate::{
config::{log_schema, GlobalOptions, SourceConfig},
config::{log_schema, GlobalOptions, SourceConfig, SourceContext},
event::Event,
test_util::{collect_n, next_addr, trace_init, wait_for_tcp},
Pipeline,
Expand All @@ -195,6 +197,7 @@ mod tests {
}
.build(
"default",
SourceContext::new_test(),
&GlobalOptions::default(),
ShutdownSignal::noop(),
sender,
Expand Down
3 changes: 2 additions & 1 deletion src/sources/mongodb_metrics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
config::{self, GlobalOptions, SourceConfig, SourceDescription},
config::{self, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
event::metric::{Metric, MetricKind, MetricValue},
internal_events::{
MongoDBMetricsBsonParseError, MongoDBMetricsCollectCompleted, MongoDBMetricsRequestError,
Expand Down Expand Up @@ -122,6 +122,7 @@ impl SourceConfig for MongoDBMetricsConfig {
async fn build(
&self,
_name: &str,
_cx: SourceContext,
_globals: &GlobalOptions,
mut shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
3 changes: 2 additions & 1 deletion src/sources/prometheus/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
config::{self, GenerateConfig, GlobalOptions, SourceConfig, SourceDescription},
config::{self, GenerateConfig, GlobalOptions, SourceConfig, SourceContext, SourceDescription},
internal_events::{
PrometheusErrorResponse, PrometheusEventReceived, PrometheusHttpError,
PrometheusParseError, PrometheusRequestCompleted,
Expand Down Expand Up @@ -42,6 +42,7 @@ impl SourceConfig for PrometheusConfig {
async fn build(
&self,
_name: &str,
_cx: SourceContext,
_globals: &GlobalOptions,
shutdown: ShutdownSignal,
out: Pipeline,
Expand Down
Loading