diff --git a/CHANGELOG.md b/CHANGELOG.md index 593dbd6..c898af7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.5.0] - TBD +- Upgrade to Telemetry SDK 0.6.1 +- Allow URI override to include or omit the full endpoint path component. + ## [0.4.0] - 2020-04-01 - Contributed: `NewRelicReporterFactory` by [Steven Schwell](https://github.com/sschwell) - Changed: update dropwizard-core version to 4.1.5 diff --git a/build.gradle.kts b/build.gradle.kts index 408233b..8068663 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -33,9 +33,9 @@ googleJavaFormat { dependencies { api("io.dropwizard.metrics:metrics-core:4.1.5") - api("com.newrelic.telemetry:telemetry:0.4.0") + api("com.newrelic.telemetry:telemetry:0.6.1") implementation("io.dropwizard:dropwizard-metrics:2.0.5") - implementation("com.newrelic.telemetry:telemetry-http-okhttp:0.4.0") + implementation("com.newrelic.telemetry:telemetry-http-okhttp:0.6.1") testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.4.2") testRuntimeOnly("org.slf4j:slf4j-simple:1.7.26") diff --git a/gradle.properties b/gradle.properties index 28198dc..b058dc9 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -releaseVersion = 0.4.1-SNAPSHOT +releaseVersion = 0.5.0-SNAPSHOT # set this to true to enable using a local sonatype (for debugging publishing issues) # (start a local sonatype in docker with this command: $ docker run -d -p 8081:8081 --name nexus sonatype/nexus3) diff --git a/src/main/java/com/codahale/metrics/newrelic/NewRelicReporterBuilder.java b/src/main/java/com/codahale/metrics/newrelic/NewRelicReporterBuilder.java index 7582dad..20e94f1 100644 --- a/src/main/java/com/codahale/metrics/newrelic/NewRelicReporterBuilder.java +++ b/src/main/java/com/codahale/metrics/newrelic/NewRelicReporterBuilder.java @@ -99,7 +99,7 @@ public NewRelicReporter build() { filter, rateUnit, durationUnit, - new TelemetryClient(metricBatchSender, null), + new TelemetryClient(metricBatchSender, null, null, null), commonAttributes, histogramTransformer, gaugeTransformer, diff --git a/src/main/java/com/codahale/metrics/newrelic/NewRelicReporterFactory.java b/src/main/java/com/codahale/metrics/newrelic/NewRelicReporterFactory.java index 1a93168..fcacfc6 100644 --- a/src/main/java/com/codahale/metrics/newrelic/NewRelicReporterFactory.java +++ b/src/main/java/com/codahale/metrics/newrelic/NewRelicReporterFactory.java @@ -6,8 +6,10 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonTypeName; import com.newrelic.telemetry.Attributes; -import com.newrelic.telemetry.SimpleMetricBatchSender; -import com.newrelic.telemetry.metrics.MetricBatchSenderBuilder; +import com.newrelic.telemetry.MetricBatchSenderFactory; +import com.newrelic.telemetry.OkHttpPoster; +import com.newrelic.telemetry.SenderConfiguration; +import com.newrelic.telemetry.metrics.MetricBatchSender; import io.dropwizard.metrics.BaseReporterFactory; import java.net.MalformedURLException; import java.net.URI; @@ -30,15 +32,12 @@ public class NewRelicReporterFactory extends BaseReporterFactory { @Override @NotNull public ScheduledReporter build(final MetricRegistry registry) { - final MetricBatchSenderBuilder metricBatchSender = SimpleMetricBatchSender.builder(apiKey); - if (overrideUri != null) { - final URI uri = URI.create(overrideUri); - try { - metricBatchSender.uriOverride(uri); - } catch (MalformedURLException t) { - throw new IllegalArgumentException(t.getMessage(), t); - } - } + MetricBatchSenderFactory factory = + MetricBatchSenderFactory.fromHttpImplementation(OkHttpPoster::new); + + SenderConfiguration.SenderConfigurationBuilder config = factory.configureWith(apiKey); + config = configureEndpoint(config); + final Attributes attributes = new Attributes(); if (commonAttributes != null) { for (final Map.Entry entry : commonAttributes.entrySet()) { @@ -50,7 +49,8 @@ else if (entry.getValue() instanceof Boolean) attributes.put(entry.getKey(), (Boolean) entry.getValue()); } } - return NewRelicReporterBuilder.forRegistry(registry, metricBatchSender.build()) + MetricBatchSender metricBatchSender = MetricBatchSender.create(config.build()); + return NewRelicReporterBuilder.forRegistry(registry, metricBatchSender) .durationUnit(getDurationUnit()) .rateUnit(getRateUnit()) .filter(getFilter()) @@ -58,4 +58,21 @@ else if (entry.getValue() instanceof Boolean) .disabledMetricAttributes(disabledMetricAttributes) .build(); } + + private SenderConfiguration.SenderConfigurationBuilder configureEndpoint( + SenderConfiguration.SenderConfigurationBuilder config) { + if (overrideUri == null) { + return config; + } + final URI uri = URI.create(overrideUri); + try { + String path = uri.getPath(); + if (path == null || path.isEmpty()) { + return config.endpoint(uri.getScheme(), uri.getHost(), uri.getPort()); + } + return config.endpointWithPath(uri.toURL()); + } catch (MalformedURLException t) { + throw new IllegalArgumentException(t.getMessage(), t); + } + } }