Skip to content

Commit 2c6a950

Browse files
neiljpowellshakuzen
authored andcommitted
New Relic Micrometer Spring Legacy Updates
Updates for New Relic properties added in Micrometer v1.3.0 related to micrometer-metrics#1588<micrometer-metrics#1588>
1 parent c1c6110 commit 2c6a950

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicProperties.java

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,26 @@
2222
* {@link ConfigurationProperties} for configuring New Relic metrics export.
2323
*
2424
* @author Jon Schneider
25+
* @author Neil Powell
2526
* @since 1.0.0
2627
*/
2728
@ConfigurationProperties(prefix = "management.metrics.export.newrelic")
2829
public class NewRelicProperties extends StepRegistryProperties {
2930

31+
/**
32+
* Whether to send the meter name as the event type instead of using the 'event-type'
33+
* configuration property value. Can be set to 'true' if New Relic guidelines are not
34+
* being followed or event types consistent with previous Spring Boot releases are
35+
* required.
36+
*/
37+
private boolean meterNameEventTypeEnabled;
38+
39+
/**
40+
* The event type that should be published. This property will be ignored if
41+
* 'meter-name-event-type-enabled' is set to 'true'.
42+
*/
43+
private String eventType = "SpringBootSample";
44+
3045
/**
3146
* New Relic API key.
3247
*/
@@ -42,6 +57,22 @@ public class NewRelicProperties extends StepRegistryProperties {
4257
*/
4358
private String uri = "https://insights-collector.newrelic.com";
4459

60+
public boolean isMeterNameEventTypeEnabled() {
61+
return this.meterNameEventTypeEnabled;
62+
}
63+
64+
public void setMeterNameEventTypeEnabled(boolean meterNameEventTypeEnabled) {
65+
this.meterNameEventTypeEnabled = meterNameEventTypeEnabled;
66+
}
67+
68+
public String getEventType() {
69+
return this.eventType;
70+
}
71+
72+
public void setEventType(String eventType) {
73+
this.eventType = eventType;
74+
}
75+
4576
public String getApiKey() {
4677
return this.apiKey;
4778
}
@@ -65,5 +96,4 @@ public String getUri() {
6596
public void setUri(String uri) {
6697
this.uri = uri;
6798
}
68-
6999
}

micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicPropertiesConfigAdapter.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* Adapter to convert {@link NewRelicProperties} to a {@link NewRelicConfig}.
2323
*
2424
* @author Jon Schneider
25+
* @author Neil Powell
2526
*/
2627
class NewRelicPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter<NewRelicProperties>
2728
implements NewRelicConfig {
@@ -30,6 +31,16 @@ class NewRelicPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapte
3031
super(properties);
3132
}
3233

34+
@Override
35+
public boolean meterNameEventTypeEnabled() {
36+
return get(NewRelicProperties::isMeterNameEventTypeEnabled, NewRelicConfig.super::meterNameEventTypeEnabled);
37+
}
38+
39+
@Override
40+
public String eventType() {
41+
return get(NewRelicProperties::getEventType, NewRelicConfig.super::eventType);
42+
}
43+
3344
@Override
3445
public String apiKey() {
3546
return get(NewRelicProperties::getApiKey, NewRelicConfig.super::apiKey);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.micrometer.spring.autoconfigure.export.newrelic;
18+
19+
import io.micrometer.newrelic.NewRelicConfig;
20+
import org.junit.jupiter.api.Test;
21+
22+
import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesTest;
23+
24+
import static org.assertj.core.api.Assertions.assertThat;
25+
26+
/**
27+
* Tests for {@link NewRelicProperties}.
28+
*
29+
* @author Neil Powell
30+
*/
31+
public class NewRelicPropertiesTests extends StepRegistryPropertiesTest {
32+
33+
@Test
34+
public void defaultValuesAreConsistent() {
35+
NewRelicProperties properties = new NewRelicProperties();
36+
NewRelicConfig config = (key) -> null;
37+
assertStepRegistryDefaultValues(properties, config);
38+
// apiKey and account are mandatory
39+
assertThat(properties.getUri()).isEqualTo(config.uri());
40+
assertThat(properties.isMeterNameEventTypeEnabled()).isEqualTo(config.meterNameEventTypeEnabled());
41+
}
42+
43+
@Test
44+
void eventTypeDefaultValueIsOverriden() {
45+
NewRelicProperties properties = new NewRelicProperties();
46+
NewRelicConfig config = (key) -> null;
47+
assertThat(properties.getEventType()).isNotEqualTo(config.eventType());
48+
assertThat(properties.getEventType()).isEqualTo("SpringBootSample");
49+
assertThat(config.eventType()).isEqualTo("MicrometerSample");
50+
}
51+
52+
}

0 commit comments

Comments
 (0)