Skip to content

Commit 5a20403

Browse files
committed
Upgrade to Micrometer 1.5 snapshots
2 parents ed9cace + 6764e5e commit 5a20403

32 files changed

+427
-128
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ dependencies {
101101
optional("org.springframework.data:spring-data-redis")
102102
optional("org.springframework.data:spring-data-solr")
103103
optional("org.springframework.integration:spring-integration-core")
104+
optional("org.springframework.kafka:spring-kafka")
104105
optional("org.springframework.security:spring-security-config")
105106
optional("org.springframework.security:spring-security-web")
106107
optional("org.springframework.session:spring-session-core")
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,37 +18,37 @@
1818

1919
import java.util.Collections;
2020

21-
import javax.management.MBeanServer;
22-
2321
import io.micrometer.core.instrument.MeterRegistry;
24-
import io.micrometer.core.instrument.binder.kafka.KafkaConsumerMetrics;
25-
import org.apache.kafka.clients.consumer.KafkaConsumer;
22+
import io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics;
2623

2724
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
2825
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
2926
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
3027
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
31-
import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
28+
import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate;
29+
import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration;
3230
import org.springframework.context.annotation.Bean;
3331
import org.springframework.context.annotation.Configuration;
32+
import org.springframework.kafka.core.ProducerFactory;
3433

3534
/**
3635
* Auto-configuration for Kafka metrics.
3736
*
3837
* @author Andy Wilkinson
38+
* @author Stephane Nicoll
3939
* @since 2.1.0
4040
*/
4141
@Configuration(proxyBeanMethods = false)
42-
@AutoConfigureAfter({ MetricsAutoConfiguration.class, JmxAutoConfiguration.class })
43-
@ConditionalOnClass({ KafkaConsumerMetrics.class, KafkaConsumer.class })
42+
@AutoConfigureAfter({ MetricsAutoConfiguration.class, KafkaAutoConfiguration.class })
43+
@ConditionalOnClass({ KafkaClientMetrics.class, ProducerFactory.class })
4444
@ConditionalOnBean(MeterRegistry.class)
4545
public class KafkaMetricsAutoConfiguration {
4646

4747
@Bean
4848
@ConditionalOnMissingBean
49-
@ConditionalOnBean(MBeanServer.class)
50-
public KafkaConsumerMetrics kafkaConsumerMetrics(MBeanServer mbeanServer) {
51-
return new KafkaConsumerMetrics(mbeanServer, Collections.emptyList());
49+
@ConditionalOnSingleCandidate(ProducerFactory.class)
50+
public KafkaClientMetrics kafkaClientMetrics(ProducerFactory<?, ?> producerFactory) {
51+
return new KafkaClientMetrics(producerFactory.createProducer(), Collections.emptyList());
5252
}
5353

5454
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValue.java

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -25,17 +25,18 @@
2525

2626
/**
2727
* A meter value that is used when configuring micrometer. Can be a String representation
28-
* of either a {@link Long} (applicable to timers and distribution summaries) or a
28+
* of either a {@link Double} (applicable to timers and distribution summaries) or a
2929
* {@link Duration} (applicable to only timers).
3030
*
3131
* @author Phillip Webb
32+
* @author Stephane Nicoll
3233
* @since 2.2.0
3334
*/
3435
public final class MeterValue {
3536

3637
private final Object value;
3738

38-
MeterValue(long value) {
39+
MeterValue(double value) {
3940
this.value = value;
4041
}
4142

@@ -48,26 +49,29 @@ public final class MeterValue {
4849
* @param meterType the meter type
4950
* @return the value or {@code null} if the value cannot be applied
5051
*/
51-
public Long getValue(Type meterType) {
52+
public Double getValue(Type meterType) {
5253
if (meterType == Type.DISTRIBUTION_SUMMARY) {
5354
return getDistributionSummaryValue();
5455
}
5556
if (meterType == Type.TIMER) {
56-
return getTimerValue();
57+
Long timerValue = getTimerValue();
58+
if (timerValue != null) {
59+
return timerValue.doubleValue();
60+
}
5761
}
5862
return null;
5963
}
6064

61-
private Long getDistributionSummaryValue() {
62-
if (this.value instanceof Long) {
63-
return (Long) this.value;
65+
private Double getDistributionSummaryValue() {
66+
if (this.value instanceof Double) {
67+
return (Double) this.value;
6468
}
6569
return null;
6670
}
6771

6872
private Long getTimerValue() {
69-
if (this.value instanceof Long) {
70-
return TimeUnit.MILLISECONDS.toNanos((long) this.value);
73+
if (this.value instanceof Double) {
74+
return TimeUnit.MILLISECONDS.toNanos(((Double) this.value).longValue());
7175
}
7276
if (this.value instanceof Duration) {
7377
return ((Duration) this.value).toNanos();
@@ -82,8 +86,9 @@ private Long getTimerValue() {
8286
* @return a {@link MeterValue} instance
8387
*/
8488
public static MeterValue valueOf(String value) {
85-
if (isNumber(value)) {
86-
return new MeterValue(Long.parseLong(value));
89+
Double number = safeParseDouble(value);
90+
if (number != null) {
91+
return new MeterValue(number);
8792
}
8893
return new MeterValue(DurationStyle.detectAndParse(value));
8994
}
@@ -92,13 +97,29 @@ public static MeterValue valueOf(String value) {
9297
* Return a new {@link MeterValue} instance for the given long value.
9398
* @param value the source value
9499
* @return a {@link MeterValue} instance
100+
* @deprecated as of 2.3.0 in favor of {@link #valueOf(double)}
95101
*/
102+
@Deprecated
96103
public static MeterValue valueOf(long value) {
97104
return new MeterValue(value);
98105
}
99106

100-
private static boolean isNumber(String value) {
101-
return value.chars().allMatch(Character::isDigit);
107+
/**
108+
* Return a new {@link MeterValue} instance for the given double value.
109+
* @param value the source value
110+
* @return a {@link MeterValue} instance
111+
*/
112+
public static MeterValue valueOf(double value) {
113+
return new MeterValue(value);
114+
}
115+
116+
private static Double safeParseDouble(String value) {
117+
try {
118+
return Double.parseDouble(value);
119+
}
120+
catch (NumberFormatException nfe) {
121+
return null;
122+
}
102123
}
103124

104125
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -91,16 +91,16 @@ public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticC
9191
.build().merge(config);
9292
}
9393

94-
private long[] convertSla(Meter.Type meterType, ServiceLevelAgreementBoundary[] sla) {
94+
private double[] convertSla(Meter.Type meterType, ServiceLevelAgreementBoundary[] sla) {
9595
if (sla == null) {
9696
return null;
9797
}
98-
long[] converted = Arrays.stream(sla).map((candidate) -> candidate.getValue(meterType)).filter(Objects::nonNull)
99-
.mapToLong(Long::longValue).toArray();
98+
double[] converted = Arrays.stream(sla).map((candidate) -> candidate.getValue(meterType))
99+
.filter(Objects::nonNull).mapToDouble(Double::doubleValue).toArray();
100100
return (converted.length != 0) ? converted : null;
101101
}
102102

103-
private Long convertMeterValue(Meter.Type meterType, String value) {
103+
private Double convertMeterValue(Meter.Type meterType, String value) {
104104
return (value != null) ? MeterValue.valueOf(value).getValue(meterType) : null;
105105
}
106106

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelAgreementBoundary.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,8 +22,8 @@
2222

2323
/**
2424
* A service level agreement boundary for use when configuring Micrometer. Can be
25-
* specified as either a {@link Long} (applicable to timers and distribution summaries) or
26-
* a {@link Duration} (applicable to only timers).
25+
* specified as either a {@link Double} (applicable to timers and distribution summaries)
26+
* or a {@link Duration} (applicable to only timers).
2727
*
2828
* @author Phillip Webb
2929
* @since 2.0.0
@@ -42,17 +42,17 @@ public final class ServiceLevelAgreementBoundary {
4242
* @param meterType the meter type
4343
* @return the value or {@code null} if the value cannot be applied
4444
*/
45-
public Long getValue(Meter.Type meterType) {
45+
public Double getValue(Meter.Type meterType) {
4646
return this.value.getValue(meterType);
4747
}
4848

4949
/**
50-
* Return a new {@link ServiceLevelAgreementBoundary} instance for the given long
50+
* Return a new {@link ServiceLevelAgreementBoundary} instance for the given double
5151
* value.
5252
* @param value the source value
5353
* @return a {@link ServiceLevelAgreementBoundary} instance
5454
*/
55-
public static ServiceLevelAgreementBoundary valueOf(long value) {
55+
public static ServiceLevelAgreementBoundary valueOf(double value) {
5656
return new ServiceLevelAgreementBoundary(MeterValue.valueOf(value));
5757
}
5858

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsProperties.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -46,6 +46,12 @@ public class AppOpticsProperties extends StepRegistryProperties {
4646
*/
4747
private String hostTag = "instance";
4848

49+
/**
50+
* Whether to ship a floored time, useful when sending measurements from multiple
51+
* hosts to align them on a given time boundary.
52+
*/
53+
private boolean floorTimes;
54+
4955
/**
5056
* Number of measurements per request to use for this backend. If more measurements
5157
* are found, then multiple requests will be made.
@@ -81,6 +87,14 @@ public void setHostTag(String hostTag) {
8187
this.hostTag = hostTag;
8288
}
8389

90+
public boolean isFloorTimes() {
91+
return this.floorTimes;
92+
}
93+
94+
public void setFloorTimes(boolean floorTimes) {
95+
this.floorTimes = floorTimes;
96+
}
97+
8498
@Override
8599
public Integer getBatchSize() {
86100
return this.batchSize;

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapter.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,4 +47,9 @@ public String hostTag() {
4747
return get(AppOpticsProperties::getHostTag, AppOpticsConfig.super::hostTag);
4848
}
4949

50+
@Override
51+
public boolean floorTimes() {
52+
return get(AppOpticsProperties::isFloorTimes, AppOpticsConfig.super::floorTimes);
53+
}
54+
5055
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public class DatadogProperties extends StepRegistryProperties {
5656
* URI to ship metrics to. If you need to publish metrics to an internal proxy
5757
* en-route to Datadog, you can define the location of the proxy with this.
5858
*/
59-
private String uri = "https://app.datadoghq.com";
59+
private String uri = "https://api.datadoghq.com";
6060

6161
public String getApiKey() {
6262
return this.apiKey;

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticProperties.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -40,11 +40,15 @@ public class ElasticProperties extends StepRegistryProperties {
4040
private String index = "metrics";
4141

4242
/**
43-
* Index date format used for rolling indices. Appended to the index name, preceded by
44-
* a '-'.
43+
* Index date format used for rolling indices. Appended to the index name.
4544
*/
4645
private String indexDateFormat = "yyyy-MM";
4746

47+
/**
48+
* Prefix to separate the index name from the date format used for rolling indices.
49+
*/
50+
private String indexDateSeparator = "-";
51+
4852
/**
4953
* Name of the timestamp field.
5054
*/
@@ -65,6 +69,11 @@ public class ElasticProperties extends StepRegistryProperties {
6569
*/
6670
private String password = "";
6771

72+
/**
73+
* Ingest pipeline name. By default, events are not pre-processed.
74+
*/
75+
private String pipeline = "";
76+
6877
public String getHost() {
6978
return this.host;
7079
}
@@ -89,6 +98,14 @@ public void setIndexDateFormat(String indexDateFormat) {
8998
this.indexDateFormat = indexDateFormat;
9099
}
91100

101+
public String getIndexDateSeparator() {
102+
return this.indexDateSeparator;
103+
}
104+
105+
public void setIndexDateSeparator(String indexDateSeparator) {
106+
this.indexDateSeparator = indexDateSeparator;
107+
}
108+
92109
public String getTimestampFieldName() {
93110
return this.timestampFieldName;
94111
}
@@ -121,4 +138,12 @@ public void setPassword(String password) {
121138
this.password = password;
122139
}
123140

141+
public String getPipeline() {
142+
return this.pipeline;
143+
}
144+
145+
public void setPipeline(String pipeline) {
146+
this.pipeline = pipeline;
147+
}
148+
124149
}

0 commit comments

Comments
 (0)