diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle index 41b31ac249..c8166427ee 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/build.gradle @@ -101,6 +101,7 @@ dependencies { optional("org.springframework.data:spring-data-redis") optional("org.springframework.data:spring-data-solr") optional("org.springframework.integration:spring-integration-core") + optional("org.springframework.kafka:spring-kafka") optional("org.springframework.security:spring-security-config") optional("org.springframework.security:spring-security-web") optional("org.springframework.session:spring-session-core") diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfiguration.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfiguration.java index f2bbcfe6e1..e026f89006 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfiguration.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/KafkaMetricsAutoConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,37 +18,37 @@ package org.springframework.boot.actuate.autoconfigure.metrics; import java.util.Collections; -import javax.management.MBeanServer; - import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.kafka.KafkaConsumerMetrics; -import org.apache.kafka.clients.consumer.KafkaConsumer; +import io.micrometer.core.instrument.binder.kafka.KafkaClientMetrics; import org.springframework.boot.autoconfigure.AutoConfigureAfter; import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; +import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.kafka.core.ProducerFactory; /** * Auto-configuration for Kafka metrics. * * @author Andy Wilkinson + * @author Stephane Nicoll * @since 2.1.0 */ @Configuration(proxyBeanMethods = false) -@AutoConfigureAfter({ MetricsAutoConfiguration.class, JmxAutoConfiguration.class }) -@ConditionalOnClass({ KafkaConsumerMetrics.class, KafkaConsumer.class }) +@AutoConfigureAfter({ MetricsAutoConfiguration.class, KafkaAutoConfiguration.class }) +@ConditionalOnClass({ KafkaClientMetrics.class, ProducerFactory.class }) @ConditionalOnBean(MeterRegistry.class) public class KafkaMetricsAutoConfiguration { @Bean @ConditionalOnMissingBean - @ConditionalOnBean(MBeanServer.class) - public KafkaConsumerMetrics kafkaConsumerMetrics(MBeanServer mbeanServer) { - return new KafkaConsumerMetrics(mbeanServer, Collections.emptyList()); + @ConditionalOnSingleCandidate(ProducerFactory.class) + public KafkaClientMetrics kafkaClientMetrics(ProducerFactory producerFactory) { + return new KafkaClientMetrics(producerFactory.createProducer(), Collections.emptyList()); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValue.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValue.java index c6d5fbcd25..b0dc59d0a2 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValue.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,17 +25,18 @@ import org.springframework.boot.convert.DurationStyle; /** * A meter value that is used when configuring micrometer. Can be a String representation - * of either a {@link Long} (applicable to timers and distribution summaries) or a + * of either a {@link Double} (applicable to timers and distribution summaries) or a * {@link Duration} (applicable to only timers). * * @author Phillip Webb + * @author Stephane Nicoll * @since 2.2.0 */ public final class MeterValue { private final Object value; - MeterValue(long value) { + MeterValue(double value) { this.value = value; } @@ -48,26 +49,29 @@ public final class MeterValue { * @param meterType the meter type * @return the value or {@code null} if the value cannot be applied */ - public Long getValue(Type meterType) { + public Double getValue(Type meterType) { if (meterType == Type.DISTRIBUTION_SUMMARY) { return getDistributionSummaryValue(); } if (meterType == Type.TIMER) { - return getTimerValue(); + Long timerValue = getTimerValue(); + if (timerValue != null) { + return timerValue.doubleValue(); + } } return null; } - private Long getDistributionSummaryValue() { - if (this.value instanceof Long) { - return (Long) this.value; + private Double getDistributionSummaryValue() { + if (this.value instanceof Double) { + return (Double) this.value; } return null; } private Long getTimerValue() { - if (this.value instanceof Long) { - return TimeUnit.MILLISECONDS.toNanos((long) this.value); + if (this.value instanceof Double) { + return TimeUnit.MILLISECONDS.toNanos(((Double) this.value).longValue()); } if (this.value instanceof Duration) { return ((Duration) this.value).toNanos(); @@ -82,8 +86,9 @@ public final class MeterValue { * @return a {@link MeterValue} instance */ public static MeterValue valueOf(String value) { - if (isNumber(value)) { - return new MeterValue(Long.parseLong(value)); + Double number = safeParseDouble(value); + if (number != null) { + return new MeterValue(number); } return new MeterValue(DurationStyle.detectAndParse(value)); } @@ -92,13 +97,29 @@ public final class MeterValue { * Return a new {@link MeterValue} instance for the given long value. * @param value the source value * @return a {@link MeterValue} instance + * @deprecated as of 2.3.0 in favor of {@link #valueOf(double)} */ + @Deprecated public static MeterValue valueOf(long value) { return new MeterValue(value); } - private static boolean isNumber(String value) { - return value.chars().allMatch(Character::isDigit); + /** + * Return a new {@link MeterValue} instance for the given double value. + * @param value the source value + * @return a {@link MeterValue} instance + */ + public static MeterValue valueOf(double value) { + return new MeterValue(value); + } + + private static Double safeParseDouble(String value) { + try { + return Double.parseDouble(value); + } + catch (NumberFormatException nfe) { + return null; + } } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java index bf50bb63cc..b5bce1a418 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/PropertiesMeterFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,16 +91,16 @@ public class PropertiesMeterFilter implements MeterFilter { .build().merge(config); } - private long[] convertSla(Meter.Type meterType, ServiceLevelAgreementBoundary[] sla) { + private double[] convertSla(Meter.Type meterType, ServiceLevelAgreementBoundary[] sla) { if (sla == null) { return null; } - long[] converted = Arrays.stream(sla).map((candidate) -> candidate.getValue(meterType)).filter(Objects::nonNull) - .mapToLong(Long::longValue).toArray(); + double[] converted = Arrays.stream(sla).map((candidate) -> candidate.getValue(meterType)) + .filter(Objects::nonNull).mapToDouble(Double::doubleValue).toArray(); return (converted.length != 0) ? converted : null; } - private Long convertMeterValue(Meter.Type meterType, String value) { + private Double convertMeterValue(Meter.Type meterType, String value) { return (value != null) ? MeterValue.valueOf(value).getValue(meterType) : null; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelAgreementBoundary.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelAgreementBoundary.java index 9fa875fc18..dd0f80f770 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelAgreementBoundary.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelAgreementBoundary.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ import io.micrometer.core.instrument.Meter; /** * A service level agreement boundary for use when configuring Micrometer. Can be - * specified as either a {@link Long} (applicable to timers and distribution summaries) or - * a {@link Duration} (applicable to only timers). + * specified as either a {@link Double} (applicable to timers and distribution summaries) + * or a {@link Duration} (applicable to only timers). * * @author Phillip Webb * @since 2.0.0 @@ -42,17 +42,17 @@ public final class ServiceLevelAgreementBoundary { * @param meterType the meter type * @return the value or {@code null} if the value cannot be applied */ - public Long getValue(Meter.Type meterType) { + public Double getValue(Meter.Type meterType) { return this.value.getValue(meterType); } /** - * Return a new {@link ServiceLevelAgreementBoundary} instance for the given long + * Return a new {@link ServiceLevelAgreementBoundary} instance for the given double * value. * @param value the source value * @return a {@link ServiceLevelAgreementBoundary} instance */ - public static ServiceLevelAgreementBoundary valueOf(long value) { + public static ServiceLevelAgreementBoundary valueOf(double value) { return new ServiceLevelAgreementBoundary(MeterValue.valueOf(value)); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsProperties.java index b50a50c42c..991e733d9c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,6 +46,12 @@ public class AppOpticsProperties extends StepRegistryProperties { */ private String hostTag = "instance"; + /** + * Whether to ship a floored time, useful when sending measurements from multiple + * hosts to align them on a given time boundary. + */ + private boolean floorTimes; + /** * Number of measurements per request to use for this backend. If more measurements * are found, then multiple requests will be made. @@ -81,6 +87,14 @@ public class AppOpticsProperties extends StepRegistryProperties { this.hostTag = hostTag; } + public boolean isFloorTimes() { + return this.floorTimes; + } + + public void setFloorTimes(boolean floorTimes) { + this.floorTimes = floorTimes; + } + @Override public Integer getBatchSize() { return this.batchSize; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapter.java index 88ebb38e8f..7a959fb7bc 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,4 +47,9 @@ class AppOpticsPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapt return get(AppOpticsProperties::getHostTag, AppOpticsConfig.super::hostTag); } + @Override + public boolean floorTimes() { + return get(AppOpticsProperties::isFloorTimes, AppOpticsConfig.super::floorTimes); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java index f042358d64..139c16fd98 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/datadog/DatadogProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ public class DatadogProperties extends StepRegistryProperties { * URI to ship metrics to. If you need to publish metrics to an internal proxy * en-route to Datadog, you can define the location of the proxy with this. */ - private String uri = "https://app.datadoghq.com"; + private String uri = "https://api.datadoghq.com"; public String getApiKey() { return this.apiKey; diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticProperties.java index 5af408d5d9..2a94556cda 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,11 +40,15 @@ public class ElasticProperties extends StepRegistryProperties { private String index = "metrics"; /** - * Index date format used for rolling indices. Appended to the index name, preceded by - * a '-'. + * Index date format used for rolling indices. Appended to the index name. */ private String indexDateFormat = "yyyy-MM"; + /** + * Prefix to separate the index name from the date format used for rolling indices. + */ + private String indexDateSeparator = "-"; + /** * Name of the timestamp field. */ @@ -65,6 +69,11 @@ public class ElasticProperties extends StepRegistryProperties { */ private String password = ""; + /** + * Ingest pipeline name. By default, events are not pre-processed. + */ + private String pipeline = ""; + public String getHost() { return this.host; } @@ -89,6 +98,14 @@ public class ElasticProperties extends StepRegistryProperties { this.indexDateFormat = indexDateFormat; } + public String getIndexDateSeparator() { + return this.indexDateSeparator; + } + + public void setIndexDateSeparator(String indexDateSeparator) { + this.indexDateSeparator = indexDateSeparator; + } + public String getTimestampFieldName() { return this.timestampFieldName; } @@ -121,4 +138,12 @@ public class ElasticProperties extends StepRegistryProperties { this.password = password; } + public String getPipeline() { + return this.pipeline; + } + + public void setPipeline(String pipeline) { + this.pipeline = pipeline; + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapter.java index 8d41ebe252..06a507b506 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,6 +47,11 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter return get(ElasticProperties::getIndexDateFormat, ElasticConfig.super::indexDateFormat); } + @Override + public String indexDateSeparator() { + return get(ElasticProperties::getIndexDateSeparator, ElasticConfig.super::indexDateSeparator); + } + @Override public String timestampFieldName() { return get(ElasticProperties::getTimestampFieldName, ElasticConfig.super::timestampFieldName); @@ -67,4 +72,9 @@ class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter return get(ElasticProperties::getPassword, ElasticConfig.super::password); } + @Override + public String pipeline() { + return get(ElasticProperties::getPipeline, ElasticConfig.super::pipeline); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteProperties.java index d5eb861b8d..3dec132528 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,8 +70,14 @@ public class GraphiteProperties { private GraphiteProtocol protocol = GraphiteProtocol.PICKLED; /** - * For the default naming convention, turn the specified tag keys into part of the - * metric prefix. + * Whether Graphite tags should be used, as opposed to a hierarchical naming + * convention. + */ + private boolean graphiteTagsEnabled = true; + + /** + * For the hierarchical naming convention, turn the specified tag keys into part of + * the metric prefix. Ignored if "graphiteTagsEnabled" is true. */ private String[] tagsAsPrefix = new String[0]; @@ -131,6 +137,14 @@ public class GraphiteProperties { this.protocol = protocol; } + public boolean isGraphiteTagsEnabled() { + return this.graphiteTagsEnabled; + } + + public void setGraphiteTagsEnabled(boolean graphiteTagsEnabled) { + this.graphiteTagsEnabled = graphiteTagsEnabled; + } + public String[] getTagsAsPrefix() { return this.tagsAsPrefix; } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapter.java index 7f3067e163..bc89039799 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesConfigAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -76,6 +76,11 @@ class GraphitePropertiesConfigAdapter extends PropertiesConfigAdapter assertThat(context).doesNotHaveBean(KafkaConsumerMetrics.class)); + void whenThereIsNoProducerFactoryAutoConfigurationBacksOff() { + this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(KafkaClientMetrics.class)); } @Test - void whenThereIsAnMBeanServerKafkaConsumerMetricsIsConfigured() { - this.contextRunner.withConfiguration(AutoConfigurations.of(JmxAutoConfiguration.class)) - .run((context) -> assertThat(context).hasSingleBean(KafkaConsumerMetrics.class)); + void whenThereIsAnAProducerFactoryKafkaClientMetricsIsConfigured() { + this.contextRunner.withConfiguration(AutoConfigurations.of(KafkaAutoConfiguration.class)) + .run((context) -> assertThat(context).hasSingleBean(KafkaClientMetrics.class)); } @Test - void allowsCustomKafkaConsumerMetricsToBeUsed() { - this.contextRunner.withConfiguration(AutoConfigurations.of(JmxAutoConfiguration.class)) - .withUserConfiguration(CustomKafkaConsumerMetricsConfiguration.class) - .run((context) -> assertThat(context).hasSingleBean(KafkaConsumerMetrics.class) - .hasBean("customKafkaConsumerMetrics")); + void allowsCustomKafkaClientMetricsToBeUsed() { + this.contextRunner.withConfiguration(AutoConfigurations.of(KafkaAutoConfiguration.class)) + .withUserConfiguration(CustomKafkaClientMetricsConfiguration.class).run((context) -> assertThat(context) + .hasSingleBean(KafkaClientMetrics.class).hasBean("customKafkaClientMetrics")); } @Configuration(proxyBeanMethods = false) - static class CustomKafkaConsumerMetricsConfiguration { + static class CustomKafkaClientMetricsConfiguration { @Bean - KafkaConsumerMetrics customKafkaConsumerMetrics() { - return new KafkaConsumerMetrics(); + KafkaClientMetrics customKafkaClientMetrics() { + return mock(KafkaClientMetrics.class); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValueTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValueTests.java index f63da5faae..1c1572d168 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValueTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/MeterValueTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,17 +30,18 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link MeterValue}. * * @author Phillip Webb + * @author Stephane Nicoll */ class MeterValueTests { @Test - void getValueForDistributionSummaryWhenFromLongShouldReturnLongValue() { - MeterValue meterValue = MeterValue.valueOf(123L); - assertThat(meterValue.getValue(Type.DISTRIBUTION_SUMMARY)).isEqualTo(123); + void getValueForDistributionSummaryWhenFromNumberShouldReturnDoubleValue() { + MeterValue meterValue = MeterValue.valueOf(123.42); + assertThat(meterValue.getValue(Type.DISTRIBUTION_SUMMARY)).isEqualTo(123.42); } @Test - void getValueForDistributionSummaryWhenFromNumberStringShouldReturnLongValue() { + void getValueForDistributionSummaryWhenFromNumberStringShouldReturnDoubleValue() { MeterValue meterValue = MeterValue.valueOf("123"); assertThat(meterValue.getValue(Type.DISTRIBUTION_SUMMARY)).isEqualTo(123); } @@ -52,8 +53,8 @@ class MeterValueTests { } @Test - void getValueForTimerWhenFromLongShouldReturnMsToNanosValue() { - MeterValue meterValue = MeterValue.valueOf(123L); + void getValueForTimerWhenFromNumberShouldReturnMsToNanosValue() { + MeterValue meterValue = MeterValue.valueOf(123d); assertThat(meterValue.getValue(Type.TIMER)).isEqualTo(123000000); } @@ -81,11 +82,11 @@ class MeterValueTests { @Test void valueOfShouldWorkInBinder() { MockEnvironment environment = new MockEnvironment(); - TestPropertyValues.of("duration=10ms", "long=20").applyTo(environment); + TestPropertyValues.of("duration=10ms", "number=20.42").applyTo(environment); assertThat(Binder.get(environment).bind("duration", Bindable.of(MeterValue.class)).get().getValue(Type.TIMER)) .isEqualTo(10000000); - assertThat(Binder.get(environment).bind("long", Bindable.of(MeterValue.class)).get().getValue(Type.TIMER)) - .isEqualTo(20000000); + assertThat(Binder.get(environment).bind("number", Bindable.of(MeterValue.class)).get() + .getValue(Type.DISTRIBUTION_SUMMARY)).isEqualTo(20.42); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelAgreementBoundaryTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelAgreementBoundaryTests.java index d9cb37e7f1..f3250c13ac 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelAgreementBoundaryTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/ServiceLevelAgreementBoundaryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import static org.assertj.core.api.Assertions.assertThat; * Tests for {@link ServiceLevelAgreementBoundary}. * * @author Phillip Webb + * @author Stephane Nicoll */ class ServiceLevelAgreementBoundaryTests { @@ -46,4 +47,22 @@ class ServiceLevelAgreementBoundaryTests { assertThat(sla.getValue(Type.TIMER)).isEqualTo(123000000); } + @Test + void getValueForDistributionSummaryWhenFromDoubleShouldReturnDoubleValue() { + ServiceLevelAgreementBoundary sla = ServiceLevelAgreementBoundary.valueOf(123.42); + assertThat(sla.getValue(Type.DISTRIBUTION_SUMMARY)).isEqualTo(123.42); + } + + @Test + void getValueForDistributionSummaryWhenFromStringShouldReturnDoubleValue() { + ServiceLevelAgreementBoundary sla = ServiceLevelAgreementBoundary.valueOf("123.42"); + assertThat(sla.getValue(Type.DISTRIBUTION_SUMMARY)).isEqualTo(123.42); + } + + @Test + void getValueForDistributionSummaryWhenFromDurationShouldReturnNull() { + ServiceLevelAgreementBoundary sla = ServiceLevelAgreementBoundary.valueOf("123ms"); + assertThat(sla.getValue(Type.DISTRIBUTION_SUMMARY)).isNull(); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java index ff619497c5..ff0f57f379 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -61,4 +61,11 @@ class AppOpticsPropertiesConfigAdapterTests assertThat(createConfigAdapter(properties).hostTag()).isEqualTo("node"); } + @Test + void whenPropertiesFloorTimesIsSetAdapterHostTagReturnsIt() { + AppOpticsProperties properties = createProperties(); + properties.setFloorTimes(true); + assertThat(createConfigAdapter(properties).floorTimes()).isTrue(); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesTests.java index 2ca99cf87a..5e3f4b6cec 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/appoptics/AppOpticsPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ class AppOpticsPropertiesTests extends StepRegistryPropertiesTests { assertStepRegistryDefaultValues(properties, config); assertThat(properties.getUri()).isEqualToIgnoringWhitespace(config.uri()); assertThat(properties.getHostTag()).isEqualToIgnoringWhitespace(config.hostTag()); + assertThat(properties.isFloorTimes()).isEqualTo(config.floorTimes()); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java index f3a27b724a..23e840531c 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesConfigAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -48,6 +48,13 @@ class ElasticPropertiesConfigAdapterTests { assertThat(new ElasticPropertiesConfigAdapter(properties).indexDateFormat()).isEqualTo("yyyy"); } + @Test + void whenPropertiesIndexDateSeparatorIsSetAdapterIndexDateFormatReturnsIt() { + ElasticProperties properties = new ElasticProperties(); + properties.setIndexDateSeparator("*"); + assertThat(new ElasticPropertiesConfigAdapter(properties).indexDateSeparator()).isEqualTo("*"); + } + @Test void whenPropertiesTimestampFieldNameIsSetAdapterTimestampFieldNameReturnsIt() { ElasticProperties properties = new ElasticProperties(); @@ -76,4 +83,11 @@ class ElasticPropertiesConfigAdapterTests { assertThat(new ElasticPropertiesConfigAdapter(properties).password()).isEqualTo("secret"); } + @Test + void whenPropertiesPipelineIsSetAdapterPasswordReturnsIt() { + ElasticProperties properties = new ElasticProperties(); + properties.setPipeline("testPipeline"); + assertThat(new ElasticPropertiesConfigAdapter(properties).pipeline()).isEqualTo("testPipeline"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesTests.java index 407c968c14..7e692f0a7f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/elastic/ElasticPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,10 +38,12 @@ class ElasticPropertiesTests extends StepRegistryPropertiesTests { assertThat(properties.getHost()).isEqualTo(config.host()); assertThat(properties.getIndex()).isEqualTo(config.index()); assertThat(properties.getIndexDateFormat()).isEqualTo(config.indexDateFormat()); + assertThat(properties.getIndexDateSeparator()).isEqualTo(config.indexDateSeparator()); assertThat(properties.getPassword()).isEqualTo(config.password()); assertThat(properties.getTimestampFieldName()).isEqualTo(config.timestampFieldName()); assertThat(properties.getUserName()).isEqualTo(config.userName()); assertThat(properties.isAutoCreateIndex()).isEqualTo(config.autoCreateIndex()); + assertThat(properties.getPipeline()).isEqualTo(config.pipeline()); } } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfigurationTests.java index 7be60e9b6c..b495495382 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphiteMetricsExportAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -46,10 +46,23 @@ class GraphiteMetricsExportAutoConfigurationTests { this.contextRunner.run((context) -> assertThat(context).doesNotHaveBean(GraphiteMeterRegistry.class)); } + @Test + void autoConfiguresUseTagsAsPrefixIsIgnoredByDefault() { + this.contextRunner.withUserConfiguration(BaseConfiguration.class) + .withPropertyValues("management.metrics.export.graphite.tags-as-prefix=ignored").run((context) -> { + assertThat(context).hasSingleBean(GraphiteMeterRegistry.class); + GraphiteMeterRegistry registry = context.getBean(GraphiteMeterRegistry.class); + registry.counter("test.count", Tags.of("app", "myapp")); + assertThat(registry.getDropwizardRegistry().getMeters()).containsOnlyKeys("test.count;app=myapp"); + }); + } + @Test void autoConfiguresUseTagsAsPrefix() { this.contextRunner.withUserConfiguration(BaseConfiguration.class) - .withPropertyValues("management.metrics.export.graphite.tags-as-prefix=app").run((context) -> { + .withPropertyValues("management.metrics.export.graphite.tags-as-prefix=app", + "management.metrics.export.graphite.graphite-tags-enabled=false") + .run((context) -> { assertThat(context).hasSingleBean(GraphiteMeterRegistry.class); GraphiteMeterRegistry registry = context.getBean(GraphiteMeterRegistry.class); registry.counter("test.count", Tags.of("app", "myapp")); diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesTests.java index 54aef944a3..5e0ed18fc5 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/graphite/GraphitePropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,6 +39,7 @@ class GraphitePropertiesTests { assertThat(properties.getHost()).isEqualTo(config.host()); assertThat(properties.getPort()).isEqualTo(config.port()); assertThat(properties.getProtocol()).isEqualTo(config.protocol()); + assertThat(properties.isGraphiteTagsEnabled()).isEqualTo(config.graphiteTagsEnabled()); assertThat(properties.getTagsAsPrefix()).isEqualTo(config.tagsAsPrefix()); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesTests.java index 993986a80b..3cfc3c5ac9 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/prometheus/PrometheusPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,6 +33,7 @@ class PrometheusPropertiesTests { PrometheusProperties properties = new PrometheusProperties(); PrometheusConfig config = PrometheusConfig.DEFAULT; assertThat(properties.isDescriptions()).isEqualTo(config.descriptions()); + assertThat(properties.getHistogramFlavor()).isEqualTo(config.histogramFlavor()); assertThat(properties.getStep()).isEqualTo(config.step()); } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java index 30dcdc04ec..e4e37bad73 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/statsd/StatsdMetricsExportAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.statsd; import io.micrometer.core.instrument.Clock; import io.micrometer.statsd.StatsdConfig; import io.micrometer.statsd.StatsdMeterRegistry; -import io.micrometer.statsd.StatsdMetrics; import org.junit.jupiter.api.Test; import org.springframework.boot.autoconfigure.AutoConfigurations; @@ -47,9 +46,8 @@ class StatsdMetricsExportAutoConfigurationTests { @Test void autoConfiguresItsConfigMeterRegistryAndMetrics() { - this.contextRunner.withUserConfiguration(BaseConfiguration.class) - .run((context) -> assertThat(context).hasSingleBean(StatsdMeterRegistry.class) - .hasSingleBean(StatsdConfig.class).hasSingleBean(StatsdMetrics.class)); + this.contextRunner.withUserConfiguration(BaseConfiguration.class).run((context) -> assertThat(context) + .hasSingleBean(StatsdMeterRegistry.class).hasSingleBean(StatsdConfig.class)); } @Test diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java index 50c04b9c4a..62281d9e5f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/wavefront/WavefrontMetricsExportAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 the original author or authors. + * Copyright 2012-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package org.springframework.boot.actuate.autoconfigure.metrics.export.wavefront; +import com.wavefront.sdk.common.WavefrontSender; import io.micrometer.core.instrument.Clock; import io.micrometer.wavefront.WavefrontConfig; import io.micrometer.wavefront.WavefrontMeterRegistry; @@ -28,6 +29,7 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; /** * Tests for {@link WavefrontMetricsExportAutoConfiguration}. @@ -53,9 +55,10 @@ class WavefrontMetricsExportAutoConfigurationTests { @Test void autoConfigurationCanBeDisabled() { this.contextRunner.withUserConfiguration(BaseConfiguration.class) - .withPropertyValues("management.metrics.export.wavefront.enabled=false") + .withPropertyValues("management.metrics.export.wavefront.api-token=abcde", + "management.metrics.export.wavefront.enabled=false") .run((context) -> assertThat(context).doesNotHaveBean(WavefrontMeterRegistry.class) - .doesNotHaveBean(WavefrontConfig.class)); + .doesNotHaveBean(WavefrontConfig.class).doesNotHaveBean(WavefrontSender.class)); } @Test @@ -63,7 +66,30 @@ class WavefrontMetricsExportAutoConfigurationTests { this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class) .run((context) -> assertThat(context).hasSingleBean(Clock.class) .hasSingleBean(WavefrontMeterRegistry.class).hasSingleBean(WavefrontConfig.class) - .hasBean("customConfig")); + .hasSingleBean(WavefrontSender.class).hasBean("customConfig")); + } + + @Test + void configureWavefrontSender() { + this.contextRunner.withUserConfiguration(BaseConfiguration.class) + .withPropertyValues("management.metrics.export.wavefront.api-token=abcde", + "management.metrics.export.wavefront.sender.max-queue-size=100", + "management.metrics.export.wavefront.sender.batch-size=200", + "management.metrics.export.wavefront.sender.message-size=1KB") + .run((context) -> { + WavefrontSender sender = context.getBean(WavefrontSender.class); + assertThat(sender).extracting("metricsBuffer").hasFieldOrPropertyWithValue("capacity", 100); + assertThat(sender).hasFieldOrPropertyWithValue("batchSize", 200); + assertThat(sender).hasFieldOrPropertyWithValue("messageSizeBytes", 1024); + }); + } + + @Test + void allowsWavefrontSenderToBeCustomized() { + this.contextRunner.withUserConfiguration(CustomSenderConfiguration.class) + .run((context) -> assertThat(context).hasSingleBean(Clock.class) + .hasSingleBean(WavefrontMeterRegistry.class).hasSingleBean(WavefrontConfig.class) + .hasSingleBean(WavefrontSender.class).hasBean("customSender")); } @Test @@ -109,13 +135,29 @@ class WavefrontMetricsExportAutoConfigurationTests { @Override public String uri() { - return WavefrontConfig.DEFAULT_PROXY.uri(); + return WavefrontConfig.DEFAULT_DIRECT.uri(); + } + + @Override + public String apiToken() { + return "abc-def"; } }; } } + @Configuration(proxyBeanMethods = false) + @Import(BaseConfiguration.class) + static class CustomSenderConfiguration { + + @Bean + WavefrontSender customSender() { + return mock(WavefrontSender.class); + } + + } + @Configuration(proxyBeanMethods = false) @Import(BaseConfiguration.class) static class CustomRegistryConfiguration { diff --git a/spring-boot-project/spring-boot-dependencies/build.gradle b/spring-boot-project/spring-boot-dependencies/build.gradle index 5967e2eb44..ea0b1de51b 100644 --- a/spring-boot-project/spring-boot-dependencies/build.gradle +++ b/spring-boot-project/spring-boot-dependencies/build.gradle @@ -1182,7 +1182,7 @@ bom { ] } } - library("Micrometer", "1.3.7") { + library("Micrometer", "1.5.0-SNAPSHOT") { group("io.micrometer") { modules = [ "micrometer-registry-stackdriver" { diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc index 78a269b984..a4ee216687 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/production-ready-features.adoc @@ -1791,7 +1791,7 @@ Spring Boot registers the following core metrics when applicable: ** Number of classes loaded/unloaded * CPU metrics * File descriptor metrics -* Kafka consumer metrics (<> should be enabled) +* Kafka consumer metrics * Log4j2 metrics: record the number of events logged to Log4j2 at each level * Logback metrics: record the number of events logged to Logback at each level * Uptime metrics: report a gauge for uptime and a fixed gauge representing the application's absolute start time