Map connection and read timeouts for New Relic again

Closes gh-21440
pull/21581/head
Stephane Nicoll 5 years ago
parent 53bf65df47
commit 069c31a074

@ -17,12 +17,14 @@
package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic; package org.springframework.boot.actuate.autoconfigure.metrics.export.newrelic;
import io.micrometer.core.instrument.Clock; import io.micrometer.core.instrument.Clock;
import io.micrometer.core.ipc.http.HttpUrlConnectionSender;
import io.micrometer.newrelic.ClientProviderType;
import io.micrometer.newrelic.NewRelicClientProvider; import io.micrometer.newrelic.NewRelicClientProvider;
import io.micrometer.newrelic.NewRelicConfig; import io.micrometer.newrelic.NewRelicConfig;
import io.micrometer.newrelic.NewRelicInsightsAgentClientProvider;
import io.micrometer.newrelic.NewRelicInsightsApiClientProvider;
import io.micrometer.newrelic.NewRelicMeterRegistry; import io.micrometer.newrelic.NewRelicMeterRegistry;
import io.micrometer.newrelic.NewRelicMeterRegistry.Builder;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.CompositeMeterRegistryAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration; import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
@ -67,13 +69,23 @@ public class NewRelicMetricsExportAutoConfiguration {
return new NewRelicPropertiesConfigAdapter(this.properties); return new NewRelicPropertiesConfigAdapter(this.properties);
} }
@Bean
@ConditionalOnMissingBean
public NewRelicClientProvider newRelicClientProvider(NewRelicConfig newRelicConfig) {
if (newRelicConfig.clientProviderType() == ClientProviderType.INSIGHTS_AGENT) {
return new NewRelicInsightsAgentClientProvider(newRelicConfig);
}
return new NewRelicInsightsApiClientProvider(newRelicConfig,
new HttpUrlConnectionSender(this.properties.getConnectTimeout(), this.properties.getReadTimeout()));
}
@Bean @Bean
@ConditionalOnMissingBean @ConditionalOnMissingBean
public NewRelicMeterRegistry newRelicMeterRegistry(NewRelicConfig newRelicConfig, Clock clock, public NewRelicMeterRegistry newRelicMeterRegistry(NewRelicConfig newRelicConfig, Clock clock,
ObjectProvider<NewRelicClientProvider> newRelicClientProvider) { NewRelicClientProvider newRelicClientProvider) {
Builder builder = NewRelicMeterRegistry.builder(newRelicConfig).clock(clock); return NewRelicMeterRegistry.builder(newRelicConfig).clock(clock).clientProvider(newRelicClientProvider)
newRelicClientProvider.ifUnique(builder::clientProvider); .build();
return builder.build();
} }
} }

Loading…
Cancel
Save