Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
4ef88f3
Add datadog section
StephenWakely Oct 18, 2023
8a1e9f1
Send global datadog options to sinks
StephenWakely Oct 19, 2023
202b87f
Fix tests
StephenWakely Oct 23, 2023
11c5deb
Added a test
StephenWakely Oct 25, 2023
ce39ea6
Update docs
StephenWakely Oct 25, 2023
6c7785f
Remove source feature
StephenWakely Oct 25, 2023
a1397bb
Merge remote-tracking branch 'origin' into stephen/dd_global
StephenWakely Oct 25, 2023
dea6fc8
Test local setting can override the global one
StephenWakely Oct 25, 2023
6ff4a8b
Spelling
StephenWakely Oct 25, 2023
cc1c656
Update docs
StephenWakely Oct 26, 2023
43767a6
Feedback from Doug
StephenWakely Oct 26, 2023
427d966
Merge remote-tracking branch 'origin' into OPW-43/dd_global
StephenWakely Oct 26, 2023
deeee6f
Allow datadog options to be specified by passing in the RootOpts
StephenWakely Oct 27, 2023
53c581b
Merge remote-tracking branch 'origin' into OPW-43/dd_global
StephenWakely Oct 27, 2023
86badbe
Pass datadog options through a new extra_context parameter
StephenWakely Nov 13, 2023
03a21df
Merge remote-tracking branch 'origin' into OPW-43/dd_global
StephenWakely Nov 13, 2023
7649fce
Fix extra context
StephenWakely Nov 15, 2023
e9df5ed
Tidy up a little
StephenWakely Nov 15, 2023
a16f9b4
Merge remote-tracking branch 'origin' into OPW-43/dd_global
StephenWakely Nov 15, 2023
552bc9d
Make Datadog options pub
StephenWakely Nov 16, 2023
db210a4
Updated licenses
StephenWakely Nov 17, 2023
c2837fe
Add anymap to spellings
StephenWakely Nov 17, 2023
994d8e7
Add to upgrade guide
StephenWakely Nov 20, 2023
b93667c
Feedback from Doug
StephenWakely Nov 20, 2023
2c4efd0
Spelling
StephenWakely Nov 20, 2023
5b42e79
Feedback from Bryce
StephenWakely Nov 21, 2023
d233c51
Component docs
StephenWakely Nov 21, 2023
f3684bb
Feedback from Bruce
StephenWakely Nov 27, 2023
a40d9bc
Use single_value in tests
StephenWakely Nov 29, 2023
8e67da9
Rename dd_common to local_dd_common
StephenWakely Nov 29, 2023
c33e900
Pass default for extra context when running as a Windows service
StephenWakely Dec 1, 2023
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
42 changes: 41 additions & 1 deletion src/config/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ use crate::{enrichment_tables::EnrichmentTables, providers::Providers, secrets::

#[cfg(feature = "api")]
use super::api;
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
use super::datadog;
#[cfg(feature = "enterprise")]
use super::enterprise;
use super::{
Expand All @@ -33,6 +39,15 @@ pub struct ConfigBuilder {
#[serde(default)]
pub api: api::Options,

#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
#[configurable(derived)]
#[serde(default)]
pub datadog: datadog::Options,

#[configurable(derived)]
#[configurable(metadata(docs::hidden))]
#[serde(default)]
Expand Down Expand Up @@ -92,6 +107,12 @@ struct ConfigBuilderHash<'a> {
#[cfg(feature = "api")]
api: &'a api::Options,
schema: &'a schema::Options,
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
datadog: &'a datadog::Options,
global: &'a GlobalOptions,
healthchecks: &'a HealthcheckOptions,
enrichment_tables: BTreeMap<&'a ComponentKey, &'a EnrichmentTableOuter>,
Expand Down Expand Up @@ -171,6 +192,12 @@ impl<'a> From<&'a ConfigBuilder> for ConfigBuilderHash<'a> {
#[cfg(feature = "api")]
api: &value.api,
schema: &value.schema,
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
datadog: &value.datadog,
global: &value.global,
healthchecks: &value.healthchecks,
enrichment_tables: value.enrichment_tables.iter().collect(),
Expand All @@ -190,6 +217,12 @@ impl From<Config> for ConfigBuilder {
global,
#[cfg(feature = "api")]
api,
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
datadog,
schema,
#[cfg(feature = "enterprise")]
enterprise,
Expand Down Expand Up @@ -220,6 +253,12 @@ impl From<Config> for ConfigBuilder {
global,
#[cfg(feature = "api")]
api,
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
datadog,
schema,
#[cfg(feature = "enterprise")]
enterprise,
Expand Down Expand Up @@ -434,6 +473,7 @@ mod tests {
// reproducible across versions.
let expected_keys = [
"api",
"datadog",
"enrichment_tables",
"global",
"healthchecks",
Expand Down Expand Up @@ -467,7 +507,7 @@ mod tests {
/// the `ConfigBuilder` has changed what it serializes, or the implementation of `serde_json` has changed.
/// If this test fails, we should ideally be able to fix so that the original hash passes!
fn version_hash_match() {
let expected_hash = "6c98bea9d9e2f3133e2d39ba04592d17f96340a9bc4c8d697b09f5af388a76bd";
let expected_hash = "2c0ee2dfb8789e09dd953316fdef8b30b10fce3e259d44ca9461cf84ff63d12d";
let builder = ConfigBuilder::default();
let mut hash_builder = ConfigBuilderHash::from(&builder);
hash_builder.version = "1.2.3".into();
Expand Down
12 changes: 12 additions & 0 deletions src/config/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<
global,
#[cfg(feature = "api")]
api,
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
datadog,
schema,
#[cfg(feature = "enterprise")]
enterprise,
Expand Down Expand Up @@ -102,6 +108,12 @@ pub fn compile(mut builder: ConfigBuilder) -> Result<(Config, Vec<String>), Vec<
#[cfg(feature = "api")]
api,
schema,
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
datadog,
#[cfg(feature = "enterprise")]
enterprise,
hash,
Expand Down
38 changes: 38 additions & 0 deletions src/config/datadog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//! Datadog global options.
//! This is used to allow settings (api_key and site) to be specified in the configuration file
//! globally which will apply to all datadog components. Each component can override the settings
//! specified here if necessary.
//!
use vector_common::sensitive_string::SensitiveString;
use vector_config::configurable_component;

use crate::common::datadog::DD_US_SITE;

/// Default settings to use for Datadog components.
#[configurable_component]
#[derive(Clone, Debug, Derivative)]
#[derivative(Default)]
#[serde(default, deny_unknown_fields)]
pub struct Options {
/// Default Datadog API key to use for Datadog components.
Comment thread
StephenWakely marked this conversation as resolved.
Outdated
#[serde(default = "default_api_key")]
#[derivative(Default(value = "default_api_key()"))]
#[configurable(metadata(docs::examples = "${DATADOG_API_KEY_ENV_VAR}"))]
#[configurable(metadata(docs::examples = "ef8d5de700e7989468166c40fc8a0ccd"))]
pub api_key: Option<SensitiveString>,

/// Default site to use for DataDog components.
Comment thread
StephenWakely marked this conversation as resolved.
Outdated
#[serde(default = "default_site")]
#[derivative(Default(value = "default_site()"))]
#[configurable(metadata(docs::examples = "us3.datadoghq.com"))]
#[configurable(metadata(docs::examples = "datadoghq.eu"))]
pub site: String,
}

fn default_api_key() -> Option<SensitiveString> {
std::env::var("DD_API_KEY").ok().map(Into::into)
}

pub fn default_site() -> String {
std::env::var("DD_SITE").unwrap_or(DD_US_SITE.to_string())
}
31 changes: 13 additions & 18 deletions src/config/enterprise.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ use url::{ParseError, Url};
use vector_core::config::proxy::ProxyConfig;

use super::{
load_source_from_paths, process_paths, ComponentKey, Config, ConfigPath, OutputId, SinkOuter,
SourceOuter, TransformOuter,
datadog::default_site, load_source_from_paths, process_paths, ComponentKey, Config, ConfigPath,
OutputId, SinkOuter, SourceOuter, TransformOuter,
};
use crate::{
common::datadog::{get_api_base_endpoint, get_base_domain_region, Region},
conditions::AnyCondition,
http::{HttpClient, HttpError},
sinks::{
datadog::{
default_site, logs::DatadogLogsConfig, metrics::DatadogMetricsConfig,
DatadogCommonConfig,
},
datadog::{logs::DatadogLogsConfig, metrics::DatadogMetricsConfig, DatadogCommonConfig},
util::{http::RequestConfig, retries::ExponentialBackoff},
},
sources::{
Expand Down Expand Up @@ -481,12 +478,11 @@ fn setup_logs_reporting(

// Create a Datadog logs sink to consume and emit internal logs.
let datadog_logs = DatadogLogsConfig {
dd_common: DatadogCommonConfig {
endpoint: datadog.endpoint.clone(),
site: datadog.site.clone(),
default_api_key: api_key.into(),
..Default::default()
},
dd_common: DatadogCommonConfig::new(
datadog.endpoint.clone(),
Some(datadog.site.clone()),
Some(api_key.into()),
),
region: datadog.region,
request: RequestConfig {
headers: IndexMap::from([(
Expand Down Expand Up @@ -589,12 +585,11 @@ fn setup_metrics_reporting(

// Create a Datadog metrics sink to consume and emit internal + host metrics.
let datadog_metrics = DatadogMetricsConfig {
dd_common: DatadogCommonConfig {
endpoint: datadog.endpoint.clone(),
site: datadog.site.clone(),
default_api_key: api_key.into(),
..Default::default()
},
dd_common: DatadogCommonConfig::new(
datadog.endpoint.clone(),
Some(datadog.site.clone()),
Some(api_key.into()),
),
region: datadog.region,
..Default::default()
};
Expand Down
12 changes: 12 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ pub mod api;
mod builder;
mod cmd;
mod compiler;
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
pub mod datadog;
mod diff;
mod enrichment_table;
#[cfg(feature = "enterprise")]
Expand Down Expand Up @@ -106,6 +112,12 @@ pub struct Config {
#[cfg(feature = "api")]
pub api: api::Options,
pub schema: schema::Options,
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
pub datadog: datadog::Options,
pub hash: Option<String>,
#[cfg(feature = "enterprise")]
pub enterprise: Option<enterprise::Options>,
Expand Down
8 changes: 8 additions & 0 deletions src/config/sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use vector_core::{
sink::VectorSink,
};

use super::datadog;
use super::{id::Inputs, schema, ComponentKey, ProxyConfig, Resource};
use crate::sinks::{util::UriSerde, Healthcheck};

Expand Down Expand Up @@ -239,6 +240,12 @@ dyn_clone::clone_trait_object!(SinkConfig);
pub struct SinkContext {
pub healthcheck: SinkHealthcheckOptions,
pub globals: GlobalOptions,
#[cfg(any(
feature = "sinks-datadog_logs",
feature = "sinks-datadog_metrics",
feature = "sinks-datadog_traces",
))]
pub datadog: datadog::Options,
pub proxy: ProxyConfig,
pub schema: schema::Options,
pub app_name: String,
Expand All @@ -250,6 +257,7 @@ impl Default for SinkContext {
Self {
healthcheck: Default::default(),
globals: Default::default(),
datadog: Default::default(),
proxy: Default::default(),
schema: Default::default(),
app_name: crate::get_app_name().to_string(),
Expand Down
24 changes: 14 additions & 10 deletions src/sinks/datadog/events/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use vrl::value::Kind;

use crate::{
common::datadog::{get_base_domain_region, Region},
config::{AcknowledgementsConfig, GenerateConfig, Input, SinkConfig, SinkContext},
config::{datadog, AcknowledgementsConfig, GenerateConfig, Input, SinkConfig, SinkContext},
http::HttpClient,
sinks::{
datadog::{
Expand Down Expand Up @@ -54,10 +54,10 @@ impl GenerateConfig for DatadogEventsConfig {
}

impl DatadogEventsConfig {
fn get_api_events_endpoint(&self) -> http::Uri {
fn get_api_events_endpoint(&self, global: &datadog::Options) -> http::Uri {
let api_base_endpoint = get_api_base_endpoint(
self.dd_common.endpoint.as_ref(),
get_base_domain_region(self.dd_common.site.as_str(), self.region.as_ref()),
get_base_domain_region(self.dd_common.site(global), self.region.as_ref()),
);

// We know this URI will be valid since we have just built it up ourselves.
Expand All @@ -70,10 +70,14 @@ impl DatadogEventsConfig {
Ok(client)
}

fn build_sink(&self, client: HttpClient) -> crate::Result<VectorSink> {
fn build_sink(
&self,
global: &datadog::Options,
client: HttpClient,
) -> crate::Result<VectorSink> {
let service = DatadogEventsService::new(
self.get_api_events_endpoint(),
self.dd_common.default_api_key.clone().into(),
self.get_api_events_endpoint(global),
self.dd_common.default_api_key(global),
client,
);

Expand All @@ -96,10 +100,10 @@ impl DatadogEventsConfig {
impl SinkConfig for DatadogEventsConfig {
async fn build(&self, cx: SinkContext) -> crate::Result<(VectorSink, Healthcheck)> {
let client = self.build_client(cx.proxy())?;
let healthcheck = self
.dd_common
.build_healthcheck(client.clone(), self.region.as_ref())?;
let sink = self.build_sink(client)?;
let healthcheck =
self.dd_common
.build_healthcheck(&cx.datadog, client.clone(), self.region.as_ref())?;
let sink = self.build_sink(&cx.datadog, client)?;

Ok((sink, healthcheck))
}
Expand Down
9 changes: 6 additions & 3 deletions src/sinks/datadog/events/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ use futures::{
use http::Request;
use hyper::Body;
use tower::{Service, ServiceExt};
use vector_common::request_metadata::{GroupedCountByteSize, MetaDescriptive};
use vector_common::{
request_metadata::{GroupedCountByteSize, MetaDescriptive},
sensitive_string::SensitiveString,
};
use vector_stream::DriverResponse;

use crate::{
Expand Down Expand Up @@ -53,15 +56,15 @@ pub struct DatadogEventsService {
impl DatadogEventsService {
pub fn new(
endpoint: http::Uri,
default_api_key: String,
default_api_key: SensitiveString,
http_client: HttpClient<Body>,
) -> Self {
let batch_http_service = HttpBatchService::new(http_client, move |req| {
let req: DatadogEventsRequest = req;

let api_key = match req.metadata.api_key.as_ref() {
Some(x) => x.as_ref(),
None => default_api_key.as_str(),
None => default_api_key.inner(),
};

let request = Request::post(&endpoint)
Expand Down
Loading