Skip to content

Commit e8db31b

Browse files
authored
Merge pull request aol#378 from jijisv/datadog_report_fix
Datadog report fix
2 parents fa42150 + 22e402d commit e8db31b

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

micro-core/src/main/resources/logback.xml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
<configuration scan="true">
22

3-
43
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
54
<encoder>
6-
<pattern>%date{MMM dd yyyy h:mm:ss a z,EST} %-5p %c - %msg --
7-
[%thread] %n</pattern>
5+
<pattern>%date{MMM dd yyyy h:mm:ss a z,EST} %-5p %c - %msg -- [%thread] %n</pattern>
86
</encoder>
97
</appender>
108

11-
12-
13-
14-
15-
16-
179
<root>
1810
<level value="INFO" />
1911
<appender-ref ref="CONSOLE" />

micro-metrics-datadog/src/main/java/com/aol/micro/server/datadog/metrics/DatadogMetricsConfigurer.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.util.stream.Stream;
1111

1212
import cyclops.control.Maybe;
13+
import lombok.extern.slf4j.Slf4j;
1314
import org.coursera.metrics.datadog.DatadogReporter;
1415
import org.coursera.metrics.datadog.transport.HttpTransport;
1516
import org.springframework.beans.factory.annotation.Autowired;
@@ -24,6 +25,7 @@
2425

2526
@Configuration
2627
@EnableMetrics
28+
@Slf4j
2729
public class DatadogMetricsConfigurer extends MetricsConfigurerAdapter {
2830

2931
private String apiKey;
@@ -36,19 +38,20 @@ public class DatadogMetricsConfigurer extends MetricsConfigurerAdapter {
3638
private final String host;
3739

3840
@Autowired
39-
public DatadogMetricsConfigurer(@Value("${datadog.apikey}") String apiKey,
40-
@Value("${datadog.tags:{\"stage:dev\"}}") String tags, @Value("${datadog.report.period:1}") int period,
41-
@Value("${datadog.report.timeunit:SECONDS}") TimeUnit timeUnit,
42-
@Value("${datadog.report.expansions:#{null}}") String expStr,
43-
@Value("${host.address:#{null}}") String host){
41+
public DatadogMetricsConfigurer(@Value("${datadog.apikey:#{null}}") String apiKey,
42+
@Value("${datadog.tags:{\"stage:dev\"}}") String tags,
43+
@Value("${datadog.report.period:1}") int period,
44+
@Value("${datadog.report.timeunit:SECONDS}") TimeUnit timeUnit,
45+
@Value("${datadog.report.expansions:#{null}}") String expStr,
46+
@Value("${host.address:#{null}}") String host){
4447
this.apiKey = apiKey;
4548
this.tags = Arrays.asList(Optional.ofNullable(tags)
4649
.orElse("")
4750
.split(","));
4851
this.period = period;
4952
this.timeUnit = timeUnit;
5053
this.expansions = expansions(expStr);
51-
this.host = host;
54+
this.host = host;
5255
}
5356

5457
private EnumSet<DatadogReporter.Expansion> expansions(String expStr) {
@@ -65,10 +68,14 @@ private EnumSet<DatadogReporter.Expansion> expansions(String expStr) {
6568

6669
@Override
6770
public void configureReporters(MetricRegistry metricRegistry) {
71+
if (Objects.isNull(apiKey)) {
72+
log.error("The 'datadog.apikey' is null. Datadog reporting will be ignored.");
73+
return;
74+
}
6875
HttpTransport httpTransport = new HttpTransport.Builder().withApiKey(apiKey)
6976
.build();
7077
EnumSet<DatadogReporter.Expansion> expansions = DatadogReporter.Expansion.ALL;
71-
DatadogReporter.Builder builder = DatadogReporter.forRegistry(metricRegistry)
78+
DatadogReporter.Builder builder = DatadogReporter.forRegistry(metricRegistry)
7279
.withTransport(httpTransport)
7380
.withExpansions(expansions)
7481
.withTags(tags);

0 commit comments

Comments
 (0)