Skip to content
Open
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
3 changes: 3 additions & 0 deletions changelog.d/new_relic_override_endpoint.enhancement.md
Original file line number Diff line number Diff line change
@@ -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
21 changes: 18 additions & 3 deletions src/sinks/new_relic/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,18 @@ pub struct NewRelicConfig {
)]
acknowledgements: AcknowledgementsConfig,

#[serde(skip)]
pub override_uri: Option<Uri>,
/// 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<String>,
}

impl_generate_config_from_default!(NewRelicConfig);
Expand Down Expand Up @@ -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::<Uri>().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,
}
}
}
2 changes: 1 addition & 1 deletion src/sinks/new_relic/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading