diff --git a/changelog.d/new_relic_override_endpoint.enhancement.md b/changelog.d/new_relic_override_endpoint.enhancement.md new file mode 100644 index 0000000000000..b125839350fae --- /dev/null +++ b/changelog.d/new_relic_override_endpoint.enhancement.md @@ -0,0 +1,3 @@ +The `new_relic` sink now supports an `override_endpoint` configuration option that allows sending data to custom New Relic API endpoints, such as staging environments. + +authors: tracyatrf diff --git a/src/sinks/new_relic/config.rs b/src/sinks/new_relic/config.rs index f0f6c1d7695a3..074001f15f51f 100644 --- a/src/sinks/new_relic/config.rs +++ b/src/sinks/new_relic/config.rs @@ -109,8 +109,18 @@ pub struct NewRelicConfig { )] acknowledgements: AcknowledgementsConfig, - #[serde(skip)] - pub override_uri: Option, + /// Override the default New Relic API endpoint. + /// + /// This is useful for sending data to a New Relic staging environment or other + /// non-production endpoints. + /// + /// When set, this URL takes precedence over the `region` and `api` settings for + /// determining the endpoint. + #[configurable(validation(format = "uri"))] + #[configurable(metadata(docs::examples = "https://staging-metric-api.newrelic.com/metric/v1"))] + #[configurable(metadata(docs::examples = "https://custom-endpoint.example.com/v1"))] + #[serde(default)] + pub override_endpoint: Option, } impl_generate_config_from_default!(NewRelicConfig); @@ -218,12 +228,17 @@ impl NewRelicCredentials { impl From<&NewRelicConfig> for NewRelicCredentials { fn from(config: &NewRelicConfig) -> Self { + let override_uri = config + .override_endpoint + .as_ref() + .map(|s| s.parse::().expect("override_endpoint should be a valid URI")); + Self { license_key: config.license_key.inner().to_string(), account_id: config.account_id.inner().to_string(), api: config.api, region: config.region.unwrap_or(NewRelicRegion::Us), - override_uri: config.override_uri.clone(), + override_uri, } } } diff --git a/src/sinks/new_relic/tests.rs b/src/sinks/new_relic/tests.rs index 55f8ef96b6341..7ee16d6681e3e 100644 --- a/src/sinks/new_relic/tests.rs +++ b/src/sinks/new_relic/tests.rs @@ -33,7 +33,7 @@ async fn sink() -> (VectorSink, Event) { toml::de::ValueDeserializer::parse(&config).expect("toml should deserialize"), ) .expect("config should be valid"); - config.override_uri = Some(mock_endpoint); + config.override_endpoint = Some(mock_endpoint.to_string()); let context = SinkContext::default(); let (sink, _healthcheck) = config.build(context).await.unwrap();