From 80ebe9a3ddf365ed26c684984409edcebc5a6ad3 Mon Sep 17 00:00:00 2001 From: Tommy Ludwig <8924140+shakuzen@users.noreply.github.com> Date: Fri, 25 Oct 2019 14:31:17 +0900 Subject: [PATCH] Remove micrometer-spring-legacy module We will no longer publish or support the module in versions going forward. Users should instead use a supported version of Spring Boot to use Micrometer with Spring. Resolves #1662 --- config/checkstyle/checkstyle-suppressions.xml | 1 - micrometer-spring-legacy/README.md | 14 - micrometer-spring-legacy/build.gradle | 88 ---- .../MetricsEnvironmentPostProcessor.java | 63 --- .../java/io/micrometer/spring/TimedUtils.java | 45 -- .../async/ThreadPoolTaskExecutorMetrics.java | 109 ----- .../async/TimedThreadPoolTaskExecutor.java | 84 ---- ...mpositeMeterRegistryAutoConfiguration.java | 35 -- .../CompositeMeterRegistryConfiguration.java | 60 --- .../JvmMetricsAutoConfiguration.java | 71 --- .../Log4J2MetricsAutoConfiguration.java | 51 -- .../LogbackMetricsAutoConfiguration.java | 80 --- .../MeterRegistryConfigurer.java | 101 ---- .../MeterRegistryCustomizer.java | 40 -- .../MeterRegistryPostProcessor.java | 90 ---- .../spring/autoconfigure/MeterValue.java | 104 ---- .../MetricsAutoConfiguration.java | 131 ----- .../autoconfigure/MetricsProperties.java | 231 --------- .../NoOpMeterRegistryConfiguration.java | 39 -- .../OnlyOnceLoggingDenyMeterFilter.java | 59 --- .../autoconfigure/PropertiesMeterFilter.java | 137 ------ .../ServiceLevelAgreementBoundary.java | 67 --- .../SystemMetricsAutoConfiguration.java | 66 --- ...acheMeterBinderProvidersConfiguration.java | 85 ---- .../cache/CacheMetricsAutoConfiguration.java | 43 -- .../CacheMetricsRegistrarConfiguration.java | 115 ----- .../export/StringToDurationConverter.java | 77 --- .../export/StringToTimeUnitConverter.java | 34 -- ...pOpticsMetricsExportAutoConfiguration.java | 68 --- .../export/appoptics/AppOpticsProperties.java | 103 ---- .../AppOpticsPropertiesConfigAdapter.java | 50 -- .../AtlasMetricsExportAutoConfiguration.java | 64 --- .../export/atlas/AtlasProperties.java | 123 ----- .../atlas/AtlasPropertiesConfigAdapter.java | 106 ---- ...MonitorMetricsExportAutoConfiguration.java | 80 --- .../azuremonitor/AzureMonitorProperties.java | 42 -- .../AzureMonitorPropertiesConfigAdapter.java | 37 -- ...DatadogMetricsExportAutoConfiguration.java | 63 --- .../export/datadog/DatadogProperties.java | 97 ---- .../DatadogPropertiesConfigAdapter.java | 58 --- ...natraceMetricsExportAutoConfiguration.java | 63 --- .../export/dynatrace/DynatraceProperties.java | 96 ---- .../DynatracePropertiesConfigAdapter.java | 58 --- ...ElasticMetricsExportAutoConfiguration.java | 64 --- .../export/elastic/ElasticProperties.java | 148 ------ .../ElasticPropertiesConfigAdapter.java | 77 --- ...GangliaMetricsExportAutoConfiguration.java | 63 --- .../export/ganglia/GangliaProperties.java | 150 ------ .../GangliaPropertiesConfigAdapter.java | 91 ---- ...raphiteMetricsExportAutoConfiguration.java | 64 --- .../export/graphite/GraphiteProperties.java | 137 ------ .../GraphitePropertiesConfigAdapter.java | 83 ---- .../HumioMetricsExportAutoConfiguration.java | 64 --- .../export/humio/HumioProperties.java | 104 ---- .../humio/HumioPropertiesConfigAdapter.java | 49 -- .../InfluxMetricsExportAutoConfiguration.java | 63 --- .../export/influx/InfluxProperties.java | 179 ------- .../influx/InfluxPropertiesConfigAdapter.java | 88 ---- .../JmxMetricsExportAutoConfiguration.java | 63 --- .../export/jmx/JmxProperties.java | 56 --- .../jmx/JmxPropertiesConfigAdapter.java | 48 -- .../KairosMetricsExportAutoConfiguration.java | 65 --- .../export/kairos/KairosProperties.java | 69 --- .../kairos/KairosPropertiesConfigAdapter.java | 47 -- ...LoggingMetricsExportAutoConfiguration.java | 65 --- .../logging/LoggingRegistryProperties.java | 42 -- ...oggingRegistryPropertiesConfigAdapter.java | 36 -- ...ewRelicMetricsExportAutoConfiguration.java | 64 --- .../export/newrelic/NewRelicProperties.java | 69 --- .../NewRelicPropertiesConfigAdapter.java | 47 -- .../autoconfigure/export/package-info.java | 21 - ...metheusMetricsExportAutoConfiguration.java | 158 ------ .../prometheus/PrometheusProperties.java | 160 ------ .../PrometheusPropertiesConfigAdapter.java | 51 -- .../properties/PropertiesConfigAdapter.java | 56 --- .../properties/StepRegistryProperties.java | 108 ----- .../StepRegistryPropertiesConfigAdapter.java | 75 --- ...ignalFxMetricsExportAutoConfiguration.java | 63 --- .../export/signalfx/SignalFxProperties.java | 86 ---- .../SignalFxPropertiesConfigAdapter.java | 48 -- .../SimpleMetricsExportAutoConfiguration.java | 61 --- .../export/simple/SimpleProperties.java | 59 --- .../simple/SimplePropertiesConfigAdapter.java | 50 -- ...kdriverMetricsExportAutoConfiguration.java | 79 --- .../stackdriver/StackdriverProperties.java | 74 --- .../StackdriverPropertiesConfigAdapter.java | 37 -- .../StatsdMetricsExportAutoConfiguration.java | 69 --- .../export/statsd/StatsdProperties.java | 149 ------ .../statsd/StatsdPropertiesConfigAdapter.java | 87 ---- ...vefrontMetricsExportAutoConfiguration.java | 70 --- .../export/wavefront/WavefrontProperties.java | 141 ------ .../WavefrontPropertiesConfigAdapter.java | 76 --- ...ataSourcePoolMetricsAutoConfiguration.java | 113 ----- .../JerseyServerMetricsAutoConfiguration.java | 126 ----- .../KafkaMetricsAutoConfiguration.java | 54 --- .../HibernateMetricsAutoConfiguration.java | 110 ----- .../RestTemplateMetricsAutoConfiguration.java | 124 ----- .../jetty/JettyMetricsAutoConfiguration.java | 51 -- .../WebMvcMetricsAutoConfiguration.java | 91 ---- .../TomcatMetricsAutoConfiguration.java | 51 -- .../cache/CacheMeterBinderProvider.java | 43 -- .../spring/cache/CacheMetricsRegistrar.java | 118 ----- .../CaffeineCacheMeterBinderProvider.java | 38 -- .../cache/ConcurrentMapCacheMetrics.java | 172 ------- .../EhCache2CacheMeterBinderProvider.java | 38 -- .../HazelcastCacheMeterBinderProvider.java | 40 -- .../cache/JCacheCacheMeterBinderProvider.java | 38 -- .../micrometer/spring/cache/package-info.java | 21 - .../PrometheusPushGatewayManager.java | 200 -------- .../prometheus/PrometheusScrapeEndpoint.java | 59 --- .../PrometheusScrapeMvcEndpoint.java | 32 -- .../integration/SpringIntegrationMetrics.java | 143 ------ .../spring/jdbc/DataSourcePoolMetrics.java | 60 --- .../scheduling/ScheduledMethodMetrics.java | 121 ----- .../io/micrometer/spring/util/LambdaSafe.java | 457 ------------------ ...faultRestTemplateExchangeTagsProvider.java | 45 -- .../MetricsClientHttpRequestInterceptor.java | 127 ----- .../client/MetricsRestTemplateCustomizer.java | 74 --- .../web/client/RestTemplateExchangeTags.java | 170 ------- .../RestTemplateExchangeTagsProvider.java | 45 -- .../spring/web/client/package-info.java | 21 - .../JettyServerThreadPoolMetricsBinder.java | 75 --- .../servlet/DefaultWebMvcTagsProvider.java | 63 --- .../web/servlet/WebMvcMetricsFilter.java | 178 ------- .../spring/web/servlet/WebMvcTags.java | 187 ------- .../web/servlet/WebMvcTagsProvider.java | 61 --- .../web/tomcat/TomcatMetricsBinder.java | 82 ---- ...itional-spring-configuration-metadata.json | 106 ---- .../main/resources/META-INF/spring.factories | 39 -- .../micrometer/spring/CountedAspectTest.java | 180 ------- .../io/micrometer/spring/TimedAspectTest.java | 200 -------- .../io/micrometer/spring/TimedUtilsTest.java | 89 ---- ...oolTaskExecutorMetricsIntegrationTest.java | 73 --- .../ThreadPoolTaskExecutorMetricsTest.java | 89 ---- ...onfigurationDefaultSimpleRegistryTest.java | 43 -- ...figurationExistingPrimaryRegistryTest.java | 53 -- ...erRegistryConfigurationNoRegistryTest.java | 47 -- ...gistryConfigurationSingleRegistryTest.java | 41 -- ...mpositeMeterRegistryConfigurationTest.java | 57 --- .../CompositeRegistryDoubleCountingTest.java | 82 ---- .../JvmMetricsAutoConfigurationTest.java | 166 ------- .../Log4J2MetricsAutoConfigurationTest.java | 96 ---- .../LogbackMetricsAutoConfigurationTest.java | 97 ---- .../MeterRegistryCustomizerTest.java | 70 --- .../spring/autoconfigure/MeterValueTest.java | 75 --- ...tricsAutoConfigurationIntegrationTest.java | 149 ------ .../MetricsAutoConfigurationTest.java | 218 --------- .../PrometheusEndpointIntegrationTest.java | 54 --- .../PropertiesMeterFilterIntegrationTest.java | 64 --- .../PropertiesMeterFilterTest.java | 321 ------------ .../ServiceLevelAgreementBoundaryTest.java | 48 -- .../SingleRegistryDoubleCountingTest.java | 75 --- .../SystemMetricsAutoConfigurationTest.java | 159 ------ .../CacheMetricsAutoConfigurationTest.java | 89 ---- .../export/StringToDurationConverterTest.java | 43 -- ...icsMetricsExportAutoConfigurationTest.java | 152 ------ .../AppOpticsPropertiesConfigAdapterTest.java | 64 --- .../appoptics/AppOpticsPropertiesTest.java | 39 -- ...mioMetricsExportAutoConfigurationTest.java | 69 --- ...rosMetricsExportAutoConfigurationTest.java | 138 ------ .../KairosPropertiesConfigAdapterTest.java | 64 --- .../export/kairos/KairosPropertiesTest.java | 42 -- ...eusMetricsExportAutoConfigurationTest.java | 176 ------- ...epRegistryPropertiesConfigAdapterTest.java | 82 ---- .../StepRegistryPropertiesTest.java | 43 -- ...erMetricsExportAutoConfigurationTests.java | 97 ---- ...ourcePoolMetricsAutoConfigurationTest.java | 100 ---- ...seyServerMetricsAutoConfigurationTest.java | 190 -------- .../KafkaMetricsAutoConfigurationTest.java | 91 ---- ...HibernateMetricsAutoConfigurationTest.java | 103 ---- .../autoconfigure/web/TestController.java | 45 -- ...tricsAutoConfigurationIntegrationTest.java | 146 ------ ...tTemplateMetricsAutoConfigurationTest.java | 100 ---- .../JettyMetricsAutoConfigurationTest.java | 111 ----- .../WebMvcMetricsAutoConfigurationTest.java | 177 ------- .../TomcatMetricsAutoConfigurationTest.java | 137 ------ ...rrentMapCacheMetricsCompatibilityTest.java | 47 -- .../PrometheusPushGatewayManagerTest.java | 214 -------- .../SpringIntegrationMetricsTest.java | 87 ---- .../jdbc/DataSourcePoolMetricsHikariTest.java | 78 --- .../jdbc/DataSourcePoolMetricsTest.java | 83 ---- .../ExecutorServiceMetricsTest.java | 55 --- .../ScheduledMethodMetricsTest.java | 123 ----- .../spring/security/SpringSecurityTest.java | 90 ---- ...tRestTemplateExchangeTagsProviderTest.java | 138 ------ .../MetricsRestTemplateCustomizerTest.java | 108 ----- .../client/RestTemplateExchangeTagsTest.java | 111 ----- .../server/JerseyServerMetricsTest.java | 90 ---- .../WebMvcMetricsFilterAutoTimedTest.java | 92 ---- ...tricsFilterCustomExceptionHandlerTest.java | 138 ------ .../web/servlet/WebMvcMetricsFilterTest.java | 436 ----------------- .../spring/web/servlet/WebMvcTagsTest.java | 132 ----- .../src/test/resources/logback.xml | 31 -- .../src/main/resources/application.yml | 46 -- .../build.gradle | 11 +- .../boot2}/samples/AppOpticsSample.java | 4 +- .../boot2}/samples/AtlasSample.java | 4 +- .../boot2}/samples/AzureMonitorSample.java | 4 +- .../boot2}/samples/DatadogSample.java | 4 +- .../boot2}/samples/DynatraceSample.java | 4 +- .../boot2}/samples/ElasticSample.java | 4 +- .../boot2}/samples/GangliaSample.java | 4 +- .../boot2}/samples/HumioSample.java | 4 +- .../boot2}/samples/InfluxSample.java | 4 +- .../micrometer/boot2}/samples/JmxSample.java | 4 +- .../boot2}/samples/KairosSample.java | 4 +- .../boot2}/samples/LoggingRegistrySample.java | 4 +- .../boot2}/samples/NewRelicSample.java | 4 +- .../samples/PrometheusPushgatewaySample.java | 4 +- .../boot2}/samples/PrometheusSample.java | 4 +- .../boot2}/samples/SignalFxSample.java | 4 +- .../boot2}/samples/SimpleSample.java | 4 +- .../boot2}/samples/StackdriverSample.java | 4 +- .../boot2}/samples/StatsdDatadogSample.java | 4 +- .../boot2}/samples/StatsdEtsySample.java | 6 +- .../boot2}/samples/StatsdTelegrafSample.java | 4 +- .../boot2}/samples/WavefrontSample.java | 4 +- .../samples/components/PersonController.java | 2 +- .../SpringIntegrationApplication.java | 6 +- .../src/main/resources/.gitignore | 0 .../main/resources/application-appoptics.yml | 2 +- .../src/main/resources/application-atlas.yml | 0 .../resources/application-azuremonitor.yml | 0 .../main/resources/application-datadog.yml | 0 .../main/resources/application-dynatrace.yml | 0 .../main/resources/application-elastic.yml | 0 .../main/resources/application-ganglia.yml | 0 .../src/main/resources/application-humio.yml | 0 .../src/main/resources/application-influx.yml | 0 .../src/main/resources/application-jmx.yml | 0 .../src/main/resources/application-kairos.yml | 0 .../main/resources/application-logging.yml | 0 .../application-prometheus-pushgateway.yml | 21 +- .../main/resources/application-prometheus.yml | 3 +- .../main/resources/application-signalfx.yml | 0 .../resources/application-stackdriver.yml | 0 .../resources/application-statsd-datadog.yml | 0 .../resources/application-statsd-etsy.yml | 0 .../resources/application-statsd-telegraf.yml | 0 .../main/resources/application-wavefront.yml | 0 .../src/main}/resources/application.yml | 16 +- .../src/main/resources/logback.xml | 0 scripts/sync-to-maven-central.sh | 3 +- settings.gradle | 3 +- 244 files changed, 81 insertions(+), 17693 deletions(-) delete mode 100644 micrometer-spring-legacy/README.md delete mode 100644 micrometer-spring-legacy/build.gradle delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/MetricsEnvironmentPostProcessor.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/TimedUtils.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetrics.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/async/TimedThreadPoolTaskExecutor.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/JvmMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/Log4J2MetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/LogbackMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryConfigurer.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryCustomizer.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryPostProcessor.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterValue.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MetricsProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/NoOpMeterRegistryConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/OnlyOnceLoggingDenyMeterFilter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/ServiceLevelAgreementBoundary.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/SystemMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMeterBinderProvidersConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsRegistrarConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/StringToDurationConverter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/StringToTimeUnitConverter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatraceMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatraceProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatracePropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphiteMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphiteProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphitePropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingRegistryProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingRegistryPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/package-info.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/PropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimpleMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimpleProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimplePropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontMetricsExportAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontProperties.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontPropertiesConfigAdapter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/jdbc/DataSourcePoolMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/jersey/JerseyServerMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/kafka/consumer/KafkaMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/orm/jpa/HibernateMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/jetty/JettyMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/servlet/WebMvcMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/tomcat/TomcatMetricsAutoConfiguration.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CacheMeterBinderProvider.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CacheMetricsRegistrar.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CaffeineCacheMeterBinderProvider.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/ConcurrentMapCacheMetrics.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/EhCache2CacheMeterBinderProvider.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/HazelcastCacheMeterBinderProvider.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/JCacheCacheMeterBinderProvider.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/package-info.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusPushGatewayManager.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusScrapeEndpoint.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusScrapeMvcEndpoint.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/integration/SpringIntegrationMetrics.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/jdbc/DataSourcePoolMetrics.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/scheduling/ScheduledMethodMetrics.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/util/LambdaSafe.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/DefaultRestTemplateExchangeTagsProvider.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/MetricsClientHttpRequestInterceptor.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/MetricsRestTemplateCustomizer.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/RestTemplateExchangeTags.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/RestTemplateExchangeTagsProvider.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/package-info.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/jetty/JettyServerThreadPoolMetricsBinder.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/DefaultWebMvcTagsProvider.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilter.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcTags.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcTagsProvider.java delete mode 100644 micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/tomcat/TomcatMetricsBinder.java delete mode 100644 micrometer-spring-legacy/src/main/resources/META-INF/additional-spring-configuration-metadata.json delete mode 100644 micrometer-spring-legacy/src/main/resources/META-INF/spring.factories delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/CountedAspectTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/TimedAspectTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/TimedUtilsTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetricsIntegrationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetricsTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationDefaultSimpleRegistryTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationExistingPrimaryRegistryTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationNoRegistryTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationSingleRegistryTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeRegistryDoubleCountingTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/JvmMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/Log4J2MetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/LogbackMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MeterRegistryCustomizerTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MeterValueTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MetricsAutoConfigurationIntegrationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PrometheusEndpointIntegrationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilterIntegrationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilterTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/ServiceLevelAgreementBoundaryTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/SingleRegistryDoubleCountingTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/SystemMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/StringToDurationConverterTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsMetricsExportAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapterTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/humio/HumioMetricsExportAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapterTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusMetricsExportAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesConfigAdapterTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverMetricsExportAutoConfigurationTests.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/jdbc/DataSourcePoolMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/jersey/JerseyServerMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/kafka/consumer/KafkaMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/orm/jpa/HibernateMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/TestController.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfigurationIntegrationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/jetty/JettyMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/servlet/WebMvcMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/tomcat/TomcatMetricsAutoConfigurationTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/cache/ConcurrentMapCacheMetricsCompatibilityTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/export/prometheus/PrometheusPushGatewayManagerTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/integration/SpringIntegrationMetricsTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/jdbc/DataSourcePoolMetricsHikariTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/jdbc/DataSourcePoolMetricsTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/scheduling/ExecutorServiceMetricsTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/scheduling/ScheduledMethodMetricsTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/security/SpringSecurityTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/DefaultRestTemplateExchangeTagsProviderTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/MetricsRestTemplateCustomizerTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/RestTemplateExchangeTagsTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/jersey2/server/JerseyServerMetricsTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterAutoTimedTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterCustomExceptionHandlerTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterTest.java delete mode 100644 micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcTagsTest.java delete mode 100644 micrometer-spring-legacy/src/test/resources/logback.xml delete mode 100644 samples/micrometer-samples-boot1/src/main/resources/application.yml rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/build.gradle (80%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/AppOpticsSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/AtlasSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/AzureMonitorSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/DatadogSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/DynatraceSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/ElasticSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/GangliaSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/HumioSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/InfluxSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/JmxSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/KairosSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/LoggingRegistrySample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/NewRelicSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/PrometheusPushgatewaySample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/PrometheusSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/SignalFxSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/SimpleSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/StackdriverSample.java (92%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/StatsdDatadogSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/StatsdEtsySample.java (92%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/StatsdTelegrafSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/WavefrontSample.java (91%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/components/PersonController.java (98%) rename samples/{micrometer-samples-boot1/src/main/java/io/micrometer/boot1 => micrometer-samples-boot2/src/main/java/io/micrometer/boot2}/samples/integration/SpringIntegrationApplication.java (92%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/.gitignore (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-appoptics.yml (97%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-atlas.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-azuremonitor.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-datadog.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-dynatrace.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-elastic.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-ganglia.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-humio.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-influx.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-jmx.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-kairos.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-logging.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-prometheus-pushgateway.yml (70%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-prometheus.yml (95%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-signalfx.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-stackdriver.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-statsd-datadog.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-statsd-etsy.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-statsd-telegraf.yml (100%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/application-wavefront.yml (100%) rename {micrometer-spring-legacy/src/test => samples/micrometer-samples-boot2/src/main}/resources/application.yml (90%) rename samples/{micrometer-samples-boot1 => micrometer-samples-boot2}/src/main/resources/logback.xml (100%) diff --git a/config/checkstyle/checkstyle-suppressions.xml b/config/checkstyle/checkstyle-suppressions.xml index c1bb51b877..2eaf847a00 100644 --- a/config/checkstyle/checkstyle-suppressions.xml +++ b/config/checkstyle/checkstyle-suppressions.xml @@ -7,5 +7,4 @@ - diff --git a/micrometer-spring-legacy/README.md b/micrometer-spring-legacy/README.md deleted file mode 100644 index ecc3c19d41..0000000000 --- a/micrometer-spring-legacy/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# Spring Bindings for Micrometer - -## Deprecation Notice -**Now that Spring Boot 1.x support is End Of Life, this module is deprecated and will be removed. Upgrade to Spring Boot 2.x to continue using supported versions of Micrometer with Spring.** - ---- - -This project contains Spring-specific configurations and support that help -you to create a well-instrumented Spring 4.x or Spring Boot 1.x application with a -minimum amount of boilerplate. - -As of Spring 5 / Spring Boot 2, a dependency on this module is -unnecessary, as the Spring Boot metrics system is based on Micrometer -and all necessary configuration is present in Spring Boot itself. diff --git a/micrometer-spring-legacy/build.gradle b/micrometer-spring-legacy/build.gradle deleted file mode 100644 index d65ccff24b..0000000000 --- a/micrometer-spring-legacy/build.gradle +++ /dev/null @@ -1,88 +0,0 @@ -plugins { - id "io.spring.dependency-management" version "1.0.3.RELEASE" -} - -apply plugin: 'nebula.optional-base' -apply plugin: 'nebula.facet' - -dependencyManagement { - imports { - mavenBom 'org.springframework.boot:spring-boot-dependencies:1.5.17.RELEASE' - } - dependencies { - dependency 'org.assertj:assertj-core:3.8.0' - dependency 'io.projectreactor:reactor-core:3.1.4.RELEASE' - } -} - -repositories { - // for spring-cloud-test-support - maven { url 'https://repo.spring.io/libs-milestone' } -} - -dependencies { - compile project(':micrometer-core') - - compile 'org.springframework:spring-beans', optional - compile 'org.springframework.boot:spring-boot', optional - compile 'org.springframework.boot:spring-boot-actuator', optional - compile 'org.springframework.boot:spring-boot-starter-aop', optional - compile 'org.springframework.boot:spring-boot-starter-cache', optional - compile 'org.springframework.boot:spring-boot-starter-security', optional - compile 'org.springframework:spring-webmvc', optional - compile 'org.springframework:spring-web', optional - compile 'javax.servlet:javax.servlet-api:3.1.0', optional - compile 'org.aspectj:aspectjweaver:1.8.+', optional - compile 'io.prometheus:simpleclient_pushgateway:latest.release', optional - - ['atlas', 'azure-monitor', 'prometheus', 'datadog', 'elastic', 'ganglia', 'graphite', 'jmx', 'influx', 'statsd', 'new-relic', 'cloudwatch', 'cloudwatch2', 'signalfx', 'wavefront', 'dynatrace', 'humio', 'appoptics', 'kairos', 'stackdriver'].each { sys -> - compile project(":micrometer-registry-$sys"), optional - } - - compile project(":micrometer-jersey2"), optional - - compile 'org.springframework.integration:spring-integration-core', optional - - compile 'com.hazelcast:hazelcast-spring', optional - - annotationProcessor 'org.springframework.boot:spring-boot-autoconfigure-processor' - - // to validate auto-completion on configuration properties - annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor' - - testCompile project(':micrometer-test') - - testCompile 'org.springframework.boot:spring-boot-starter-web' - testCompile 'org.springframework.boot:spring-boot-actuator' - testCompile 'org.springframework.boot:spring-boot-starter-test' - testCompile 'org.springframework.boot:spring-boot-starter-jersey' - - // for testing DataSource metrics - testCompile 'org.hsqldb:hsqldb' - testCompile 'org.springframework.boot:spring-boot-starter-jdbc' - testCompile 'com.zaxxer:HikariCP' - - // for use in mock servers - testCompile 'org.apache.tomcat.embed:tomcat-embed-core' - - // for classpath exclusion in tests - testCompile 'org.springframework.cloud:spring-cloud-test-support:2.+' - - testRuntime 'org.apache.httpcomponents:httpclient:4.5.+' - - testCompile 'org.springframework.integration:spring-integration-java-dsl' - testCompile 'org.springframework.integration:spring-integration-ws' - testCompile 'org.springframework.integration:spring-integration-xml' - - testCompile 'org.springframework.security:spring-security-test' - - testCompile 'io.github.resilience4j:resilience4j-retry:latest.release' - - // required for jdk 9 testing - testRuntime 'javax.xml.bind:jaxb-api:2.3.0' - testRuntime 'javax.activation:activation:1.1.1' - testRuntime 'com.sun.xml.messaging.saaj:saaj-impl:1.4.0' - - testImplementation 'junit:junit:4.12' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:latest.release' -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/MetricsEnvironmentPostProcessor.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/MetricsEnvironmentPostProcessor.java deleted file mode 100644 index 22ef2806b4..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/MetricsEnvironmentPostProcessor.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.env.EnvironmentPostProcessor; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.MapPropertySource; -import org.springframework.core.env.MutablePropertySources; -import org.springframework.core.env.PropertySource; - -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * @author Dave Syer - */ -public class MetricsEnvironmentPostProcessor implements EnvironmentPostProcessor { - - private static final Log log = LogFactory.getLog(MetricsEnvironmentPostProcessor.class); - - @Override - public void postProcessEnvironment(ConfigurableEnvironment environment, - SpringApplication application) { - // Make spring AOP default to target class so RestTemplates can be customized, - // @Scheduled instrumented - log.debug("Setting 'spring.aop.proxyTargetClass=true' to make spring AOP default to target class so RestTemplates can be customized"); - addDefaultProperty(environment, "spring.aop.proxyTargetClass", "true"); - } - - private void addDefaultProperty(ConfigurableEnvironment environment, String name, - String value) { - MutablePropertySources sources = environment.getPropertySources(); - Map map = null; - if (sources.contains("defaultProperties")) { - PropertySource source = sources.get("defaultProperties"); - if (source instanceof MapPropertySource) { - map = ((MapPropertySource) source).getSource(); - } - } else { - map = new LinkedHashMap<>(); - sources.addLast(new MapPropertySource("defaultProperties", map)); - } - if (map != null) { - map.put(name, value); - } - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/TimedUtils.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/TimedUtils.java deleted file mode 100644 index c5902baeb0..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/TimedUtils.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring; - -import io.micrometer.core.annotation.Timed; -import io.micrometer.core.annotation.TimedSet; -import org.springframework.core.annotation.AnnotationUtils; - -import java.lang.reflect.AnnotatedElement; -import java.util.Arrays; -import java.util.Collections; -import java.util.Set; -import java.util.stream.Collectors; - -public final class TimedUtils { - private TimedUtils() { - } - - public static Set findTimedAnnotations(AnnotatedElement element) { - Timed t = AnnotationUtils.findAnnotation(element, Timed.class); - //noinspection ConstantConditions - if (t != null) - return Collections.singleton(t); - - TimedSet ts = AnnotationUtils.findAnnotation(element, TimedSet.class); - if (ts != null) { - return Arrays.stream(ts.value()).collect(Collectors.toSet()); - } - - return Collections.emptySet(); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetrics.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetrics.java deleted file mode 100644 index f80167a011..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetrics.java +++ /dev/null @@ -1,109 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.async; - -import io.micrometer.core.instrument.FunctionCounter; -import io.micrometer.core.instrument.Gauge; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.NonNullFields; -import io.micrometer.core.lang.Nullable; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - -import java.util.concurrent.Executor; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.ThreadPoolExecutor; - -import static java.util.Arrays.asList; - -/** - * Monitors the status of {@link ThreadPoolTaskExecutor} pools. Does not record timings on operations executed in the - * {@link ExecutorService}, as this requires the instance to be wrapped. Timings are provided separately by wrapping - * the executor service with {@link TimedThreadPoolTaskExecutor}. - * - * @author David Held - */ -@NonNullApi -@NonNullFields -public class ThreadPoolTaskExecutorMetrics implements MeterBinder { - private final String name; - private final Iterable tags; - - @Nullable - private final ThreadPoolTaskExecutor executor; - - public ThreadPoolTaskExecutorMetrics(ThreadPoolTaskExecutor executor, String name, Iterable tags) { - this.name = name; - this.tags = tags; - this.executor = executor; - } - - /** - * Returns a new {@link ThreadPoolTaskExecutor} with recorded metrics. - * - * @param registry The registry to bind metrics to. - * @param name The name prefix of the metrics. - * @param tags Tags to apply to all recorded metrics. - * @return The instrumented executor, proxied. - */ - public static ThreadPoolTaskExecutor monitor(MeterRegistry registry, String name, Iterable tags) { - return new TimedThreadPoolTaskExecutor(registry, name, tags); - } - - /** - * Returns a new {@link ThreadPoolTaskExecutor} with recorded metrics. - * - * @param registry The registry to bind metrics to. - * @param name The name prefix of the metrics. - * @param tags Tags to apply to all recorded metrics. - * @return The instrumented executor, proxied. - */ - public static Executor monitor(MeterRegistry registry, String name, Tag... tags) { - return monitor(registry, name, asList(tags)); - } - - @Override - public void bindTo(MeterRegistry registry) { - if (executor == null) { - return; - } - monitor(registry, executor.getThreadPoolExecutor()); - } - - private void monitor(MeterRegistry registry, ThreadPoolExecutor tp) { - FunctionCounter.builder(name + ".completed", tp, ThreadPoolExecutor::getCompletedTaskCount) - .tags(tags) - .description("The approximate total number of tasks that have completed execution") - .register(registry); - - Gauge.builder(name + ".active", tp, ThreadPoolExecutor::getActiveCount) - .tags(tags) - .description("The approximate number of threads that are actively executing tasks") - .register(registry); - - Gauge.builder(name + ".queued", tp, tpRef -> tpRef.getQueue().size()) - .tags(tags) - .description("The approximate number of threads that are queued for execution") - .register(registry); - - Gauge.builder(name + ".pool", tp, ThreadPoolExecutor::getPoolSize) - .tags(tags) - .description("The current number of threads in the pool") - .register(registry); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/async/TimedThreadPoolTaskExecutor.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/async/TimedThreadPoolTaskExecutor.java deleted file mode 100644 index 6fc9102303..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/async/TimedThreadPoolTaskExecutor.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.async; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Timer; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.NonNullFields; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.util.concurrent.ListenableFuture; - -import java.util.concurrent.Callable; -import java.util.concurrent.Future; - -/** - * A {@link ThreadPoolTaskExecutor} which is timed - * - * @author David Held - */ -@NonNullApi -@NonNullFields -public class TimedThreadPoolTaskExecutor extends ThreadPoolTaskExecutor { - private final MeterRegistry registry; - private final String name; - private final Iterable tags; - private final Timer timer; - - public TimedThreadPoolTaskExecutor(MeterRegistry registry, String name, Iterable tags) { - this.registry = registry; - this.name = name; - this.tags = tags; - this.timer = registry.timer(name, tags); - } - - @Override - public void initialize() { - super.initialize(); - new ThreadPoolTaskExecutorMetrics(this, name, tags).bindTo(registry); - } - - @Override - public void execute(Runnable task) { - super.execute(timer.wrap(task)); - } - - @Override - public void execute(Runnable task, long startTimeout) { - super.execute(timer.wrap(task), startTimeout); - } - - @Override - public Future submit(Callable task) { - return super.submit(timer.wrap(task)); - } - - @Override - public Future submit(Runnable task) { - return super.submit(timer.wrap(task)); - } - - @Override - public ListenableFuture submitListenable(Callable task) { - return super.submitListenable(timer.wrap(task)); - } - - @Override - public ListenableFuture submitListenable(Runnable task) { - return super.submitListenable(timer.wrap(task)); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryAutoConfiguration.java deleted file mode 100644 index 02e735a3c8..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryAutoConfiguration.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; - -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.context.annotation.Import; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for a - * {@link CompositeMeterRegistry}. - * - * @author Andy Wilkinson - */ -@Import({ NoOpMeterRegistryConfiguration.class, - CompositeMeterRegistryConfiguration.class }) -@ConditionalOnClass(CompositeMeterRegistry.class) -public class CompositeMeterRegistryAutoConfiguration { - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfiguration.java deleted file mode 100644 index 8ede476bd6..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfiguration.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate; -import org.springframework.boot.autoconfigure.condition.NoneNestedConditions; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Primary; - -import java.util.List; - -/** - * Configuration for a {@link CompositeMeterRegistry}. - * - * @author Andy Wilkinson - */ -@Conditional(CompositeMeterRegistryConfiguration.MultipleNonPrimaryMeterRegistriesCondition.class) -class CompositeMeterRegistryConfiguration { - - @Bean - @Primary - public CompositeMeterRegistry compositeMeterRegistry(Clock clock, List registries) { - return new CompositeMeterRegistry(clock, registries); - } - - static class MultipleNonPrimaryMeterRegistriesCondition extends NoneNestedConditions { - - MultipleNonPrimaryMeterRegistriesCondition() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @ConditionalOnMissingBean(MeterRegistry.class) - static class NoMeterRegistryCondition { - - } - - @ConditionalOnSingleCandidate(MeterRegistry.class) - static class SingleInjectableMeterRegistry { - - } - } -} \ No newline at end of file diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/JvmMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/JvmMetricsAutoConfiguration.java deleted file mode 100644 index e6c93333d7..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/JvmMetricsAutoConfiguration.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -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.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; -import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; -import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; -import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for JVM metrics. - * - * @author Jon Schneider - * @author Stephane Nicoll - * @since 1.1.0 - */ -@Configuration -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnClass(MeterRegistry.class) -@ConditionalOnBean(MeterRegistry.class) -@ConditionalOnProperty(value = "management.metrics.binders.jvm.enabled", matchIfMissing = true) -public class JvmMetricsAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public JvmGcMetrics jvmGcMetrics() { - return new JvmGcMetrics(); - } - - @Bean - @ConditionalOnMissingBean - public JvmMemoryMetrics jvmMemoryMetrics() { - return new JvmMemoryMetrics(); - } - - @Bean - @ConditionalOnMissingBean - public JvmThreadMetrics jvmThreadMetrics() { - return new JvmThreadMetrics(); - } - - @Bean - @ConditionalOnMissingBean - public ClassLoaderMetrics classLoaderMetrics() { - return new ClassLoaderMetrics(); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/Log4J2MetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/Log4J2MetricsAutoConfiguration.java deleted file mode 100644 index 9b7af4ab03..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/Log4J2MetricsAutoConfiguration.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -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.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.logging.Log4j2Metrics; -import org.apache.logging.log4j.core.LoggerContext; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for Log4J2 metrics. - * - * @author Jon Schneider - * @author Andy Wilkinson - * @since 1.1.0 - */ -@Configuration -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnClass({ Log4j2Metrics.class, LoggerContext.class }) -@ConditionalOnBean(MeterRegistry.class) -@ConditionalOnProperty(value = "management.metrics.binders.log4j2.enabled", matchIfMissing = true) -public class Log4J2MetricsAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public Log4j2Metrics log4j2Metrics() { - return new Log4j2Metrics(); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/LogbackMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/LogbackMetricsAutoConfiguration.java deleted file mode 100644 index 333df7a9ec..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/LogbackMetricsAutoConfiguration.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionMessage; -import org.springframework.boot.autoconfigure.condition.ConditionOutcome; -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.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.condition.SpringBootCondition; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.ConditionContext; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.type.AnnotatedTypeMetadata; - -import ch.qos.logback.classic.LoggerContext; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.logging.LogbackMetrics; -import io.micrometer.spring.autoconfigure.LogbackMetricsAutoConfiguration.LogbackLoggingCondition; -import org.slf4j.ILoggerFactory; -import org.slf4j.LoggerFactory; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for Logback metrics. - * - * @author Jon Schneider - * @author Stephane Nicoll - * @since 1.1.0 - */ -@Configuration -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnClass({ MeterRegistry.class, LoggerContext.class, LoggerFactory.class }) -@ConditionalOnBean(MeterRegistry.class) -@Conditional(LogbackLoggingCondition.class) -@ConditionalOnProperty(value = "management.metrics.binders.logback.enabled", matchIfMissing = true) -public class LogbackMetricsAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public LogbackMetrics logbackMetrics() { - return new LogbackMetrics(); - } - - static class LogbackLoggingCondition extends SpringBootCondition { - - @Override - public ConditionOutcome getMatchOutcome(ConditionContext context, - AnnotatedTypeMetadata metadata) { - ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory(); - ConditionMessage.Builder message = ConditionMessage - .forCondition("LogbackLoggingCondition"); - if (loggerFactory instanceof LoggerContext) { - return ConditionOutcome.match( - message.because("ILoggerFactory is a Logback LoggerContext")); - } - return ConditionOutcome - .noMatch(message.because("ILoggerFactory is an instance of " - + loggerFactory.getClass().getCanonicalName())); - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryConfigurer.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryConfigurer.java deleted file mode 100644 index 77229edef0..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryConfigurer.java +++ /dev/null @@ -1,101 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Metrics; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; -import io.micrometer.core.instrument.config.MeterFilter; - -import java.util.Collections; -import java.util.List; - -import org.springframework.beans.factory.ObjectProvider; - -/** - * Applies {@link MeterRegistryCustomizer customizers}, {@link MeterFilter filters}, - * {@link MeterBinder binders} and {@link Metrics#addRegistry - * global registration} to {@link MeterRegistry meter registries}. - * - * @author Jon Schneider - * @author Phillip Webb - */ -class MeterRegistryConfigurer { - - private final ObjectProvider>> customizers; - - private final ObjectProvider> filters; - - private final ObjectProvider> binders; - - private final boolean addToGlobalRegistry; - - private final boolean hasCompositeMeterRegistry; - - MeterRegistryConfigurer(ObjectProvider>> customizers, - ObjectProvider> filters, ObjectProvider> binders, - boolean addToGlobalRegistry, boolean hasCompositeMeterRegistry) { - this.customizers = customizers; - this.filters = filters; - this.binders = binders; - this.addToGlobalRegistry = addToGlobalRegistry; - this.hasCompositeMeterRegistry = hasCompositeMeterRegistry; - } - - void configure(MeterRegistry registry) { - // Customizers must be applied before binders, as they may add custom - // tags or alter timer or summary configuration. - customize(registry); - addFilters(registry); - if (!this.hasCompositeMeterRegistry - || registry instanceof CompositeMeterRegistry) { - addBinders(registry); - } - if (this.addToGlobalRegistry && registry != Metrics.globalRegistry) { - Metrics.addRegistry(registry); - } - } - - @SuppressWarnings("unchecked") - private void customize(MeterRegistry registry) { - // Customizers must be applied before binders, as they may add custom tags or alter - // timer or summary configuration. - for (MeterRegistryCustomizer customizer : getOrEmpty(this.customizers)) { - try { - customizer.customize(registry); - } catch (ClassCastException ignored) { - // This is essentially what LambdaSafe.callbacks(..).invoke(..) is doing - // in Spring Boot 2, just trapping ClassCastExceptions since the generic type - // has been erased by this point. - } - } - } - - private void addFilters(MeterRegistry registry) { - getOrEmpty(this.filters).forEach(registry.config()::meterFilter); - } - - private void addBinders(MeterRegistry registry) { - getOrEmpty(this.binders).forEach((binder) -> binder.bindTo(registry)); - } - - private List getOrEmpty(ObjectProvider> listProvider) { - List list = listProvider.getIfAvailable(); - return list != null ? list : Collections.emptyList(); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryCustomizer.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryCustomizer.java deleted file mode 100644 index 82da681f02..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryCustomizer.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.Meter; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.lang.NonNullApi; - -/** - * Callback interface that can be used to customize the primary auto-configured {@link MeterRegistry}. - *

- * Configurers are guaranteed to be applied before any {@link Meter} is registered with - * the registry. - * - * @author Jon Schneider - */ -@FunctionalInterface -@NonNullApi -public interface MeterRegistryCustomizer { - - /** - * Configure the given registry. - * - * @param registry the registry to configure - */ - void customize(M registry); -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryPostProcessor.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryPostProcessor.java deleted file mode 100644 index 92d09f6e6f..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterRegistryPostProcessor.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; -import io.micrometer.core.instrument.config.MeterFilter; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.beans.factory.config.BeanPostProcessor; -import org.springframework.context.ApplicationContext; - -import java.util.List; - -/** - * {@link BeanPostProcessor} that delegates to a lazily created - * {@link MeterRegistryConfigurer} to post-process {@link MeterRegistry} beans. - * - * @author Jon Schneider - * @author Phillip Webb - * @author Andy Wilkinson - */ -class MeterRegistryPostProcessor implements BeanPostProcessor { - - private final ObjectProvider> meterBinders; - - private final ObjectProvider> meterFilters; - - private final ObjectProvider>> meterRegistryCustomizers; - - private final ObjectProvider metricsProperties; - - private volatile MeterRegistryConfigurer configurer; - - private volatile ApplicationContext applicationContext; - - MeterRegistryPostProcessor( - ObjectProvider> meterBinders, - ObjectProvider> meterFilters, - ObjectProvider>> meterRegistryCustomizers, - ObjectProvider metricsProperties, - ApplicationContext applicationContext) { - this.meterBinders = meterBinders; - this.meterFilters = meterFilters; - this.meterRegistryCustomizers = meterRegistryCustomizers; - this.metricsProperties = metricsProperties; - this.applicationContext = applicationContext; - } - - @Override - public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { - return bean; - } - - @Override - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { - if (bean instanceof MeterRegistry) { - getConfigurer().configure((MeterRegistry) bean); - } - return bean; - } - - private MeterRegistryConfigurer getConfigurer() { - if (this.configurer == null) { - boolean hasCompositeMeterRegistry = this.applicationContext - .getBeanNamesForType(CompositeMeterRegistry.class, false, false) - .length != 0; - this.configurer = new MeterRegistryConfigurer(this.meterRegistryCustomizers, - this.meterFilters, this.meterBinders, - this.metricsProperties.getObject().isUseGlobalRegistry(), - hasCompositeMeterRegistry); - } - return this.configurer; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterValue.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterValue.java deleted file mode 100644 index 9cb214600d..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MeterValue.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -import io.micrometer.core.instrument.Meter; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; - -/** - * 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 - * {@link Duration} (applicable to only timers). - * - * @author Phillip Webb - */ -final class MeterValue { - - private static final StringToDurationConverter durationConverter = new StringToDurationConverter(); - - private final Object value; - - MeterValue(long value) { - this.value = value; - } - - MeterValue(Duration value) { - this.value = value; - } - - /** - * Return the underlying value of the SLA in form suitable to apply to the given meter - * type. - * @param meterType the meter type - * @return the value or {@code null} if the value cannot be applied - */ - public Long getValue(Meter.Type meterType) { - if (meterType == Meter.Type.DISTRIBUTION_SUMMARY) { - return getDistributionSummaryValue(); - } - if (meterType == Meter.Type.TIMER) { - return getTimerValue(); - } - return null; - } - - private Long getDistributionSummaryValue() { - if (this.value instanceof Long) { - return (Long) this.value; - } - return null; - } - - private Long getTimerValue() { - if (this.value instanceof Long) { - return TimeUnit.MILLISECONDS.toNanos((long) this.value); - } - if (this.value instanceof Duration) { - return ((Duration) this.value).toNanos(); - } - return null; - } - - /** - * Return a new {@link MeterValue} instance for the given String value. The value may - * contain a simple number, or a {@link Duration duration string}. - * @param value the source value - * @return a {@link MeterValue} instance - */ - public static MeterValue valueOf(String value) { - if (isNumber(value)) { - return new MeterValue(Long.parseLong(value)); - } - return new MeterValue(durationConverter.convert(value)); - } - - /** - * Return a new {@link MeterValue} instance for the given long value. - * @param value the source value - * @return a {@link MeterValue} instance - */ - public static MeterValue valueOf(long value) { - return new MeterValue(value); - } - - private static boolean isNumber(String value) { - return value.chars().allMatch(Character::isDigit); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MetricsAutoConfiguration.java deleted file mode 100644 index c4506c8048..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MetricsAutoConfiguration.java +++ /dev/null @@ -1,131 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import java.util.List; - -import io.micrometer.core.annotation.Timed; -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.instrument.binder.hystrix.HystrixMetricsBinder; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.spring.integration.SpringIntegrationMetrics; -import io.micrometer.spring.scheduling.ScheduledMethodMetrics; - -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration; -import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.condition.SearchStrategy; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; -import org.springframework.integration.config.EnableIntegrationManagement; -import org.springframework.integration.support.management.IntegrationManagementConfigurer; - -/** - * {@link EnableAutoConfiguration} for Micrometer-based metrics. - * - * @author Jon Schneider - */ -@Configuration -@ConditionalOnClass(Timed.class) -@EnableConfigurationProperties(MetricsProperties.class) -@AutoConfigureAfter({ - DataSourceAutoConfiguration.class, - RabbitAutoConfiguration.class, - CacheAutoConfiguration.class -}) -@AutoConfigureBefore(CompositeMeterRegistryAutoConfiguration.class) -public class MetricsAutoConfiguration { - @Bean - @ConditionalOnMissingBean - public Clock micrometerClock() { - return Clock.SYSTEM; - } - - @Bean - public static MeterRegistryPostProcessor meterRegistryPostProcessor( - ObjectProvider> meterBinders, - ObjectProvider> meterFilters, - ObjectProvider>> meterRegistryCustomizers, - ObjectProvider metricsProperties, - ApplicationContext applicationContext) { - return new MeterRegistryPostProcessor(meterBinders, meterFilters, meterRegistryCustomizers, metricsProperties, - applicationContext); - } - - @Bean - @Order(0) - public PropertiesMeterFilter propertiesMeterFilter(MetricsProperties properties) { - return new PropertiesMeterFilter(properties); - } - - @Bean - @ConditionalOnClass(name = "com.netflix.hystrix.strategy.HystrixPlugins") - @ConditionalOnProperty(value = "management.metrics.binders.hystrix.enabled", matchIfMissing = true) - public HystrixMetricsBinder hystrixMetricsBinder() { - return new HystrixMetricsBinder(); - } - - /** - * Replaced by built-in Micrometer integration starting in Spring Integration 5.0.2. - */ - @Configuration - @ConditionalOnClass(EnableIntegrationManagement.class) - static class MetricsIntegrationConfiguration { - - @Bean(name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME) - @ConditionalOnMissingBean(value = IntegrationManagementConfigurer.class, name = IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME, search = SearchStrategy.CURRENT) - public IntegrationManagementConfigurer integrationManagementConfigurer() { - IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer(); - configurer.setDefaultCountsEnabled(true); - configurer.setDefaultStatsEnabled(true); - return configurer; - } - - @Bean - public SpringIntegrationMetrics springIntegrationMetrics( - IntegrationManagementConfigurer configurer) { - return new SpringIntegrationMetrics(configurer); - } - } - - @Configuration - @ConditionalOnClass(name = "org.aspectj.lang.ProceedingJoinPoint") - @ConditionalOnProperty(value = "spring.aop.auto", havingValue = "true", matchIfMissing = true) - static class AopRequiredConfiguration { - - // If AOP is not enabled, scheduled interception will not work. - @Bean - @ConditionalOnProperty(value = "management.metrics.binders.scheduled.enabled", matchIfMissing = true) - @ConditionalOnMissingBean - public ScheduledMethodMetrics metricsSchedulingAspect(MeterRegistry registry) { - return new ScheduledMethodMetrics(registry); - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MetricsProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MetricsProperties.java deleted file mode 100644 index 7ee22084be..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/MetricsProperties.java +++ /dev/null @@ -1,231 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.util.HashMap; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * {@link ConfigurationProperties} for configuring Micrometer-based metrics. - * - * @author Jon Schneider - * @author Alexander Abramov - */ -@ConfigurationProperties("management.metrics") -public class MetricsProperties { - - private final Web web = new Web(); - private final Distribution distribution = new Distribution(); - - /** - * If {@code false}, the matching meter(s) are no-op. - */ - private final Map enable = new HashMap<>(); - - /** - * Common tags that are applied to every meter. - */ - private final Map tags = new LinkedHashMap<>(); - - /** - * Whether or not auto-configured MeterRegistry implementations should be bound to the - * global static registry on Metrics. For testing, set this to 'false' to maximize - * test independence. - */ - private boolean useGlobalRegistry = true; - - public boolean isUseGlobalRegistry() { - return this.useGlobalRegistry; - } - - public void setUseGlobalRegistry(boolean useGlobalRegistry) { - this.useGlobalRegistry = useGlobalRegistry; - } - - public Web getWeb() { - return this.web; - } - - public Map getEnable() { - return enable; - } - - public Map getTags() { - return this.tags; - } - - public Distribution getDistribution() { - return distribution; - } - - public static class Web { - - private final Client client = new Client(); - - private final Server server = new Server(); - - public Client getClient() { - return this.client; - } - - public Server getServer() { - return this.server; - } - - public static class Client { - /** - * Name of the metric for sent requests. - */ - private String requestsMetricName = "http.client.requests"; - - /** - * Maximum number of unique URI tag values allowed. After the max number of tag values is reached, - * metrics with additional tag values are denied by filter. - */ - private int maxUriTags = 100; - - public String getRequestsMetricName() { - return this.requestsMetricName; - } - - public void setRequestsMetricName(String requestsMetricName) { - this.requestsMetricName = requestsMetricName; - } - - public int getMaxUriTags() { - return maxUriTags; - } - - public void setMaxUriTags(int maxUriTags) { - this.maxUriTags = maxUriTags; - } - } - - public static class Server { - - /** - * Whether or not requests handled by Spring MVC or WebFlux should be - * automatically timed. If the number of time series emitted grows too large - * on account of request mapping timings, disable this and use 'Timed' on a - * per request mapping basis as needed. - */ - private boolean autoTimeRequests = true; - - /** - * Name of the metric for received requests. - */ - private String requestsMetricName = "http.server.requests"; - - /** - * Maximum number of unique URI tag values allowed. After the max number of - * tag values is reached, metrics with additional tag values are denied by - * filter. - */ - private int maxUriTags = 100; - - public boolean isAutoTimeRequests() { - return this.autoTimeRequests; - } - - public void setAutoTimeRequests(boolean autoTimeRequests) { - this.autoTimeRequests = autoTimeRequests; - } - - public String getRequestsMetricName() { - return this.requestsMetricName; - } - - public void setRequestsMetricName(String requestsMetricName) { - this.requestsMetricName = requestsMetricName; - } - - public int getMaxUriTags() { - return this.maxUriTags; - } - - public void setMaxUriTags(int maxUriTags) { - this.maxUriTags = maxUriTags; - } - - } - } - - public static class Distribution { - - /** - * Whether meter IDs starting with the specified name should publish percentile - * histograms. For monitoring systems that support aggregable percentile - * calculation based on a histogram, this can be set to true. For other systems, - * this has no effect. The longest match wins, the key `all` can also be used to - * configure all meters. - */ - private final Map percentilesHistogram = new LinkedHashMap<>(); - - /** - * Specific computed non-aggregable percentiles to ship to the backend for meter - * IDs starting-with the specified name. The longest match wins, the key `all` can - * also be used to configure all meters. - */ - private final Map percentiles = new LinkedHashMap<>(); - - /** - * Specific SLA boundaries for meter IDs starting-with the specified name. The - * longest match wins. Counters will be published for each specified boundary. - * Values can be specified as a long or as a Duration value (for timer meters, - * defaulting to ms if no unit specified). - */ - private final Map sla = new LinkedHashMap<>(); - - /** - * Minimum value that meter IDs starting-with the specified name are expected to - * observe. The longest match wins. Values can be specified as a long or as a - * Duration value (for timer meters, defaulting to ms if no unit specified). - */ - private final Map minimumExpectedValue = new LinkedHashMap<>(); - - /** - * Maximum value that meter IDs starting-with the specified name are expected to - * observe. The longest match wins. Values can be specified as a long or as a - * Duration value (for timer meters, defaulting to ms if no unit specified). - */ - private final Map maximumExpectedValue = new LinkedHashMap<>(); - - public Map getPercentilesHistogram() { - return this.percentilesHistogram; - } - - public Map getPercentiles() { - return this.percentiles; - } - - public Map getSla() { - return this.sla; - } - - public Map getMinimumExpectedValue() { - return this.minimumExpectedValue; - } - - public Map getMaximumExpectedValue() { - return this.maximumExpectedValue; - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/NoOpMeterRegistryConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/NoOpMeterRegistryConfiguration.java deleted file mode 100644 index 6a797b9621..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/NoOpMeterRegistryConfiguration.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; - -/** - * Configuration for a no-op meter registry when the context does not contain an - * auto-configured {@link MeterRegistry}. - * - * @author Andy Wilkinson - */ -@ConditionalOnBean(Clock.class) -@ConditionalOnMissingBean(MeterRegistry.class) -class NoOpMeterRegistryConfiguration { - - @Bean - public CompositeMeterRegistry noOpMeterRegistry(Clock clock) { - return new CompositeMeterRegistry(clock); - } -} \ No newline at end of file diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/OnlyOnceLoggingDenyMeterFilter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/OnlyOnceLoggingDenyMeterFilter.java deleted file mode 100644 index bd1e0845c1..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/OnlyOnceLoggingDenyMeterFilter.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.function.Supplier; - -import org.springframework.util.Assert; - -import io.micrometer.core.instrument.Meter; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.core.instrument.config.MeterFilterReply; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * {@link MeterFilter} to log only once a warning message and deny a {@link Meter} - * {@link Meter.Id}. - * - * @author Jon Schneider - * @author Dmytro Nosan - */ -public final class OnlyOnceLoggingDenyMeterFilter implements MeterFilter { - - private static final Log logger = LogFactory - .getLog(OnlyOnceLoggingDenyMeterFilter.class); - - private final AtomicBoolean alreadyWarned = new AtomicBoolean(false); - - private final Supplier message; - - public OnlyOnceLoggingDenyMeterFilter(Supplier message) { - Assert.notNull(message, "Message must not be null"); - this.message = message; - } - - @Override - public MeterFilterReply accept(Meter.Id id) { - if (logger.isWarnEnabled() - && this.alreadyWarned.compareAndSet(false, true)) { - logger.warn(this.message.get()); - } - return MeterFilterReply.DENY; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilter.java deleted file mode 100644 index e4267c8b2b..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilter.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.Meter; -import io.micrometer.core.instrument.Meter.Id; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.core.instrument.config.MeterFilterReply; -import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; -import io.micrometer.spring.autoconfigure.MetricsProperties.Distribution; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -import java.util.Arrays; -import java.util.Map; -import java.util.Objects; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -/** - * {@link MeterFilter} to apply settings from {@link MetricsProperties}. - * - * @author Jon Schneider - * @author Phillip Webb - * @author Stephane Nicoll - * @author Artsiom Yudovin - * @author Alexander Abramov - */ -public class PropertiesMeterFilter implements MeterFilter { - - private final MetricsProperties properties; - - private final MeterFilter mapFilter; - - public PropertiesMeterFilter(MetricsProperties properties) { - Assert.notNull(properties, "Properties must not be null"); - this.properties = properties; - this.mapFilter = createMapFilter(properties.getTags()); - } - - private static MeterFilter createMapFilter(Map tags) { - if (tags.isEmpty()) { - return new MeterFilter() { - }; - } - Tags commonTags = Tags.of(tags.entrySet().stream() - .map((entry) -> Tag.of(entry.getKey(), entry.getValue())) - .collect(Collectors.toList())); - return MeterFilter.commonTags(commonTags); - } - - @Override - public MeterFilterReply accept(Meter.Id id) { - boolean enabled = lookupWithFallbackToAll(this.properties.getEnable(), id, true); - return enabled ? MeterFilterReply.NEUTRAL : MeterFilterReply.DENY; - } - - @Override - public Id map(Id id) { - return this.mapFilter.map(id); - } - - @Override - public DistributionStatisticConfig configure(Meter.Id id, - DistributionStatisticConfig config) { - Distribution distribution = this.properties.getDistribution(); - return DistributionStatisticConfig.builder() - .percentilesHistogram( - lookupWithFallbackToAll(distribution.getPercentilesHistogram(), id, null)) - .percentiles( - lookupWithFallbackToAll(distribution.getPercentiles(), id, null)) - .sla(convertSla(id.getType(), lookup(distribution.getSla(), id, null))) - .minimumExpectedValue(convertMeterValue(id.getType(), - lookup(distribution.getMinimumExpectedValue(), id, null))) - .maximumExpectedValue(convertMeterValue(id.getType(), - lookup(distribution.getMaximumExpectedValue(), id, null))) - .build().merge(config); - } - - private long[] 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(); - return (converted.length != 0) ? converted : null; - } - - private Long convertMeterValue(Meter.Type meterType, String value) { - return (value != null) ? MeterValue.valueOf(value).getValue(meterType) : null; - } - - private T lookup(Map values, Id id, T defaultValue) { - if (values.isEmpty()) { - return defaultValue; - } - return doLookup(values, id, () -> defaultValue); - } - - private T lookupWithFallbackToAll(Map values, Id id, T defaultValue) { - if (values.isEmpty()) { - return defaultValue; - } - return doLookup(values, id, () -> values.getOrDefault("all", defaultValue)); - } - - private T doLookup(Map values, Id id, Supplier defaultValue) { - String name = id.getName(); - while (StringUtils.hasLength(name)) { - T result = values.get(name); - if (result != null) { - return result; - } - int lastDot = name.lastIndexOf('.'); - name = (lastDot != -1) ? name.substring(0, lastDot) : ""; - } - - return defaultValue.get(); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/ServiceLevelAgreementBoundary.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/ServiceLevelAgreementBoundary.java deleted file mode 100644 index d8d0b55f02..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/ServiceLevelAgreementBoundary.java +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.Meter; - -import java.time.Duration; - -/** - * 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). - * - * @author Phillip Webb - */ -public final class ServiceLevelAgreementBoundary { - - private final MeterValue value; - - ServiceLevelAgreementBoundary(MeterValue value) { - this.value = value; - } - - /** - * Return the underlying value of the SLA in form suitable to apply to the given meter - * type. - * @param meterType the meter type - * @return the value or {@code null} if the value cannot be applied - */ - public Long getValue(Meter.Type meterType) { - return this.value.getValue(meterType); - } - - /** - * Return a new {@link ServiceLevelAgreementBoundary} instance for the given long - * value. - * @param value the source value - * @return a {@link ServiceLevelAgreementBoundary} instance - */ - public static ServiceLevelAgreementBoundary valueOf(long value) { - return new ServiceLevelAgreementBoundary(MeterValue.valueOf(value)); - } - - /** - * Return a new {@link ServiceLevelAgreementBoundary} instance for the given long - * value. - * @param value the source value - * @return a {@link ServiceLevelAgreementBoundary} instance - */ - public static ServiceLevelAgreementBoundary valueOf(String value) { - return new ServiceLevelAgreementBoundary(MeterValue.valueOf(value)); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/SystemMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/SystemMetricsAutoConfiguration.java deleted file mode 100644 index 9dabf5a3e9..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/SystemMetricsAutoConfiguration.java +++ /dev/null @@ -1,66 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -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.condition.ConditionalOnProperty; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics; -import io.micrometer.core.instrument.binder.system.ProcessorMetrics; -import io.micrometer.core.instrument.binder.system.UptimeMetrics; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for system metrics. - * - * @author Jon Schneider - * @author Stephane Nicoll - * @since 1.1.0 - */ -@Configuration -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnClass(MeterRegistry.class) -@ConditionalOnBean(MeterRegistry.class) -public class SystemMetricsAutoConfiguration { - - @Bean - @ConditionalOnProperty(value = "management.metrics.binders.uptime.enabled", matchIfMissing = true) - @ConditionalOnMissingBean - public UptimeMetrics uptimeMetrics() { - return new UptimeMetrics(); - } - - @Bean - @ConditionalOnProperty(value = "management.metrics.binders.processor.enabled", matchIfMissing = true) - @ConditionalOnMissingBean - public ProcessorMetrics processorMetrics() { - return new ProcessorMetrics(); - } - - @Bean - @ConditionalOnProperty(name = "management.metrics.binders.files.enabled", matchIfMissing = true) - @ConditionalOnMissingBean - public FileDescriptorMetrics fileDescriptorMetrics() { - return new FileDescriptorMetrics(); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMeterBinderProvidersConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMeterBinderProvidersConfiguration.java deleted file mode 100644 index 2463b1e16d..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMeterBinderProvidersConfiguration.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2012-2019 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.autoconfigure.cache; - -import com.hazelcast.core.Hazelcast; -import com.hazelcast.spring.cache.HazelcastCache; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.spring.cache.*; -import net.sf.ehcache.Ehcache; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.cache.caffeine.CaffeineCache; -import org.springframework.cache.ehcache.EhCacheCache; -import org.springframework.cache.jcache.JCacheCache; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Configure {@link CacheMeterBinderProvider} beans. - * - * @author Stephane Nicoll - */ -@Configuration -@ConditionalOnClass(MeterBinder.class) -class CacheMeterBinderProvidersConfiguration { - - @Configuration - @ConditionalOnClass({CaffeineCache.class, - com.github.benmanes.caffeine.cache.Cache.class}) - static class CaffeineCacheMeterBinderProviderConfiguration { - - @Bean - public CaffeineCacheMeterBinderProvider caffeineCacheMeterBinderProvider() { - return new CaffeineCacheMeterBinderProvider(); - } - - } - - @Configuration - @ConditionalOnClass({EhCacheCache.class, Ehcache.class}) - static class EhCache2CacheMeterBinderProviderConfiguration { - - @Bean - public EhCache2CacheMeterBinderProvider ehCache2CacheMeterBinderProvider() { - return new EhCache2CacheMeterBinderProvider(); - } - - } - - @Configuration - @ConditionalOnClass({HazelcastCache.class, Hazelcast.class}) - static class HazelcastCacheMeterBinderProviderConfiguration { - - @Bean - public HazelcastCacheMeterBinderProvider hazelcastCacheMeterBinderProvider() { - return new HazelcastCacheMeterBinderProvider(); - } - - } - - @Configuration - @ConditionalOnClass({JCacheCache.class, javax.cache.CacheManager.class}) - static class JCacheCacheMeterBinderProviderConfiguration { - - @Bean - public JCacheCacheMeterBinderProvider jCacheCacheMeterBinderProvider() { - return new JCacheCacheMeterBinderProvider(); - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsAutoConfiguration.java deleted file mode 100644 index 6b369fec5e..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsAutoConfiguration.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2019 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.autoconfigure.cache; - -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for metrics on all available - * {@link Cache caches}. - * - * @author Stephane Nicoll - * @since 1.2.0 - */ -@Configuration -@AutoConfigureAfter({MetricsAutoConfiguration.class, CacheAutoConfiguration.class}) -@ConditionalOnBean(CacheManager.class) -@Import({CacheMeterBinderProvidersConfiguration.class, - CacheMetricsRegistrarConfiguration.class}) -public class CacheMetricsAutoConfiguration { - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsRegistrarConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsRegistrarConfiguration.java deleted file mode 100644 index 86f35e4149..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsRegistrarConfiguration.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2012-2019 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.autoconfigure.cache; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.spring.cache.CacheMeterBinderProvider; -import io.micrometer.spring.cache.CacheMetricsRegistrar; -import org.springframework.boot.autoconfigure.condition.AllNestedConditions; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.cache.Cache; -import org.springframework.cache.CacheManager; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.StringUtils; - -import javax.annotation.PostConstruct; -import java.util.Collection; -import java.util.Map; - -/** - * Configure a {@link CacheMetricsRegistrar} and register all available {@link Cache - * caches}. - * - * @author Stephane Nicoll - * @author Johnny Lim - */ -@Configuration -@Conditional(CacheMetricsRegistrarConfiguration.CacheMetricsRegistrarConditionalOnBeans.class) -class CacheMetricsRegistrarConfiguration { - - private static final String CACHE_MANAGER_SUFFIX = "cacheManager"; - - private final MeterRegistry registry; - - private final CacheMetricsRegistrar cacheMetricsRegistrar; - - private final Map cacheManagers; - - CacheMetricsRegistrarConfiguration(MeterRegistry registry, - Collection> binderProviders, - Map cacheManagers) { - this.registry = registry; - this.cacheManagers = cacheManagers; - this.cacheMetricsRegistrar = new CacheMetricsRegistrar(this.registry, - binderProviders); - } - - @Bean - public CacheMetricsRegistrar cacheMetricsRegistrar() { - return this.cacheMetricsRegistrar; - } - - @PostConstruct - public void bindCachesToRegistry() { - this.cacheManagers.forEach(this::bindCacheManagerToRegistry); - } - - private void bindCacheManagerToRegistry(String beanName, CacheManager cacheManager) { - cacheManager.getCacheNames().forEach((cacheName) -> bindCacheToRegistry(beanName, - cacheManager.getCache(cacheName))); - } - - private void bindCacheToRegistry(String beanName, Cache cache) { - Tag cacheManagerTag = Tag.of("cacheManager", getCacheManagerName(beanName)); - this.cacheMetricsRegistrar.bindCacheToRegistry(cache, cacheManagerTag); - } - - /** - * Get the name of a {@link CacheManager} based on its {@code beanName}. - * - * @param beanName the name of the {@link CacheManager} bean - * @return a name for the given cache manager - */ - private String getCacheManagerName(String beanName) { - if (beanName.length() > CACHE_MANAGER_SUFFIX.length() - && StringUtils.endsWithIgnoreCase(beanName, CACHE_MANAGER_SUFFIX)) { - return beanName.substring(0, - beanName.length() - CACHE_MANAGER_SUFFIX.length()); - } - return beanName; - } - - static class CacheMetricsRegistrarConditionalOnBeans extends AllNestedConditions { - - CacheMetricsRegistrarConditionalOnBeans() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @ConditionalOnBean(MeterRegistry.class) - static class ConditionalOnMeterRegistryBean { - } - - @ConditionalOnBean(CacheMeterBinderProvider.class) - static class ConditionalOnCacheMeterBinderProviderBean { - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/StringToDurationConverter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/StringToDurationConverter.java deleted file mode 100644 index 7cc75b37a4..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/StringToDurationConverter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export; - -import io.micrometer.core.instrument.util.StringUtils; -import io.micrometer.core.lang.Nullable; -import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; -import org.springframework.core.annotation.Order; -import org.springframework.core.convert.converter.Converter; - -import java.time.Duration; -import java.time.format.DateTimeParseException; -import java.util.Optional; -import java.util.function.Function; - -/** - * A {@link Converter} to create a {@link Duration} from a {@link String}. - * - * @author Jon Schneider - * @author Andy Wilkinson - */ -@ConfigurationPropertiesBinding -@Order(0) -public class StringToDurationConverter implements Converter { - - @Nullable - private static Duration simpleParse(@Nullable String rawTime) { - if (StringUtils.isEmpty(rawTime)) - return null; - if (!Character.isDigit(rawTime.charAt(0))) - return null; - - String time = rawTime.toLowerCase(); - return tryParse(time, "ns", Duration::ofNanos) - .orElseGet(() -> tryParse(time, "ms", Duration::ofMillis) - .orElseGet(() -> tryParse(time, "s", Duration::ofSeconds) - .orElseGet(() -> tryParse(time, "m", Duration::ofMinutes) - .orElseGet(() -> tryParse(time, "h", Duration::ofHours) - .orElseGet(() -> tryParse(time, "d", Duration::ofDays) - .orElse(null)))))); - } - - private static Optional tryParse(String time, String unit, Function toDuration) { - if (time.endsWith(unit)) { - String trim = time.substring(0, time.lastIndexOf(unit)).trim(); - try { - return Optional.of(toDuration.apply(Long.parseLong(trim))); - } catch (NumberFormatException ignore) { - return Optional.empty(); - } - } - return Optional.empty(); - } - - @Override - public Duration convert(@Nullable String source) { - Duration duration = simpleParse(source); - try { - return duration == null ? Duration.parse(source) : duration; - } catch (DateTimeParseException e) { - throw new IllegalArgumentException("Cannot convert '" + source + "' to Duration", e); - } - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/StringToTimeUnitConverter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/StringToTimeUnitConverter.java deleted file mode 100644 index 07b9073fea..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/StringToTimeUnitConverter.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export; - -import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; -import org.springframework.core.annotation.Order; -import org.springframework.core.convert.converter.Converter; - -import java.util.concurrent.TimeUnit; - -/** - * @author Nicolas Portmann - */ -@ConfigurationPropertiesBinding -@Order(0) -public class StringToTimeUnitConverter implements Converter { - @Override - public TimeUnit convert(String source) { - return TimeUnit.valueOf(source.toUpperCase()); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsMetricsExportAutoConfiguration.java deleted file mode 100644 index 63c24a7c20..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.appoptics; - -import io.micrometer.appoptics.AppOpticsConfig; -import io.micrometer.appoptics.AppOpticsMeterRegistry; -import io.micrometer.core.instrument.Clock; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to AppOptics. - * - * @author Hunter Sherman - * @author Stephane Nicoll - * @since 1.1.0 - */ -@Configuration -@AutoConfigureBefore({ CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class }) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(AppOpticsMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.appoptics", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(AppOpticsProperties.class) -@Import(StringToDurationConverter.class) -public class AppOpticsMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public AppOpticsConfig appOpticsConfig(AppOpticsProperties appOpticsProperties) { - return new AppOpticsPropertiesConfigAdapter(appOpticsProperties); - } - - @Bean - @ConditionalOnMissingBean - public AppOpticsMeterRegistry appOpticsMeterRegistry(AppOpticsConfig config, - Clock clock) { - return new AppOpticsMeterRegistry(config, clock); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsProperties.java deleted file mode 100644 index a4cb5d6277..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsProperties.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.appoptics; - -import java.time.Duration; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring AppOptics metrics export. - * - * @author Hunter Sherman - * @author Stephane Nicoll - * @since 1.1.0 - */ -@ConfigurationProperties(prefix = "management.metrics.export.appoptics") -public class AppOpticsProperties extends StepRegistryProperties { - - /** - * URI to ship metrics to. - */ - private String uri = "https://api.appoptics.com/v1/measurements"; - - /** - * AppOptics API token. - */ - private String apiToken; - - /** - * Tag that will be mapped to "@host" when shipping metrics to AppOptics. - */ - private String hostTag = "instance"; - - /** - * Number of measurements per request to use for this backend. If more measurements - * are found, then multiple requests will be made. - */ - private Integer batchSize = 500; - - /** - * Connection timeout for requests to this backend. - */ - private Duration connectTimeout = Duration.ofSeconds(5); - - public String getUri() { - return this.uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getApiToken() { - return this.apiToken; - } - - public void setApiToken(String apiToken) { - this.apiToken = apiToken; - } - - public String getHostTag() { - return this.hostTag; - } - - public void setHostTag(String hostTag) { - this.hostTag = hostTag; - } - - @Override - public Integer getBatchSize() { - return this.batchSize; - } - - @Override - public void setBatchSize(Integer batchSize) { - this.batchSize = batchSize; - } - - @Override - public Duration getConnectTimeout() { - return this.connectTimeout; - } - - @Override - public void setConnectTimeout(Duration connectTimeout) { - this.connectTimeout = connectTimeout; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapter.java deleted file mode 100644 index fe14b4335c..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapter.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.appoptics; - -import io.micrometer.appoptics.AppOpticsConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link AppOpticsProperties} to an {@link AppOpticsConfig}. - * - * @author Hunter Sherman - * @author Stephane Nicoll - */ -class AppOpticsPropertiesConfigAdapter - extends StepRegistryPropertiesConfigAdapter - implements AppOpticsConfig { - - AppOpticsPropertiesConfigAdapter(AppOpticsProperties properties) { - super(properties); - } - - @Override - public String uri() { - return get(AppOpticsProperties::getUri, AppOpticsConfig.super::uri); - } - - @Override - public String apiToken() { - return get(AppOpticsProperties::getApiToken, AppOpticsConfig.super::apiToken); - } - - @Override - public String hostTag() { - return get(AppOpticsProperties::getHostTag, AppOpticsConfig.super::hostTag); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasMetricsExportAutoConfiguration.java deleted file mode 100644 index d75a61ee1d..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.atlas; - -import com.netflix.spectator.atlas.AtlasConfig; -import io.micrometer.atlas.AtlasMeterRegistry; -import io.micrometer.core.instrument.Clock; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to Atlas. - * - * @author Jon Schneider - * @author Andy Wilkinson - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(AtlasMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.atlas", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(AtlasProperties.class) -@Import(StringToDurationConverter.class) -public class AtlasMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(AtlasConfig.class) - public AtlasConfig atlasConfig(AtlasProperties atlasProperties) { - return new AtlasPropertiesConfigAdapter(atlasProperties); - } - - @Bean - @ConditionalOnMissingBean - public AtlasMeterRegistry atlasMeterRegistry(AtlasConfig config, Clock clock) { - return new AtlasMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasProperties.java deleted file mode 100644 index 278ec1d45d..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasProperties.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.atlas; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.time.Duration; - -/** - * {@link ConfigurationProperties} for configuring Atlas metrics export. - * - * @author Jon Schneider - */ -@ConfigurationProperties(prefix = "management.metrics.export.atlas") -public class AtlasProperties extends StepRegistryProperties { - - /** - * URI of the Atlas server. - */ - private String uri = "http://localhost:7101/api/v1/publish"; - - /** - * Time to live for meters that do not have any activity. After this period the meter - * will be considered expired and will not get reported. - */ - private Duration meterTimeToLive = Duration.ofMinutes(15); - - /** - * Whether to enable streaming to Atlas LWC. - */ - private boolean lwcEnabled; - - /** - * Frequency for refreshing config settings from the LWC service. - */ - private Duration configRefreshFrequency = Duration.ofSeconds(10); - - /** - * Time to live for subscriptions from the LWC service. - */ - private Duration configTimeToLive = Duration.ofSeconds(150); - - /** - * URI for the Atlas LWC endpoint to retrieve current subscriptions. - */ - private String configUri = "http://localhost:7101/lwc/api/v1/expressions/local-dev"; - - /** - * URI for the Atlas LWC endpoint to evaluate the data for a subscription. - */ - private String evalUri = "http://localhost:7101/lwc/api/v1/evaluate"; - - public String getUri() { - return this.uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public Duration getMeterTimeToLive() { - return this.meterTimeToLive; - } - - public void setMeterTimeToLive(Duration meterTimeToLive) { - this.meterTimeToLive = meterTimeToLive; - } - - public boolean isLwcEnabled() { - return this.lwcEnabled; - } - - public void setLwcEnabled(boolean lwcEnabled) { - this.lwcEnabled = lwcEnabled; - } - - public Duration getConfigRefreshFrequency() { - return this.configRefreshFrequency; - } - - public void setConfigRefreshFrequency(Duration configRefreshFrequency) { - this.configRefreshFrequency = configRefreshFrequency; - } - - public Duration getConfigTimeToLive() { - return this.configTimeToLive; - } - - public void setConfigTimeToLive(Duration configTimeToLive) { - this.configTimeToLive = configTimeToLive; - } - - public String getConfigUri() { - return this.configUri; - } - - public void setConfigUri(String configUri) { - this.configUri = configUri; - } - - public String getEvalUri() { - return this.evalUri; - } - - public void setEvalUri(String evalUri) { - this.evalUri = evalUri; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasPropertiesConfigAdapter.java deleted file mode 100644 index e9eece5b28..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/atlas/AtlasPropertiesConfigAdapter.java +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.atlas; - -import com.netflix.spectator.atlas.AtlasConfig; -import io.micrometer.spring.autoconfigure.export.properties.PropertiesConfigAdapter; - -import java.time.Duration; - -/** - * Adapter to convert {@link AtlasProperties} to an {@link AtlasConfig}. - * - * @author Jon Schneider - * @author Phillip Webb - */ -class AtlasPropertiesConfigAdapter extends PropertiesConfigAdapter - implements AtlasConfig { - - AtlasPropertiesConfigAdapter(AtlasProperties properties) { - super(properties); - } - - @Override - public String get(String key) { - return null; - } - - @Override - public Duration step() { - return get(AtlasProperties::getStep, AtlasConfig.super::step); - } - - @Override - public boolean enabled() { - return get(AtlasProperties::isEnabled, AtlasConfig.super::enabled); - } - - @Override - public Duration connectTimeout() { - return get(AtlasProperties::getConnectTimeout, AtlasConfig.super::connectTimeout); - } - - @Override - public Duration readTimeout() { - return get(AtlasProperties::getReadTimeout, AtlasConfig.super::readTimeout); - } - - @Override - public int numThreads() { - return get(AtlasProperties::getNumThreads, AtlasConfig.super::numThreads); - } - - @Override - public int batchSize() { - return get(AtlasProperties::getBatchSize, AtlasConfig.super::batchSize); - } - - @Override - public String uri() { - return get(AtlasProperties::getUri, AtlasConfig.super::uri); - } - - @Override - public Duration meterTTL() { - return get(AtlasProperties::getMeterTimeToLive, AtlasConfig.super::meterTTL); - } - - @Override - public boolean lwcEnabled() { - return get(AtlasProperties::isLwcEnabled, AtlasConfig.super::lwcEnabled); - } - - @Override - public Duration configRefreshFrequency() { - return get(AtlasProperties::getConfigRefreshFrequency, - AtlasConfig.super::configRefreshFrequency); - } - - @Override - public Duration configTTL() { - return get(AtlasProperties::getConfigTimeToLive, AtlasConfig.super::configTTL); - } - - @Override - public String configUri() { - return get(AtlasProperties::getConfigUri, AtlasConfig.super::configUri); - } - - @Override - public String evalUri() { - return get(AtlasProperties::getEvalUri, AtlasConfig.super::evalUri); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorMetricsExportAutoConfiguration.java deleted file mode 100644 index 6ef10c67a6..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.azuremonitor; - -import com.microsoft.applicationinsights.TelemetryConfiguration; -import io.micrometer.azuremonitor.AzureMonitorConfig; -import io.micrometer.azuremonitor.AzureMonitorMeterRegistry; -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.util.StringUtils; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Auto-configuration for exporting metrics to Azure Monitor. - * - * @author Dhaval Doshi - * @since 1.1.0 - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(AzureMonitorMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.azuremonitor", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(AzureMonitorProperties.class) -@Import(StringToDurationConverter.class) -public class AzureMonitorMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public AzureMonitorConfig azureMonitorConfig(AzureMonitorProperties properties) { - return new AzureMonitorPropertiesConfigAdapter(properties); - } - - @Bean - @ConditionalOnMissingBean - public TelemetryConfiguration telemetryConfiguration(AzureMonitorConfig config) { - // Gets the active instance of TelemetryConfiguration either created by starter or xml - TelemetryConfiguration telemetryConfiguration = TelemetryConfiguration.getActive(); - if (StringUtils.isEmpty(telemetryConfiguration.getInstrumentationKey())) { - telemetryConfiguration.setInstrumentationKey(config.instrumentationKey()); - } - return telemetryConfiguration; - } - - @Bean - @ConditionalOnMissingBean - public AzureMonitorMeterRegistry azureMeterRegistry(AzureMonitorConfig config, TelemetryConfiguration configuration, Clock clock) { - return AzureMonitorMeterRegistry.builder(config) - .clock(clock) - .telemetryConfiguration(configuration) - .build(); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorProperties.java deleted file mode 100644 index c6a2c416a7..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorProperties.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.azuremonitor; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring Azure Monitor metrics export. - * - * @author Dhaval Doshi - * @since 1.1.0 - */ -@ConfigurationProperties(prefix = "management.metrics.export.azuremonitor") -public class AzureMonitorProperties extends StepRegistryProperties { - - /** - * Instrumentation key. - */ - private String instrumentationKey; - - public String getInstrumentationKey() { - return this.instrumentationKey; - } - - public void setInstrumentationKey(String instrumentationKey) { - this.instrumentationKey = instrumentationKey; - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorPropertiesConfigAdapter.java deleted file mode 100644 index 05499dcabe..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/azuremonitor/AzureMonitorPropertiesConfigAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.azuremonitor; - -import io.micrometer.azuremonitor.AzureMonitorConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link AzureMonitorProperties} to an {@link AzureMonitorConfig}. - * - * @author Dhaval Doshi - */ -class AzureMonitorPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter - implements AzureMonitorConfig { - - AzureMonitorPropertiesConfigAdapter(AzureMonitorProperties properties) { - super(properties); - } - - @Override - public String instrumentationKey() { - return get(AzureMonitorProperties::getInstrumentationKey, AzureMonitorConfig.super::instrumentationKey); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogMetricsExportAutoConfiguration.java deleted file mode 100644 index 1324746b39..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.datadog; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.datadog.DatadogConfig; -import io.micrometer.datadog.DatadogMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to Datadog. - * - * @author Jon Schneider - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(DatadogMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.datadog", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(DatadogProperties.class) -@Import(StringToDurationConverter.class) -public class DatadogMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public DatadogConfig datadogConfig(DatadogProperties props) { - return new DatadogPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public DatadogMeterRegistry datadogMeterRegistry(DatadogConfig config, Clock clock) { - return new DatadogMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogProperties.java deleted file mode 100644 index 4a682f1d5e..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogProperties.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.datadog; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring Datadog metrics export. - * - * @author Jon Schneider - */ -@ConfigurationProperties(prefix = "management.metrics.export.datadog") -public class DatadogProperties extends StepRegistryProperties { - - /** - * Datadog API key. - */ - private String apiKey; - - /** - * Datadog application key. Not strictly required, but improves the Datadog experience - * by sending meter descriptions, types, and base units to Datadog. - */ - private String applicationKey; - - /** - * Whether to publish descriptions metadata to Datadog. Turn this off to minimize the - * amount of metadata sent. - */ - private boolean descriptions = true; - - /** - * Tag that will be mapped to "host" when shipping metrics to Datadog. - */ - private String hostTag = "instance"; - - /** - * 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"; - - public String getApiKey() { - return this.apiKey; - } - - public void setApiKey(String apiKey) { - this.apiKey = apiKey; - } - - public String getApplicationKey() { - return this.applicationKey; - } - - public void setApplicationKey(String applicationKey) { - this.applicationKey = applicationKey; - } - - public boolean isDescriptions() { - return this.descriptions; - } - - public void setDescriptions(boolean descriptions) { - this.descriptions = descriptions; - } - - public String getHostTag() { - return this.hostTag; - } - - public void setHostTag(String hostTag) { - this.hostTag = hostTag; - } - - public String getUri() { - return this.uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogPropertiesConfigAdapter.java deleted file mode 100644 index a046bf3816..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/datadog/DatadogPropertiesConfigAdapter.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.datadog; - -import io.micrometer.datadog.DatadogConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link DatadogProperties} to a {@link DatadogConfig}. - * - * @author Jon Schneider - * @author Phillip Webb - */ -class DatadogPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter implements DatadogConfig { - - DatadogPropertiesConfigAdapter(DatadogProperties properties) { - super(properties); - } - - @Override - public String apiKey() { - return get(DatadogProperties::getApiKey, DatadogConfig.super::apiKey); - } - - @Override - public String applicationKey() { - return get(DatadogProperties::getApplicationKey, DatadogConfig.super::applicationKey); - } - - @Override - public String hostTag() { - return get(DatadogProperties::getHostTag, DatadogConfig.super::hostTag); - } - - @Override - public String uri() { - return get(DatadogProperties::getUri, DatadogConfig.super::uri); - } - - @Override - public boolean descriptions() { - return get(DatadogProperties::isDescriptions, DatadogConfig.super::descriptions); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatraceMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatraceMetricsExportAutoConfiguration.java deleted file mode 100644 index d3b76d6ba9..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatraceMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.dynatrace; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.dynatrace.DynatraceConfig; -import io.micrometer.dynatrace.DynatraceMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to Dynatrace. - * - * @author Oriol Barcelona - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(DynatraceMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.dynatrace", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(DynatraceProperties.class) -@Import(StringToDurationConverter.class) -public class DynatraceMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public DynatraceConfig dynatraceConfig(DynatraceProperties props) { - return new DynatracePropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public DynatraceMeterRegistry dynatraceMeterRegistry(DynatraceConfig config, Clock clock) { - return new DynatraceMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatraceProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatraceProperties.java deleted file mode 100644 index edd7478285..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatraceProperties.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.dynatrace; - - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring Dynatrace metrics export. - * - * @author Oriol Barcelona - */ -@ConfigurationProperties(prefix = "management.metrics.export.dynatrace") -public class DynatraceProperties extends StepRegistryProperties { - - /** - * Dynatrace authentication token. - */ - private String apiToken; - - /** - * ID of the custom device that is exporting metrics to Dynatrace. - */ - private String deviceId; - - /** - * Technology type for exported metrics. Used to group metrics under a logical - * technology name in the Dynatrace UI. - */ - private String technologyType = "java"; - - /** - * URI to ship metrics to. Should be used for SaaS, self managed instances or to - * en-route through an internal proxy. - */ - private String uri; - - /** - * Group for exported metrics. Used to name custom device group in the Dynatrace UI. - */ - private String group; - - public String getApiToken() { - return this.apiToken; - } - - public void setApiToken(String apiToken) { - this.apiToken = apiToken; - } - - public String getDeviceId() { - return this.deviceId; - } - - public void setDeviceId(String deviceId) { - this.deviceId = deviceId; - } - - public String getTechnologyType() { - return this.technologyType; - } - - public void setTechnologyType(String technologyType) { - this.technologyType = technologyType; - } - - public String getUri() { - return this.uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getGroup() { - return group; - } - - public void setGroup(String group) { - this.group = group; - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatracePropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatracePropertiesConfigAdapter.java deleted file mode 100644 index a69193f73b..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/dynatrace/DynatracePropertiesConfigAdapter.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.dynatrace; - -import io.micrometer.dynatrace.DynatraceConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link DynatraceProperties} to a {@link io.micrometer.dynatrace.DynatraceConfig}. - * - * @author Oriol Barcelona - */ -class DynatracePropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter implements DynatraceConfig { - - DynatracePropertiesConfigAdapter(DynatraceProperties properties) { - super(properties); - } - - @Override - public String apiToken() { - - return get(DynatraceProperties::getApiToken, DynatraceConfig.super::apiToken); - } - - @Override - public String uri() { - return get(DynatraceProperties::getUri, DynatraceConfig.super::uri); - } - - @Override - public String deviceId() { - return get(DynatraceProperties::getDeviceId, DynatraceConfig.super::deviceId); - } - - @Override - public String technologyType() { - return get(DynatraceProperties::getTechnologyType, DynatraceConfig.super::technologyType); - } - - @Override - public String group() { - return get(DynatraceProperties::getGroup, DynatraceConfig.super::group); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticMetricsExportAutoConfiguration.java deleted file mode 100644 index e4d2663f01..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.elastic; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.elastic.ElasticConfig; -import io.micrometer.elastic.ElasticMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to Elastic. - * - * @author Nicolas Portmann - * @since 1.1.0 - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(ElasticMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.elastic", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(ElasticProperties.class) -@Import(StringToDurationConverter.class) -public class ElasticMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public ElasticConfig elasticConfig(ElasticProperties props) { - return new ElasticPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public ElasticMeterRegistry elasticMeterRegistry(ElasticConfig config, Clock clock) { - return new ElasticMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticProperties.java deleted file mode 100644 index 50c4cc3560..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticProperties.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.elastic; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring Elastic metrics export. - * - * @author Nicolas Portmann - * @since 1.1.0 - */ -@ConfigurationProperties(prefix = "management.metrics.export.elastic") -public class ElasticProperties extends StepRegistryProperties { - - /** - * Host to export metrics to. - */ - private String host = "http://localhost:9200"; - - /** - * Index to export metrics to. - */ - private String index = "metrics"; - - /** - * Index date format used for rolling indices. Appended to the index name, preceded by - * a '-'. - */ - private String indexDateFormat = "yyyy-MM"; - - /** - * Name of the timestamp field. - */ - private String timestampFieldName = "@timestamp"; - - /** - * Whether to create the index automatically if it does not exist. - */ - private boolean autoCreateIndex = true; - - /** - * Login user of the Elastic server. - */ - private String userName = ""; - - /** - * Login password of the Elastic server. - */ - private String password = ""; - - /** - * Ingest pipeline name. - */ - private String pipeline = ""; - - /** - * Separator between the index name and the date part. - */ - private String indexDateSeparator = "-"; - - public String getHost() { - return this.host; - } - - public void setHost(String host) { - this.host = host; - } - - public String getIndex() { - return this.index; - } - - public void setIndex(String index) { - this.index = index; - } - - public String getIndexDateFormat() { - return this.indexDateFormat; - } - - public void setIndexDateFormat(String indexDateFormat) { - this.indexDateFormat = indexDateFormat; - } - - public String getTimestampFieldName() { - return this.timestampFieldName; - } - - public void setTimestampFieldName(String timestampFieldName) { - this.timestampFieldName = timestampFieldName; - } - - public boolean isAutoCreateIndex() { - return this.autoCreateIndex; - } - - public void setAutoCreateIndex(boolean autoCreateIndex) { - this.autoCreateIndex = autoCreateIndex; - } - - public String getUserName() { - return this.userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getPassword() { - return this.password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getPipeline() { - return this.pipeline; - } - - public void setPipeline(String pipeline) { - this.pipeline = pipeline; - } - - public String getIndexDateSeparator() { - return this.indexDateSeparator; - } - - public void setIndexDateSeparator(String indexDateSeparator) { - this.indexDateSeparator = indexDateSeparator; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticPropertiesConfigAdapter.java deleted file mode 100644 index c761287366..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/elastic/ElasticPropertiesConfigAdapter.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.elastic; - -import io.micrometer.elastic.ElasticConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link ElasticProperties} to an {@link ElasticConfig}. - * - * @author Nicolas Portmann - */ -class ElasticPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter implements ElasticConfig { - - ElasticPropertiesConfigAdapter(ElasticProperties properties) { - super(properties); - } - - @Override - public String host() { - return get(ElasticProperties::getHost, ElasticConfig.super::host); - } - - @Override - public String index() { - return get(ElasticProperties::getIndex, ElasticConfig.super::index); - } - - @Override - public String indexDateFormat() { - return get(ElasticProperties::getIndexDateFormat, ElasticConfig.super::indexDateFormat); - } - - @Override - public String timestampFieldName() { - return get(ElasticProperties::getTimestampFieldName, ElasticConfig.super::timestampFieldName); - } - - @Override - public boolean autoCreateIndex() { - return get(ElasticProperties::isAutoCreateIndex, ElasticConfig.super::autoCreateIndex); - } - - @Override - public String userName() { - return get(ElasticProperties::getUserName, ElasticConfig.super::userName); - } - - @Override - public String password() { - return get(ElasticProperties::getPassword, ElasticConfig.super::password); - } - - @Override - public String pipeline() { - return get(ElasticProperties::getPipeline, ElasticConfig.super::pipeline); - } - - @Override - public String indexDateSeparator() { - return get(ElasticProperties::getIndexDateSeparator, ElasticConfig.super::indexDateSeparator); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaMetricsExportAutoConfiguration.java deleted file mode 100644 index f9596d8e2f..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.ganglia; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.ganglia.GangliaConfig; -import io.micrometer.ganglia.GangliaMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to Ganglia. - * - * @author Jon Schneider - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(GangliaMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.ganglia", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(GangliaProperties.class) -@Import(StringToDurationConverter.class) -public class GangliaMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public GangliaConfig gangliaConfig(GangliaProperties props) { - return new GangliaPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public GangliaMeterRegistry gangliaMeterRegistry(GangliaConfig config, Clock clock) { - return new GangliaMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaProperties.java deleted file mode 100644 index f04e98bc8e..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaProperties.java +++ /dev/null @@ -1,150 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.ganglia; - -import info.ganglia.gmetric4j.gmetric.GMetric; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -/** - * {@link ConfigurationProperties} for configuring Ganglia metrics export. - * - * @author Jon Schneider - */ -@ConfigurationProperties(prefix = "management.metrics.export.ganglia") -public class GangliaProperties { - - /** - * Whether exporting of metrics to Ganglia is enabled. - */ - private boolean enabled = true; - - /** - * Step size (i.e. reporting frequency) to use. - */ - private Duration step = Duration.ofMinutes(1); - - /** - * Base time unit used to report rates. - */ - private TimeUnit rateUnits = TimeUnit.SECONDS; - - /** - * Base time unit used to report durations. - */ - private TimeUnit durationUnits = TimeUnit.MILLISECONDS; - - /** - * Ganglia protocol version. Must be either 3.1 or 3.0. - */ - private String protocolVersion = "3.1"; - - /** - * UDP addressing mode, either unicast or multicast. - */ - private GMetric.UDPAddressingMode addressingMode = GMetric.UDPAddressingMode.MULTICAST; - - /** - * Time to live for metrics on Ganglia. Set the multi-cast Time-To-Live to be one - * greater than the number of hops (routers) between the hosts. - */ - private Integer timeToLive = 1; - - /** - * Host of the Ganglia server to receive exported metrics. - */ - private String host = "localhost"; - - /** - * Port of the Ganglia server to receive exported metrics. - */ - private Integer port = 8649; - - public boolean isEnabled() { - return this.enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public Duration getStep() { - return this.step; - } - - public void setStep(Duration step) { - this.step = step; - } - - public TimeUnit getRateUnits() { - return this.rateUnits; - } - - public void setRateUnits(TimeUnit rateUnits) { - this.rateUnits = rateUnits; - } - - public TimeUnit getDurationUnits() { - return this.durationUnits; - } - - public void setDurationUnits(TimeUnit durationUnits) { - this.durationUnits = durationUnits; - } - - public String getProtocolVersion() { - return this.protocolVersion; - } - - public void setProtocolVersion(String protocolVersion) { - this.protocolVersion = protocolVersion; - } - - public GMetric.UDPAddressingMode getAddressingMode() { - return this.addressingMode; - } - - public void setAddressingMode(GMetric.UDPAddressingMode addressingMode) { - this.addressingMode = addressingMode; - } - - public Integer getTimeToLive() { - return this.timeToLive; - } - - public void setTimeToLive(Integer timeToLive) { - this.timeToLive = timeToLive; - } - - public String getHost() { - return this.host; - } - - public void setHost(String host) { - this.host = host; - } - - public Integer getPort() { - return this.port; - } - - public void setPort(Integer port) { - this.port = port; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaPropertiesConfigAdapter.java deleted file mode 100644 index 8bdc4daf6d..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/ganglia/GangliaPropertiesConfigAdapter.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.ganglia; - -import info.ganglia.gmetric4j.gmetric.GMetric; -import io.micrometer.ganglia.GangliaConfig; -import io.micrometer.spring.autoconfigure.export.properties.PropertiesConfigAdapter; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -/** - * Adapter to convert {@link GangliaProperties} to a {@link GangliaConfig}. - * - * @author Jon Schneider - * @author Phillip Webb - */ -class GangliaPropertiesConfigAdapter extends PropertiesConfigAdapter - implements GangliaConfig { - - GangliaPropertiesConfigAdapter(GangliaProperties properties) { - super(properties); - } - - @Override - public String get(String key) { - return null; - } - - @Override - public boolean enabled() { - return get(GangliaProperties::isEnabled, GangliaConfig.super::enabled); - } - - @Override - public Duration step() { - return get(GangliaProperties::getStep, GangliaConfig.super::step); - } - - @Override - public TimeUnit rateUnits() { - return get(GangliaProperties::getRateUnits, GangliaConfig.super::rateUnits); - } - - @Override - public TimeUnit durationUnits() { - return get(GangliaProperties::getDurationUnits, - GangliaConfig.super::durationUnits); - } - - @Override - public String protocolVersion() { - return get(GangliaProperties::getProtocolVersion, - GangliaConfig.super::protocolVersion); - } - - @Override - public GMetric.UDPAddressingMode addressingMode() { - return get(GangliaProperties::getAddressingMode, - GangliaConfig.super::addressingMode); - } - - @Override - public int ttl() { - return get(GangliaProperties::getTimeToLive, GangliaConfig.super::ttl); - } - - @Override - public String host() { - return get(GangliaProperties::getHost, GangliaConfig.super::host); - } - - @Override - public int port() { - return get(GangliaProperties::getPort, GangliaConfig.super::port); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphiteMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphiteMetricsExportAutoConfiguration.java deleted file mode 100644 index 0cb303cd41..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphiteMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.graphite; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.graphite.GraphiteConfig; -import io.micrometer.graphite.GraphiteMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to Graphite. - * - * @author Jon Schneider - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(GraphiteMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.graphite", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(GraphiteProperties.class) -@Import(StringToDurationConverter.class) -public class GraphiteMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public GraphiteConfig graphiteConfig(GraphiteProperties props) { - return new GraphitePropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public GraphiteMeterRegistry graphiteMeterRegistry(GraphiteConfig config, Clock clock) { - return new GraphiteMeterRegistry(config, clock); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphiteProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphiteProperties.java deleted file mode 100644 index c6f4ad3891..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphiteProperties.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.graphite; - -import io.micrometer.graphite.GraphiteProtocol; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -/** - * {@link ConfigurationProperties} for configuring Graphite metrics export. - * - * @author Jon Schneider - */ -@ConfigurationProperties(prefix = "management.metrics.export.graphite") -public class GraphiteProperties { - - /** - * Whether exporting of metrics to Graphite is enabled. - */ - private boolean enabled = true; - - /** - * Step size (i.e. reporting frequency) to use. - */ - private Duration step = Duration.ofMinutes(1); - - /** - * Base time unit used to report rates. - */ - private TimeUnit rateUnits = TimeUnit.SECONDS; - - /** - * Base time unit used to report durations. - */ - private TimeUnit durationUnits = TimeUnit.MILLISECONDS; - - /** - * Host of the Graphite server to receive exported metrics. - */ - private String host = "localhost"; - - /** - * Port of the Graphite server to receive exported metrics. - */ - private Integer port = 2004; - - /** - * Protocol to use while shipping data to Graphite. - */ - private GraphiteProtocol protocol = GraphiteProtocol.PICKLED; - - /** - * For the default naming convention, turn the specified tag keys into part of the - * metric prefix. - */ - private String[] tagsAsPrefix = new String[0]; - - public boolean isEnabled() { - return this.enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public Duration getStep() { - return this.step; - } - - public void setStep(Duration step) { - this.step = step; - } - - public TimeUnit getRateUnits() { - return this.rateUnits; - } - - public void setRateUnits(TimeUnit rateUnits) { - this.rateUnits = rateUnits; - } - - public TimeUnit getDurationUnits() { - return this.durationUnits; - } - - public void setDurationUnits(TimeUnit durationUnits) { - this.durationUnits = durationUnits; - } - - public String getHost() { - return this.host; - } - - public void setHost(String host) { - this.host = host; - } - - public Integer getPort() { - return this.port; - } - - public void setPort(Integer port) { - this.port = port; - } - - public GraphiteProtocol getProtocol() { - return this.protocol; - } - - public void setProtocol(GraphiteProtocol protocol) { - this.protocol = protocol; - } - - public String[] getTagsAsPrefix() { - return this.tagsAsPrefix; - } - - public void setTagsAsPrefix(String[] tagsAsPrefix) { - this.tagsAsPrefix = tagsAsPrefix; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphitePropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphitePropertiesConfigAdapter.java deleted file mode 100644 index 504739a630..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/graphite/GraphitePropertiesConfigAdapter.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.graphite; - -import io.micrometer.graphite.GraphiteConfig; -import io.micrometer.graphite.GraphiteProtocol; -import io.micrometer.spring.autoconfigure.export.properties.PropertiesConfigAdapter; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -/** - * Adapter to convert {@link GraphiteProperties} to a {@link GraphiteConfig}. - * - * @author Jon Schneider - * @author Phillip Webb - */ -class GraphitePropertiesConfigAdapter extends PropertiesConfigAdapter - implements GraphiteConfig { - - GraphitePropertiesConfigAdapter(GraphiteProperties properties) { - super(properties); - } - - @Override - public String get(String key) { - return null; - } - - @Override - public boolean enabled() { - return get(GraphiteProperties::isEnabled, GraphiteConfig.super::enabled); - } - - @Override - public Duration step() { - return get(GraphiteProperties::getStep, GraphiteConfig.super::step); - } - - @Override - public TimeUnit rateUnits() { - return get(GraphiteProperties::getRateUnits, GraphiteConfig.super::rateUnits); - } - - @Override - public TimeUnit durationUnits() { - return get(GraphiteProperties::getDurationUnits, - GraphiteConfig.super::durationUnits); - } - - @Override - public String host() { - return get(GraphiteProperties::getHost, GraphiteConfig.super::host); - } - - @Override - public int port() { - return get(GraphiteProperties::getPort, GraphiteConfig.super::port); - } - - @Override - public GraphiteProtocol protocol() { - return get(GraphiteProperties::getProtocol, GraphiteConfig.super::protocol); - } - - @Override - public String[] tagsAsPrefix() { - return get(GraphiteProperties::getTagsAsPrefix, GraphiteConfig.super::tagsAsPrefix); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioMetricsExportAutoConfiguration.java deleted file mode 100644 index 2cc45a82de..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.humio; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.humio.HumioConfig; -import io.micrometer.humio.HumioMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to Humio. - * - * @author Jon Schneider - * @since 1.1.0 - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(HumioMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.humio", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(HumioProperties.class) -@Import(StringToDurationConverter.class) -public class HumioMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public HumioConfig humioConfig(HumioProperties props) { - return new HumioPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public HumioMeterRegistry humioMeterRegistry(HumioConfig config, Clock clock) { - return new HumioMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioProperties.java deleted file mode 100644 index 0a1629b258..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioProperties.java +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.humio; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.time.Duration; -import java.util.HashMap; -import java.util.Map; - -/** - * {@link ConfigurationProperties} for configuring Humio metrics export. - * - * @author Jon Schneider - * @since 1.1.0 - */ -@ConfigurationProperties(prefix = "management.metrics.export.humio") -public class HumioProperties extends StepRegistryProperties { - - /** - * Humio API token. - */ - private String apiToken; - - /** - * Connection timeout for requests to Humio. - */ - private Duration connectTimeout = Duration.ofSeconds(5); - - /** - * Name of the repository to publish metrics to. - */ - private String repository = "sandbox"; - - /** - * Humio tags describing the data source in which metrics will be stored. Humio tags - * are a distinct concept from Micrometer's tags. Micrometer's tags are used to divide - * metrics along dimensional boundaries. - */ - private Map tags = new HashMap<>(); - - /** - * URI to ship metrics to. If you need to publish metrics to an internal proxy - * en-route to Humio, you can define the location of the proxy with this. - */ - private String uri = "https://cloud.humio.com"; - - public String getApiToken() { - return this.apiToken; - } - - public void setApiToken(String apiToken) { - this.apiToken = apiToken; - } - - @Override - public Duration getConnectTimeout() { - return this.connectTimeout; - } - - @Override - public void setConnectTimeout(Duration connectTimeout) { - this.connectTimeout = connectTimeout; - } - - public String getRepository() { - return this.repository; - } - - public void setRepository(String repository) { - this.repository = repository; - } - - public Map getTags() { - return this.tags; - } - - public void setTags(Map tags) { - this.tags = tags; - } - - public String getUri() { - return this.uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioPropertiesConfigAdapter.java deleted file mode 100644 index d1aeb4567e..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/humio/HumioPropertiesConfigAdapter.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.humio; - -import io.micrometer.humio.HumioConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -import java.util.Map; - -/** - * Adapter to convert {@link HumioProperties} to a {@link HumioConfig}. - * - * @author Jon Schneider - * @since 1.1.0 - */ -class HumioPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter implements HumioConfig { - - HumioPropertiesConfigAdapter(HumioProperties properties) { - super(properties); - } - - @Override - public String uri() { - return get(HumioProperties::getUri, HumioConfig.super::uri); - } - - @Override - public String apiToken() { - return get(HumioProperties::getApiToken, HumioConfig.super::apiToken); - } - - @Override - public Map tags() { - return get(HumioProperties::getTags, HumioConfig.super::tags); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxMetricsExportAutoConfiguration.java deleted file mode 100644 index dbf8efc0c9..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.influx; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.influx.InfluxConfig; -import io.micrometer.influx.InfluxMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to Influx. - * - * @author Jon Schneider - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(InfluxMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.influx", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(InfluxProperties.class) -@Import(StringToDurationConverter.class) -public class InfluxMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(InfluxConfig.class) - public InfluxConfig influxConfig(InfluxProperties props) { - return new InfluxPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public InfluxMeterRegistry influxMeterRegistry(InfluxConfig config, Clock clock) { - return new InfluxMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxProperties.java deleted file mode 100644 index 1ab8ea5bb0..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxProperties.java +++ /dev/null @@ -1,179 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.influx; - -import io.micrometer.influx.InfluxConsistency; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring Influx metrics export. - * - * @author Jon Schneider - */ -@ConfigurationProperties(prefix = "management.metrics.export.influx") -public class InfluxProperties extends StepRegistryProperties { - - /** - * Tag that will be mapped to "host" when shipping metrics to Influx. - */ - private String db = "mydb"; - - /** - * Write consistency for each point. - */ - private InfluxConsistency consistency = InfluxConsistency.ONE; - - /** - * Login user of the Influx server. - */ - private String userName; - - /** - * Login password of the Influx server. - */ - private String password; - - /** - * Retention policy to use (Influx writes to the DEFAULT retention policy if one is - * not specified). - */ - private String retentionPolicy; - - /** - * Time period for which Influx should retain data in the current database. For - * instance 7d, check the influx documentation for more details on the duration - * format. - */ - private String retentionDuration; - - /** - * How many copies of the data are stored in the cluster. Must be 1 for a single node - * instance. - */ - private Integer retentionReplicationFactor; - - /** - * Time range covered by a shard group. For instance 2w, check the influx - * documentation for more details on the duration format. - */ - private String retentionShardDuration; - - /** - * URI of the Influx server. - */ - private String uri = "http://localhost:8086"; - - /** - * Whether to enable GZIP compression of metrics batches published to Influx. - */ - private boolean compressed = true; - - /** - * Whether to create the Influx database if it does not exist before attempting to - * publish metrics to it. - */ - private boolean autoCreateDb = true; - - public String getDb() { - return this.db; - } - - public void setDb(String db) { - this.db = db; - } - - public InfluxConsistency getConsistency() { - return this.consistency; - } - - public void setConsistency(InfluxConsistency consistency) { - this.consistency = consistency; - } - - public String getUserName() { - return this.userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getPassword() { - return this.password; - } - - public void setPassword(String password) { - this.password = password; - } - - public String getRetentionPolicy() { - return this.retentionPolicy; - } - - public void setRetentionPolicy(String retentionPolicy) { - this.retentionPolicy = retentionPolicy; - } - - public String getRetentionDuration() { - return this.retentionDuration; - } - - public void setRetentionDuration(String retentionDuration) { - this.retentionDuration = retentionDuration; - } - - public Integer getRetentionReplicationFactor() { - return this.retentionReplicationFactor; - } - - public void setRetentionReplicationFactor(Integer retentionReplicationFactor) { - this.retentionReplicationFactor = retentionReplicationFactor; - } - - public String getRetentionShardDuration() { - return this.retentionShardDuration; - } - - public void setRetentionShardDuration(String retentionShardDuration) { - this.retentionShardDuration = retentionShardDuration; - } - - public String getUri() { - return this.uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public boolean isCompressed() { - return this.compressed; - } - - public void setCompressed(boolean compressed) { - this.compressed = compressed; - } - - public boolean isAutoCreateDb() { - return this.autoCreateDb; - } - - public void setAutoCreateDb(boolean autoCreateDb) { - this.autoCreateDb = autoCreateDb; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java deleted file mode 100644 index 2e05942cab..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/influx/InfluxPropertiesConfigAdapter.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.influx; - -import io.micrometer.influx.InfluxConfig; -import io.micrometer.influx.InfluxConsistency; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link InfluxProperties} to an {@link InfluxConfig}. - * - * @author Jon Schneider - * @author Phillip Webb - */ -class InfluxPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter implements InfluxConfig { - - InfluxPropertiesConfigAdapter(InfluxProperties properties) { - super(properties); - } - - @Override - public String db() { - return get(InfluxProperties::getDb, InfluxConfig.super::db); - } - - @Override - public InfluxConsistency consistency() { - return get(InfluxProperties::getConsistency, InfluxConfig.super::consistency); - } - - @Override - public String userName() { - return get(InfluxProperties::getUserName, InfluxConfig.super::userName); - } - - @Override - public String password() { - return get(InfluxProperties::getPassword, InfluxConfig.super::password); - } - - @Override - public String retentionPolicy() { - return get(InfluxProperties::getRetentionPolicy, InfluxConfig.super::retentionPolicy); - } - - @Override - public Integer retentionReplicationFactor() { - return get(InfluxProperties::getRetentionReplicationFactor, InfluxConfig.super::retentionReplicationFactor); - } - - @Override - public String retentionDuration() { - return get(InfluxProperties::getRetentionDuration, InfluxConfig.super::retentionDuration); - } - - @Override - public String retentionShardDuration() { - return get(InfluxProperties::getRetentionShardDuration, InfluxConfig.super::retentionShardDuration); - } - - @Override - public String uri() { - return get(InfluxProperties::getUri, InfluxConfig.super::uri); - } - - @Override - public boolean compressed() { - return get(InfluxProperties::isCompressed, InfluxConfig.super::compressed); - } - - @Override - public boolean autoCreateDb() { - return get(InfluxProperties::isAutoCreateDb, InfluxConfig.super::autoCreateDb); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxMetricsExportAutoConfiguration.java deleted file mode 100644 index d35ae539f1..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.jmx; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.jmx.JmxConfig; -import io.micrometer.jmx.JmxMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to JMX. - * - * @author Jon Schneider - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(JmxMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.jmx", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(JmxProperties.class) -@Import(StringToDurationConverter.class) -public class JmxMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public JmxConfig jmxConfig(JmxProperties props) { - return new JmxPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public JmxMeterRegistry jmxMeterRegistry(JmxConfig config, Clock clock) { - return new JmxMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxProperties.java deleted file mode 100644 index 03d7bdab64..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxProperties.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.jmx; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.time.Duration; - -/** - * {@link ConfigurationProperties} for configuring JMX metrics export. - * - * @author Jon Schneider - */ -@ConfigurationProperties(prefix = "management.metrics.export.jmx") -public class JmxProperties { - - /** - * Metrics JMX domain name. - */ - private String domain = "metrics"; - - /** - * Step size (i.e. reporting frequency) to use. - */ - private Duration step = Duration.ofMinutes(1); - - public String getDomain() { - return this.domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } - - public Duration getStep() { - return this.step; - } - - public void setStep(Duration step) { - this.step = step; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxPropertiesConfigAdapter.java deleted file mode 100644 index 57724aedf7..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/jmx/JmxPropertiesConfigAdapter.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.jmx; - -import io.micrometer.jmx.JmxConfig; -import io.micrometer.spring.autoconfigure.export.properties.PropertiesConfigAdapter; - -import java.time.Duration; - -/** - * Adapter to convert {@link JmxProperties} to a {@link JmxConfig}. - * - * @author Jon Schneider - */ -class JmxPropertiesConfigAdapter extends PropertiesConfigAdapter implements JmxConfig { - - JmxPropertiesConfigAdapter(JmxProperties properties) { - super(properties); - } - - @Override - public String get(String key) { - return null; - } - - @Override - public String domain() { - return get(JmxProperties::getDomain, JmxConfig.super::domain); - } - - @Override - public Duration step() { - return get(JmxProperties::getStep, JmxConfig.super::step); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfiguration.java deleted file mode 100644 index be99e626b0..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.kairos; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.kairos.KairosConfig; -import io.micrometer.kairos.KairosMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to KairosDB. - * - * @author Anton Ilinchik - * @since 1.1.0 - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(KairosMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.kairos", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(KairosProperties.class) -@Import(StringToDurationConverter.class) -public class KairosMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public KairosConfig kairosConfig(KairosProperties props) { - return new KairosPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public KairosMeterRegistry kairosMeterRegistry(KairosConfig config, Clock clock) { - return new KairosMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosProperties.java deleted file mode 100644 index 44b1eefe1e..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosProperties.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.kairos; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring Kairos metrics export. - * - * @author Anton Ilinchik - * @since 1.1.0 - */ -@ConfigurationProperties(prefix = "management.metrics.export.kairos") -public class KairosProperties extends StepRegistryProperties { - - /** - * URI of the KairosDB server. - */ - private String uri = "http://localhost:8080/api/v1/datapoints"; - - /** - * Login user of the KairosDB server. - */ - private String userName; - - /** - * Login password of the KairosDB server. - */ - private String password; - - public String getUri() { - return this.uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getUserName() { - return this.userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getPassword() { - return this.password; - } - - public void setPassword(String password) { - this.password = password; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java deleted file mode 100644 index 1be5ede513..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapter.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.kairos; - -import io.micrometer.kairos.KairosConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link KairosProperties} to a {@link KairosConfig}. - * - * @author Anton Ilinchik - */ -class KairosPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter implements KairosConfig { - - KairosPropertiesConfigAdapter(KairosProperties properties) { - super(properties); - } - - @Override - public String uri() { - return get(KairosProperties::getUri, KairosConfig.super::uri); - } - - @Override - public String userName() { - return get(KairosProperties::getUserName, KairosConfig.super::userName); - } - - @Override - public String password() { - return get(KairosProperties::getPassword, KairosConfig.super::password); - } -} - diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingMetricsExportAutoConfiguration.java deleted file mode 100644 index 0c92830166..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,65 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.logging; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.logging.LoggingRegistryConfig; -import io.micrometer.core.instrument.logging.LoggingMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for exporting metrics to a logging framework. - * - * Try SLF4J first and fallback to the standard output if it's unavailable. - * - * @author Jon Schneider - * @since 1.1.0 - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnProperty(prefix = "management.metrics.export.logging", name = "enabled", havingValue = "true", matchIfMissing = false) -@EnableConfigurationProperties(LoggingRegistryProperties.class) -@Import(StringToDurationConverter.class) -public class LoggingMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public LoggingRegistryConfig loggingRegistryConfig(LoggingRegistryProperties props) { - return new LoggingRegistryPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public LoggingMeterRegistry loggingMeterRegistry(LoggingRegistryConfig config, Clock clock) { - return new LoggingMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingRegistryProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingRegistryProperties.java deleted file mode 100644 index 82d8b97646..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingRegistryProperties.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.logging; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring metrics logging. - * - * @author Jon Schneider - * @since 1.1.0 - */ -@ConfigurationProperties(prefix = "management.metrics.export.logging") -public class LoggingRegistryProperties extends StepRegistryProperties { - - /** - * Whether counters and timers that have no activity in an interval are still logged. - */ - private boolean logInactive = false; - - public boolean isLogInactive() { - return logInactive; - } - - public void setLogInactive(boolean logInactive) { - this.logInactive = logInactive; - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingRegistryPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingRegistryPropertiesConfigAdapter.java deleted file mode 100644 index ee123e0bab..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/logging/LoggingRegistryPropertiesConfigAdapter.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.logging; - -import io.micrometer.core.instrument.logging.LoggingRegistryConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link LoggingRegistryProperties} to an {@link LoggingRegistryConfig}. - * - * @author Jon Schneider - */ -class LoggingRegistryPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter implements LoggingRegistryConfig { - - LoggingRegistryPropertiesConfigAdapter(LoggingRegistryProperties properties) { - super(properties); - } - - @Override - public boolean logInactive() { - return get(LoggingRegistryProperties::isLogInactive, LoggingRegistryConfig.super::logInactive); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicMetricsExportAutoConfiguration.java deleted file mode 100644 index 05716be241..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.newrelic; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.newrelic.NewRelicConfig; -import io.micrometer.newrelic.NewRelicMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to New Relic. - * - * @author Jon Schneider - * @since 1.0.0 - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(NewRelicMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.newrelic", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(NewRelicProperties.class) -@Import(StringToDurationConverter.class) -public class NewRelicMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public NewRelicConfig newRelicConfig(NewRelicProperties props) { - return new NewRelicPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public NewRelicMeterRegistry newRelicMeterRegistry(NewRelicConfig config, Clock clock) { - return new NewRelicMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicProperties.java deleted file mode 100644 index c7d059bbec..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicProperties.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.newrelic; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring New Relic metrics export. - * - * @author Jon Schneider - * @since 1.0.0 - */ -@ConfigurationProperties(prefix = "management.metrics.export.newrelic") -public class NewRelicProperties extends StepRegistryProperties { - - /** - * New Relic API key. - */ - private String apiKey; - - /** - * New Relic account ID. - */ - private String accountId; - - /** - * URI to ship metrics to. - */ - private String uri = "https://insights-collector.newrelic.com"; - - public String getApiKey() { - return this.apiKey; - } - - public void setApiKey(String apiKey) { - this.apiKey = apiKey; - } - - public String getAccountId() { - return this.accountId; - } - - public void setAccountId(String accountId) { - this.accountId = accountId; - } - - public String getUri() { - return this.uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicPropertiesConfigAdapter.java deleted file mode 100644 index 741581b6fb..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/newrelic/NewRelicPropertiesConfigAdapter.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.newrelic; - -import io.micrometer.newrelic.NewRelicConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link NewRelicProperties} to a {@link NewRelicConfig}. - * - * @author Jon Schneider - */ -class NewRelicPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter - implements NewRelicConfig { - - NewRelicPropertiesConfigAdapter(NewRelicProperties properties) { - super(properties); - } - - @Override - public String apiKey() { - return get(NewRelicProperties::getApiKey, NewRelicConfig.super::apiKey); - } - - @Override - public String accountId() { - return get(NewRelicProperties::getAccountId, NewRelicConfig.super::accountId); - } - - @Override - public String uri() { - return get(NewRelicProperties::getUri, NewRelicConfig.super::uri); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/package-info.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/package-info.java deleted file mode 100644 index 88e8bf73f5..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -@NonNullApi -@NonNullFields -package io.micrometer.spring.autoconfigure.export; - -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.NonNullFields; diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusMetricsExportAutoConfiguration.java deleted file mode 100644 index 682424720d..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,158 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.prometheus; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.prometheus.PrometheusConfig; -import io.micrometer.prometheus.PrometheusMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import io.micrometer.spring.export.prometheus.PrometheusPushGatewayManager; -import io.micrometer.spring.export.prometheus.PrometheusScrapeEndpoint; -import io.micrometer.spring.export.prometheus.PrometheusScrapeMvcEndpoint; -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.exporter.PushGateway; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.boot.actuate.autoconfigure.ManagementContextConfiguration; -import org.springframework.boot.actuate.condition.ConditionalOnEnabledEndpoint; -import org.springframework.boot.actuate.endpoint.AbstractEndpoint; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.*; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.core.env.Environment; - -import java.net.MalformedURLException; -import java.net.URL; -import java.time.Duration; -import java.util.Map; - -/** - * Configuration for exporting metrics to Prometheus. - * - * @author Jon Schneider - * @author David J. M. Karlsen - * @author Johnny Lim - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(PrometheusMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.prometheus", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(PrometheusProperties.class) -@Import(StringToDurationConverter.class) -public class PrometheusMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public PrometheusConfig prometheusConfig(PrometheusProperties props) { - return new PrometheusPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public PrometheusMeterRegistry prometheusMeterRegistry(PrometheusConfig config, CollectorRegistry collectorRegistry, - Clock clock) { - return new PrometheusMeterRegistry(config, collectorRegistry, clock); - } - - @Bean - @ConditionalOnMissingBean - public CollectorRegistry collectorRegistry() { - return new CollectorRegistry(true); - } - - @ManagementContextConfiguration - @ConditionalOnClass(AbstractEndpoint.class) - public static class PrometheusScrapeEndpointConfiguration { - @Bean - public PrometheusScrapeEndpoint prometheusEndpoint(CollectorRegistry collectorRegistry) { - return new PrometheusScrapeEndpoint(collectorRegistry); - } - - @Bean - @ConditionalOnEnabledEndpoint("prometheus") - public PrometheusScrapeMvcEndpoint prometheusMvcEndpoint(PrometheusScrapeEndpoint delegate) { - return new PrometheusScrapeMvcEndpoint(delegate); - } - } - - /** - * Configuration for Prometheus - * Pushgateway. - */ - @Configuration - @ConditionalOnClass(PushGateway.class) - @ConditionalOnProperty(prefix = "management.metrics.export.prometheus.pushgateway", name = "enabled") - public static class PrometheusPushGatewayConfiguration { - - private static final Log logger = LogFactory - .getLog(PrometheusPushGatewayConfiguration.class); - - /** - * The fallback job name. We use 'spring' since there's a history of Prometheus - * spring integration defaulting to that name from when Prometheus integration - * didn't exist in Spring itself. - */ - private static final String FALLBACK_JOB = "spring"; - - @Bean - @ConditionalOnMissingBean - public PrometheusPushGatewayManager prometheusPushGatewayManager( - CollectorRegistry collectorRegistry, - PrometheusProperties prometheusProperties, Environment environment) { - PrometheusProperties.Pushgateway properties = prometheusProperties - .getPushgateway(); - Duration pushRate = properties.getPushRate(); - String job = getJob(properties, environment); - Map groupingKey = properties.getGroupingKey(); - PrometheusPushGatewayManager.ShutdownOperation shutdownOperation = properties.getShutdownOperation(); - return new PrometheusPushGatewayManager( - getPushGateway(properties.getBaseUrl()), collectorRegistry, pushRate, - job, groupingKey, shutdownOperation); - } - - private PushGateway getPushGateway(String url) { - try { - return new PushGateway(new URL(url)); - } - catch (MalformedURLException ex) { - logger.warn(String.format( - "Invalid PushGateway base url '%s': update your configuration to a valid URL", - url)); - return new PushGateway(url); - } - } - - private String getJob(PrometheusProperties.Pushgateway properties, - Environment environment) { - String job = properties.getJob(); - job = (job != null) ? job - : environment.getProperty("spring.application.name"); - return (job != null) ? job : FALLBACK_JOB; - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusProperties.java deleted file mode 100644 index 39b9134beb..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusProperties.java +++ /dev/null @@ -1,160 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.prometheus; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.time.Duration; -import java.util.HashMap; -import java.util.Map; - -import io.micrometer.spring.export.prometheus.PrometheusPushGatewayManager.ShutdownOperation; - -/** - * {@link ConfigurationProperties} for configuring metrics export to Prometheus. - * - * @author Jon Schneider - */ -@ConfigurationProperties(prefix = "management.metrics.export.prometheus") -public class PrometheusProperties { - - /** - * Whether to enable publishing descriptions as part of the scrape payload to - * Prometheus. Turn this off to minimize the amount of data sent on each scrape. - */ - private boolean descriptions = true; - - /** - * Configuration options for using Prometheus Pushgateway, allowing metrics to be - * pushed when they cannot be scraped. - */ - private Pushgateway pushgateway = new Pushgateway(); - - /** - * Step size (i.e. reporting frequency) to use. - */ - private Duration step = Duration.ofMinutes(1); - - public boolean isDescriptions() { - return this.descriptions; - } - - public void setDescriptions(boolean descriptions) { - this.descriptions = descriptions; - } - - public Duration getStep() { - return this.step; - } - - public void setStep(Duration step) { - this.step = step; - } - - public Pushgateway getPushgateway() { - return this.pushgateway; - } - - public void setPushgateway(Pushgateway pushgateway) { - this.pushgateway = pushgateway; - } - - /** - * Configuration options for push-based interaction with Prometheus. - */ - public static class Pushgateway { - - /** - * Enable publishing via a Prometheus Pushgateway. - */ - private Boolean enabled = false; - - /** - * Base URL for the Pushgateway. - */ - private String baseUrl = "http://localhost:9091"; - - /** - * Frequency with which to push metrics. - */ - private Duration pushRate = Duration.ofMinutes(1); - - /** - * Job identifier for this application instance. - */ - private String job; - - /** - * Grouping key for the pushed metrics. - */ - private Map groupingKey = new HashMap<>(); - - /** - * Operation that should be performed on shutdown. - */ - private ShutdownOperation shutdownOperation = ShutdownOperation.NONE; - - public Boolean getEnabled() { - return this.enabled; - } - - public void setEnabled(Boolean enabled) { - this.enabled = enabled; - } - - public String getBaseUrl() { - return this.baseUrl; - } - - public void setBaseUrl(String baseUrl) { - this.baseUrl = baseUrl; - } - - public Duration getPushRate() { - return this.pushRate; - } - - public void setPushRate(Duration pushRate) { - this.pushRate = pushRate; - } - - public String getJob() { - return this.job; - } - - public void setJob(String job) { - this.job = job; - } - - public Map getGroupingKey() { - return this.groupingKey; - } - - public void setGroupingKey(Map groupingKey) { - this.groupingKey = groupingKey; - } - - public ShutdownOperation getShutdownOperation() { - return this.shutdownOperation; - } - - public void setShutdownOperation(ShutdownOperation shutdownOperation) { - this.shutdownOperation = shutdownOperation; - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusPropertiesConfigAdapter.java deleted file mode 100644 index 901b9c25ba..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusPropertiesConfigAdapter.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.prometheus; - -import io.micrometer.prometheus.PrometheusConfig; -import io.micrometer.spring.autoconfigure.export.properties.PropertiesConfigAdapter; - -import java.time.Duration; - -/** - * Adapter to convert {@link PrometheusProperties} to a {@link PrometheusConfig}. - * - * @author Jon Schneider - * @author Phillip Webb - */ -class PrometheusPropertiesConfigAdapter extends PropertiesConfigAdapter implements PrometheusConfig { - - PrometheusPropertiesConfigAdapter(PrometheusProperties properties) { - super(properties); - } - - @Override - public String get(String key) { - return null; - } - - @Override - public boolean descriptions() { - return get(PrometheusProperties::isDescriptions, - PrometheusConfig.super::descriptions); - } - - @Override - public Duration step() { - return get(PrometheusProperties::getStep, PrometheusConfig.super::step); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/PropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/PropertiesConfigAdapter.java deleted file mode 100644 index ac84e9f9f1..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/PropertiesConfigAdapter.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.properties; - -import org.springframework.util.Assert; - -import java.util.function.Function; -import java.util.function.Supplier; - -/** - * Base class for properties to config adapters. - * - * @param The properties type - * @author Phillip Webb - * @author Nikolay Rybak - */ -public class PropertiesConfigAdapter { - - private T properties; - - /** - * Create a new {@link PropertiesConfigAdapter} instance. - * - * @param properties the source properties - */ - public PropertiesConfigAdapter(T properties) { - Assert.notNull(properties, "Properties must not be null"); - this.properties = properties; - } - - /** - * Get the value from the properties or use a fallback from the {@code defaults}. - * - * @param getter the getter for the properties - * @param fallback the fallback method, usually super interface method reference - * @param the value type - * @return the property or fallback value - */ - protected final V get(Function getter, Supplier fallback) { - V value = getter.apply(properties); - return (value != null ? value : fallback.get()); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryProperties.java deleted file mode 100644 index 044559cc62..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryProperties.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.properties; - -import java.time.Duration; - -/** - * Base class for properties that configure a metrics registry that pushes aggregated - * metrics on a regular interval. - * - * @author Jon Schneider - * @author Andy Wilkinson - */ -public abstract class StepRegistryProperties { - - /** - * Step size (i.e. reporting frequency) to use. - */ - private Duration step = Duration.ofMinutes(1); - - /** - * Whether exporting of metrics to this backend is enabled. - */ - private boolean enabled = true; - - /** - * Connection timeout for requests to this backend. - */ - private Duration connectTimeout = Duration.ofSeconds(1); - - /** - * Read timeout for requests to this backend. - */ - private Duration readTimeout = Duration.ofSeconds(10); - - /** - * Number of threads to use with the metrics publishing scheduler. - */ - private Integer numThreads = 2; - - /** - * Number of measurements per request to use for this backend. If more measurements - * are found, then multiple requests will be made. - */ - private Integer batchSize = 10000; - - public Duration getStep() { - return this.step; - } - - public void setStep(Duration step) { - this.step = step; - } - - public boolean isEnabled() { - return this.enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public Duration getConnectTimeout() { - return this.connectTimeout; - } - - public void setConnectTimeout(Duration connectTimeout) { - this.connectTimeout = connectTimeout; - } - - public Duration getReadTimeout() { - return this.readTimeout; - } - - public void setReadTimeout(Duration readTimeout) { - this.readTimeout = readTimeout; - } - - public Integer getNumThreads() { - return this.numThreads; - } - - public void setNumThreads(Integer numThreads) { - this.numThreads = numThreads; - } - - public Integer getBatchSize() { - return this.batchSize; - } - - public void setBatchSize(Integer batchSize) { - this.batchSize = batchSize; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesConfigAdapter.java deleted file mode 100644 index 1d7a2bac52..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesConfigAdapter.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.properties; - -import io.micrometer.core.instrument.step.StepRegistryConfig; - -import java.time.Duration; - -/** - * Base class for {@link StepRegistryProperties} to {@link StepRegistryConfig} adapters. - * - * @param The properties type - * @author Jon Schneider - * @author Phillip Webb - */ -public abstract class StepRegistryPropertiesConfigAdapter - extends PropertiesConfigAdapter implements StepRegistryConfig { - - public StepRegistryPropertiesConfigAdapter(T properties) { - super(properties); - } - - @Override - public String prefix() { - return null; - } - - @Override - public String get(String key) { - return null; - } - - @Override - public Duration step() { - return get(T::getStep, StepRegistryConfig.super::step); - } - - @Override - public boolean enabled() { - return get(T::isEnabled, StepRegistryConfig.super::enabled); - } - - @Override - public Duration connectTimeout() { - return get(T::getConnectTimeout, StepRegistryConfig.super::connectTimeout); - } - - @Override - public Duration readTimeout() { - return get(T::getReadTimeout, StepRegistryConfig.super::readTimeout); - } - - @Override - public int numThreads() { - return get(T::getNumThreads, StepRegistryConfig.super::numThreads); - } - - @Override - public int batchSize() { - return get(T::getBatchSize, StepRegistryConfig.super::batchSize); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxMetricsExportAutoConfiguration.java deleted file mode 100644 index e17eeb9ab3..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.signalfx; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.signalfx.SignalFxConfig; -import io.micrometer.signalfx.SignalFxMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to SignalFx. - * - * @author Jon Schneider - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(SignalFxMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.signalfx", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(SignalFxProperties.class) -@Import(StringToDurationConverter.class) -public class SignalFxMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public SignalFxConfig signalFxConfig(SignalFxProperties props) { - return new SignalFxPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public SignalFxMeterRegistry signalFxMeterRegistry(SignalFxConfig config, Clock clock) { - return new SignalFxMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxProperties.java deleted file mode 100644 index 97a04fbaf3..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxProperties.java +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.signalfx; - -import java.time.Duration; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring metrics export to SignalFX. - * - * @author Jon Schneider - */ -@ConfigurationProperties(prefix = "management.metrics.export.signalfx") -public class SignalFxProperties extends StepRegistryProperties { - - /** - * Step size (i.e. reporting frequency) to use. - */ - private Duration step = Duration.ofSeconds(10); - - /** - * SignalFX access token. - */ - private String accessToken; - - /** - * URI to ship metrics to. - */ - private String uri = "https://ingest.signalfx.com"; - - /** - * Uniquely identifies the app instance that is publishing metrics to SignalFx. - * Defaults to the local host name. - */ - private String source; - - @Override - public Duration getStep() { - return this.step; - } - - @Override - public void setStep(Duration step) { - this.step = step; - } - - public String getAccessToken() { - return this.accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public String getUri() { - return this.uri; - } - - public void setUri(String uri) { - this.uri = uri; - } - - public String getSource() { - return this.source; - } - - public void setSource(String source) { - this.source = source; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxPropertiesConfigAdapter.java deleted file mode 100644 index 0231ad2e95..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/signalfx/SignalFxPropertiesConfigAdapter.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.signalfx; - -import io.micrometer.signalfx.SignalFxConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; - -/** - * Adapter to convert {@link SignalFxProperties} to a {@link SignalFxConfig}. - * - * @author Jon Schneider - */ -class SignalFxPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter - implements SignalFxConfig { - - SignalFxPropertiesConfigAdapter(SignalFxProperties properties) { - super(properties); - accessToken(); // validate that an access token is set - } - - @Override - public String accessToken() { - return get(SignalFxProperties::getAccessToken, SignalFxConfig.super::accessToken); - } - - @Override - public String uri() { - return get(SignalFxProperties::getUri, SignalFxConfig.super::uri); - } - - @Override - public String source() { - return get(SignalFxProperties::getSource, SignalFxConfig.super::source); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimpleMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimpleMetricsExportAutoConfiguration.java deleted file mode 100644 index ea4c314e58..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimpleMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.simple; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to a {@link SimpleMeterRegistry}. - * - * @author Jon Schneider - */ -@Configuration -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@AutoConfigureBefore(CompositeMeterRegistryAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@EnableConfigurationProperties(SimpleProperties.class) -@ConditionalOnMissingBean(MeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.simple", name = "enabled", havingValue = "true", matchIfMissing = true) -@Import(StringToDurationConverter.class) -public class SimpleMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public SimpleConfig simpleRegistryConfig(SimpleProperties props) { - return new SimplePropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean(MeterRegistry.class) - public SimpleMeterRegistry simpleMeterRegistry(SimpleConfig config, Clock clock) { - return new SimpleMeterRegistry(config, clock); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimpleProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimpleProperties.java deleted file mode 100644 index ea137153f2..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimpleProperties.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.simple; - -import io.micrometer.core.instrument.simple.CountingMode; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.time.Duration; - -/** - * {@link ConfigurationProperties} for configuring metrics export to a - * {@link SimpleMeterRegistry}. - * - * @author Jon Schneider - */ -@ConfigurationProperties(prefix = "management.metrics.export.simple") -public class SimpleProperties { - - /** - * Step size (i.e. reporting frequency) to use. - */ - private Duration step = Duration.ofMinutes(1); - - /** - * Counting mode. - */ - private CountingMode mode = CountingMode.CUMULATIVE; - - public Duration getStep() { - return this.step; - } - - public void setStep(Duration step) { - this.step = step; - } - - public CountingMode getMode() { - return this.mode; - } - - public void setMode(CountingMode mode) { - this.mode = mode; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimplePropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimplePropertiesConfigAdapter.java deleted file mode 100644 index 95f0d399d0..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/simple/SimplePropertiesConfigAdapter.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.simple; - -import io.micrometer.core.instrument.simple.CountingMode; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.spring.autoconfigure.export.properties.PropertiesConfigAdapter; - -import java.time.Duration; - -/** - * Adapter to convert {@link SimpleProperties} to a {@link SimpleConfig}. - * - * @author Jon Schneider - */ -class SimplePropertiesConfigAdapter extends PropertiesConfigAdapter implements SimpleConfig { - - SimplePropertiesConfigAdapter(SimpleProperties properties) { - super(properties); - } - - @Override - public String get(String key) { - return null; - } - - @Override - public Duration step() { - return get(SimpleProperties::getStep, SimpleConfig.super::step); - } - - @Override - public CountingMode mode() { - return get(SimpleProperties::getMode, SimpleConfig.super::mode); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverMetricsExportAutoConfiguration.java deleted file mode 100644 index 750445b2df..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.stackdriver; - -import com.google.api.gax.core.FixedCredentialsProvider; -import com.google.auth.oauth2.ServiceAccountCredentials; -import com.google.cloud.monitoring.v3.MetricServiceSettings; -import io.micrometer.core.instrument.Clock; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import io.micrometer.stackdriver.StackdriverConfig; -import io.micrometer.stackdriver.StackdriverMeterRegistry; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.core.io.Resource; - -/** - * Configuration for exporting metrics to Stackdriver. - * - * @author Jon Schneider - * @since 1.1.0 - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(StackdriverMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.stackdriver", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(StackdriverProperties.class) -@Import(StringToDurationConverter.class) -public class StackdriverMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - public StackdriverConfig stackdriverConfig(StackdriverProperties props) { - return new StackdriverPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public StackdriverMeterRegistry stackdriverMeterRegistry(StackdriverConfig config, StackdriverProperties props, Clock clock) { - return StackdriverMeterRegistry.builder(config) - .clock(clock) - .metricServiceSettings(() -> { - MetricServiceSettings.Builder settingsBuilder = MetricServiceSettings.newBuilder(); - Resource credentials = props.getServiceAccountCredentials(); - if (credentials != null) { - settingsBuilder.setCredentialsProvider( - FixedCredentialsProvider.create(ServiceAccountCredentials.fromStream(credentials.getInputStream()))); - } - return settingsBuilder.build(); - }) - .build(); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverProperties.java deleted file mode 100644 index 3e7add086f..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverProperties.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.stackdriver; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.core.io.Resource; - -import java.time.Duration; - -/** - * {@link ConfigurationProperties} for configuring metrics export to Stackdriver. - * - * @author Jon Schneider - * @since 1.1.0 - */ -@ConfigurationProperties(prefix = "management.metrics.export.stackdriver") -public class StackdriverProperties extends StepRegistryProperties { - - /** - * Step size (i.e. reporting frequency) to use. - */ - private Duration step = Duration.ofSeconds(10); - - /** - * Google Cloud project id. - */ - private String projectId; - - /** - * Location of JSON representation of Google Cloud service account credentials - * with at least write access to the monitoring API. - */ - private Resource serviceAccountCredentials; - - @Override - public Duration getStep() { - return this.step; - } - - @Override - public void setStep(Duration step) { - this.step = step; - } - - public String getProjectId() { - return projectId; - } - - public void setProjectId(String projectId) { - this.projectId = projectId; - } - - public Resource getServiceAccountCredentials() { - return serviceAccountCredentials; - } - - public void setServiceAccountCredentials(Resource serviceAccountCredentials) { - this.serviceAccountCredentials = serviceAccountCredentials; - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverPropertiesConfigAdapter.java deleted file mode 100644 index c03b7030f8..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverPropertiesConfigAdapter.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.stackdriver; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; -import io.micrometer.stackdriver.StackdriverConfig; - -/** - * Adapter to convert {@link StackdriverProperties} to a {@link StackdriverConfig}. - * - * @author Jon Schneider - */ -class StackdriverPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter - implements StackdriverConfig { - - StackdriverPropertiesConfigAdapter(StackdriverProperties properties) { - super(properties); - } - - @Override - public String projectId() { - return get(StackdriverProperties::getProjectId, StackdriverConfig.super::projectId); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdMetricsExportAutoConfiguration.java deleted file mode 100644 index 4a5ce759b4..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.statsd; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import io.micrometer.statsd.StatsdConfig; -import io.micrometer.statsd.StatsdMeterRegistry; -import io.micrometer.statsd.StatsdMetrics; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Configuration for exporting metrics to a StatsD agent. - * - * @author Jon Schneider - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(StatsdMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.statsd", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(StatsdProperties.class) -@Import(StringToDurationConverter.class) -public class StatsdMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(StatsdConfig.class) - public StatsdConfig statsdConfig(StatsdProperties props) { - return new StatsdPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public StatsdMeterRegistry statsdMeterRegistry(StatsdConfig config, Clock clock) { - return new StatsdMeterRegistry(config, clock); - } - - @Bean - public StatsdMetrics statsdMetrics() { - return new StatsdMetrics(); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdProperties.java deleted file mode 100644 index 1333f40235..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdProperties.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.statsd; - -import io.micrometer.statsd.StatsdFlavor; -import io.micrometer.statsd.StatsdProtocol; -import org.springframework.boot.context.properties.ConfigurationProperties; - -import java.time.Duration; - -/** - * {@link ConfigurationProperties} for configuring StatsD metrics export. - * - * @author Jon Schneider - * @author Stephane Nicoll - */ -@ConfigurationProperties(prefix = "management.metrics.export.statsd") -public class StatsdProperties { - - /** - * Whether exporting of metrics to StatsD is enabled. - */ - private boolean enabled = true; - - /** - * StatsD line protocol to use. - */ - private StatsdFlavor flavor = StatsdFlavor.DATADOG; - - /** - * Host of the StatsD server to receive exported metrics. - */ - private String host = "localhost"; - - /** - * Port of the StatsD server to receive exported metrics. - */ - private Integer port = 8125; - - /** - * Protocol of the StatsD server to receive exported metrics. - */ - private StatsdProtocol protocol = StatsdProtocol.UDP; - - /** - * Total length of a single payload should be kept within your network's MTU. - */ - private Integer maxPacketLength = 1400; - - /** - * How often gauges will be polled. When a gauge is polled, its value is recalculated - * and if the value has changed (or publishUnchangedMeters is true), it is sent to the - * StatsD server. - */ - private Duration pollingFrequency = Duration.ofSeconds(10); - - /** - * Whether to send unchanged meters to the StatsD server. - */ - private boolean publishUnchangedMeters = true; - - /** Whether measurements should be buffered before sending to the StatsD server. */ - private boolean buffered = true; - - public boolean isEnabled() { - return this.enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public StatsdFlavor getFlavor() { - return this.flavor; - } - - public void setFlavor(StatsdFlavor flavor) { - this.flavor = flavor; - } - - public String getHost() { - return this.host; - } - - public void setHost(String host) { - this.host = host; - } - - public Integer getPort() { - return this.port; - } - - public void setPort(Integer port) { - this.port = port; - } - - public StatsdProtocol getProtocol() { - return this.protocol; - } - - public void setProtocol(StatsdProtocol protocol) { - this.protocol = protocol; - } - - public Integer getMaxPacketLength() { - return this.maxPacketLength; - } - - public void setMaxPacketLength(Integer maxPacketLength) { - this.maxPacketLength = maxPacketLength; - } - - public Duration getPollingFrequency() { - return this.pollingFrequency; - } - - public void setPollingFrequency(Duration pollingFrequency) { - this.pollingFrequency = pollingFrequency; - } - - public boolean isPublishUnchangedMeters() { - return this.publishUnchangedMeters; - } - - public void setPublishUnchangedMeters(boolean publishUnchangedMeters) { - this.publishUnchangedMeters = publishUnchangedMeters; - } - - public boolean isBuffered() { - return buffered; - } - - public void setBuffered(boolean buffered) { - this.buffered = buffered; - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdPropertiesConfigAdapter.java deleted file mode 100644 index 4cfc971133..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/statsd/StatsdPropertiesConfigAdapter.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.statsd; - -import io.micrometer.spring.autoconfigure.export.properties.PropertiesConfigAdapter; -import io.micrometer.statsd.StatsdConfig; -import io.micrometer.statsd.StatsdFlavor; -import io.micrometer.statsd.StatsdProtocol; - -import java.time.Duration; - -/** - * Adapter to convert {@link StatsdProperties} to a {@link StatsdConfig}. - * - * @author Jon Schneider - */ -class StatsdPropertiesConfigAdapter extends PropertiesConfigAdapter implements StatsdConfig { - - StatsdPropertiesConfigAdapter(StatsdProperties properties) { - super(properties); - } - - @Override - public String get(String key) { - return null; - } - - @Override - public StatsdFlavor flavor() { - return get(StatsdProperties::getFlavor, StatsdConfig.super::flavor); - } - - @Override - public boolean enabled() { - return get(StatsdProperties::isEnabled, StatsdConfig.super::enabled); - } - - @Override - public String host() { - return get(StatsdProperties::getHost, StatsdConfig.super::host); - } - - @Override - public int port() { - return get(StatsdProperties::getPort, StatsdConfig.super::port); - } - - @Override - public StatsdProtocol protocol() { - return get(StatsdProperties::getProtocol, StatsdConfig.super::protocol); - } - - @Override - public int maxPacketLength() { - return get(StatsdProperties::getMaxPacketLength, - StatsdConfig.super::maxPacketLength); - } - - @Override - public Duration pollingFrequency() { - return get(StatsdProperties::getPollingFrequency, - StatsdConfig.super::pollingFrequency); - } - - @Override - public boolean publishUnchangedMeters() { - return get(StatsdProperties::isPublishUnchangedMeters, StatsdConfig.super::publishUnchangedMeters); - } - - @Override - public boolean buffered() { - return get(StatsdProperties::isBuffered, StatsdConfig.super::buffered); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontMetricsExportAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontMetricsExportAutoConfiguration.java deleted file mode 100644 index 092f932656..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontMetricsExportAutoConfiguration.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.wavefront; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.StringToDurationConverter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import io.micrometer.wavefront.WavefrontConfig; -import io.micrometer.wavefront.WavefrontMeterRegistry; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.AutoConfigureBefore; -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.condition.ConditionalOnProperty; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -/** - * Auto-configuration for Wavefront. - * - * @author Jon Schneider - * @since 1.0.0 - */ -@Configuration -@AutoConfigureBefore({CompositeMeterRegistryAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@AutoConfigureAfter(MetricsAutoConfiguration.class) -@ConditionalOnBean(Clock.class) -@ConditionalOnClass(WavefrontMeterRegistry.class) -@ConditionalOnProperty(prefix = "management.metrics.export.wavefront", name = "enabled", havingValue = "true", matchIfMissing = true) -@EnableConfigurationProperties(WavefrontProperties.class) -@Import(StringToDurationConverter.class) -public class WavefrontMetricsExportAutoConfiguration { - - @Bean - @ConditionalOnMissingBean(WavefrontConfig.class) - public WavefrontConfig wavefrontConfig(WavefrontProperties props) { - return new WavefrontPropertiesConfigAdapter(props); - } - - @Bean - @ConditionalOnMissingBean - public WavefrontMeterRegistry wavefrontMeterRegistry(WavefrontConfig config, Clock clock) { - return new WavefrontMeterRegistry(config, clock); - } - - @Bean - @ConditionalOnMissingBean - public Clock micrometerClock() { - return Clock.SYSTEM; - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontProperties.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontProperties.java deleted file mode 100644 index 46e64131d5..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontProperties.java +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.wavefront; - -import java.net.URI; -import java.time.Duration; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryProperties; -import org.springframework.boot.context.properties.ConfigurationProperties; - -/** - * {@link ConfigurationProperties} for configuring Wavefront metrics export. - * - * @author Jon Schneider - * @since 1.0.0 - */ -@ConfigurationProperties("management.metrics.export.wavefront") -public class WavefrontProperties extends StepRegistryProperties { - - /** - * Step size (i.e. reporting frequency) to use. - */ - private Duration step = Duration.ofSeconds(10); - - /** - * URI to ship metrics to. - */ - private URI uri = URI.create("https://longboard.wavefront.com"); - - /** - * Unique identifier for the app instance that is the source of metrics being - * published to Wavefront. Defaults to the local host name. - */ - private String source; - - /** - * API token used when publishing metrics directly to the Wavefront API host. - */ - private String apiToken; - - /** - * Global prefix to separate metrics originating from this app's white box - * instrumentation from those originating from other Wavefront integrations when - * viewed in the Wavefront UI. - */ - private String globalPrefix; - - /** - * Report histogram distributions aggregated into minute intervals. - */ - private boolean reportMinuteDistribution = true; - - /** - * Report histogram distributions aggregated into hour intervals. - */ - private boolean reportHourDistribution = false; - - /** - * Report histogram distributions aggregated into day intervals. - */ - private boolean reportDayDistribution = false; - - public URI getUri() { - return this.uri; - } - - public void setUri(URI uri) { - this.uri = uri; - } - - @Override - public Duration getStep() { - return this.step; - } - - @Override - public void setStep(Duration step) { - this.step = step; - } - - public String getSource() { - return this.source; - } - - public void setSource(String source) { - this.source = source; - } - - public String getApiToken() { - return this.apiToken; - } - - public void setApiToken(String apiToken) { - this.apiToken = apiToken; - } - - public String getGlobalPrefix() { - return this.globalPrefix; - } - - public void setGlobalPrefix(String globalPrefix) { - this.globalPrefix = globalPrefix; - } - - public boolean isReportMinuteDistribution() { - return reportMinuteDistribution; - } - - public void setReportMinuteDistribution(boolean reportMinuteDistribution) { - this.reportMinuteDistribution = reportMinuteDistribution; - } - - public boolean isReportHourDistribution() { - return reportHourDistribution; - } - - public void setReportHourDistribution(boolean reportHourDistribution) { - this.reportHourDistribution = reportHourDistribution; - } - - public boolean isReportDayDistribution() { - return reportDayDistribution; - } - - public void setReportDayDistribution(boolean reportDayDistribution) { - this.reportDayDistribution = reportDayDistribution; - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontPropertiesConfigAdapter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontPropertiesConfigAdapter.java deleted file mode 100644 index a5771f04b1..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/export/wavefront/WavefrontPropertiesConfigAdapter.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.wavefront; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapter; -import io.micrometer.wavefront.WavefrontConfig; - -/** - * Adapter to convert {@link WavefrontProperties} to a {@link WavefrontConfig}. - * - * @author Jon Schneider - */ -class WavefrontPropertiesConfigAdapter extends StepRegistryPropertiesConfigAdapter implements WavefrontConfig { - - WavefrontPropertiesConfigAdapter(WavefrontProperties properties) { - super(properties); - } - - @Override - public String get(String k) { - return null; - } - - @Override - public String uri() { - return get(this::getUriAsString, WavefrontConfig.DEFAULT_DIRECT::uri); - } - - @Override - public String source() { - return get(WavefrontProperties::getSource, WavefrontConfig.super::source); - } - - @Override - public String apiToken() { - return get(WavefrontProperties::getApiToken, WavefrontConfig.super::apiToken); - } - - @Override - public boolean reportMinuteDistribution() { - return get(WavefrontProperties::isReportMinuteDistribution, WavefrontConfig.super::reportMinuteDistribution); - } - - @Override - public boolean reportHourDistribution() { - return get(WavefrontProperties::isReportHourDistribution, WavefrontConfig.super::reportHourDistribution); - } - - @Override - public boolean reportDayDistribution() { - return get(WavefrontProperties::isReportDayDistribution, WavefrontConfig.super::reportDayDistribution); - } - - @Override - public String globalPrefix() { - return get(WavefrontProperties::getGlobalPrefix, WavefrontConfig.super::globalPrefix); - } - - private String getUriAsString(WavefrontProperties properties) { - return (properties.getUri() != null) ? properties.getUri().toString() : null; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/jdbc/DataSourcePoolMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/jdbc/DataSourcePoolMetricsAutoConfiguration.java deleted file mode 100644 index 3c4644e866..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/jdbc/DataSourcePoolMetricsAutoConfiguration.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.jdbc; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; - -import io.micrometer.spring.jdbc.DataSourcePoolMetrics; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.AllNestedConditions; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.StringUtils; - -import javax.sql.DataSource; -import java.util.Collection; -import java.util.Collections; -import java.util.Map; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for metrics on all available - * {@link DataSource datasources}. - * - * @author Stephane Nicoll - * @author Johnny Lim - */ -@Configuration -@AutoConfigureAfter({ MetricsAutoConfiguration.class, DataSourceAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class }) -@ConditionalOnClass({ DataSource.class, MeterRegistry.class }) -@Conditional(DataSourcePoolMetricsAutoConfiguration.DataSourcePoolMetricsConditionalOnBeans.class) -public class DataSourcePoolMetricsAutoConfiguration { - - @Configuration - @ConditionalOnBean(DataSourcePoolMetadataProvider.class) - static class DataSourcePoolMetadataMetricsConfiguration { - - private static final String DATASOURCE_SUFFIX = "dataSource"; - - private final MeterRegistry registry; - - private final Collection metadataProviders; - - DataSourcePoolMetadataMetricsConfiguration(MeterRegistry registry, - Collection metadataProviders) { - this.registry = registry; - this.metadataProviders = metadataProviders; - } - - @Autowired - public void bindDataSourcesToRegistry(Map dataSources) { - dataSources.forEach(this::bindDataSourceToRegistry); - } - - private void bindDataSourceToRegistry(String beanName, DataSource dataSource) { - String dataSourceName = getDataSourceName(beanName); - new DataSourcePoolMetrics(dataSource, this.metadataProviders, dataSourceName, - Collections.emptyList()).bindTo(this.registry); - } - - /** - * Get the name of a DataSource based on its {@code beanName}. - * @param beanName the name of the data source bean - * @return a name for the given data source - */ - private String getDataSourceName(String beanName) { - if (beanName.length() > DATASOURCE_SUFFIX.length() - && StringUtils.endsWithIgnoreCase(beanName, DATASOURCE_SUFFIX)) { - return beanName.substring(0, - beanName.length() - DATASOURCE_SUFFIX.length()); - } - return beanName; - } - - } - - static class DataSourcePoolMetricsConditionalOnBeans extends AllNestedConditions { - - DataSourcePoolMetricsConditionalOnBeans() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @ConditionalOnBean(DataSource.class) - static class ConditionalOnDataSourceBean { - } - - @ConditionalOnBean(MeterRegistry.class) - static class ConditionalOnMeterRegistryBean { - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/jersey/JerseyServerMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/jersey/JerseyServerMetricsAutoConfiguration.java deleted file mode 100644 index ae99e0bfbd..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/jersey/JerseyServerMetricsAutoConfiguration.java +++ /dev/null @@ -1,126 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.jersey; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.jersey2.server.AnnotationFinder; -import io.micrometer.jersey2.server.DefaultJerseyTagsProvider; -import io.micrometer.jersey2.server.JerseyTagsProvider; -import io.micrometer.jersey2.server.MetricsApplicationEventListener; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsProperties; -import io.micrometer.spring.autoconfigure.OnlyOnceLoggingDenyMeterFilter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.glassfish.jersey.server.ResourceConfig; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.AllNestedConditions; -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.condition.ConditionalOnWebApplication; -import org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.core.annotation.Order; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for Jersey server instrumentation. - * - * @author Michael Weirauch - * @author Michael Simons - * @author Andy Wilkinson - * @since 1.1.0 - */ -@Configuration -@AutoConfigureAfter({ MetricsAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class }) -@ConditionalOnWebApplication -@ConditionalOnClass({ ResourceConfig.class, MetricsApplicationEventListener.class }) -@Conditional(JerseyServerMetricsAutoConfiguration.JerseyServerMetricsConditionalOnBeans.class) -@EnableConfigurationProperties(MetricsProperties.class) -public class JerseyServerMetricsAutoConfiguration { - - private final MetricsProperties properties; - - public JerseyServerMetricsAutoConfiguration(MetricsProperties properties) { - this.properties = properties; - } - - @Bean - @ConditionalOnMissingBean(JerseyTagsProvider.class) - public DefaultJerseyTagsProvider jerseyTagsProvider() { - return new DefaultJerseyTagsProvider(); - } - - @Bean - public ResourceConfigCustomizer jerseyServerMetricsResourceConfigCustomizer( - MeterRegistry meterRegistry, JerseyTagsProvider tagsProvider) { - MetricsProperties.Web.Server server = this.properties.getWeb().getServer(); - return (config) -> - config.register(new MetricsApplicationEventListener(meterRegistry, - tagsProvider, server.getRequestsMetricName(), - server.isAutoTimeRequests(), new AnnotationUtilsAnnotationFinder())); - } - - @Bean - @Order(0) - public MeterFilter jerseyMetricsUriTagFilter() { - String metricName = this.properties.getWeb().getServer().getRequestsMetricName(); - MeterFilter filter = new OnlyOnceLoggingDenyMeterFilter(() -> String - .format("Reached the maximum number of URI tags for '%s'.", metricName)); - return MeterFilter.maximumAllowableTags(metricName, "uri", - this.properties.getWeb().getServer().getMaxUriTags(), filter); - } - - /** - * An {@link AnnotationFinder} that uses {@link AnnotationUtils}. - */ - private static class AnnotationUtilsAnnotationFinder implements AnnotationFinder { - - @Override - public A findAnnotation(AnnotatedElement annotatedElement, - Class annotationType) { - return AnnotationUtils.findAnnotation(annotatedElement, annotationType); - } - - } - - static class JerseyServerMetricsConditionalOnBeans extends AllNestedConditions { - - JerseyServerMetricsConditionalOnBeans() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @ConditionalOnBean(MeterRegistry.class) - static class ConditionalOnMeterRegistryBean { - } - - @ConditionalOnBean(ResourceConfig.class) - static class ConditionalOnResourceConfigBean { - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/kafka/consumer/KafkaMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/kafka/consumer/KafkaMetricsAutoConfiguration.java deleted file mode 100644 index 695c9f12e5..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/kafka/consumer/KafkaMetricsAutoConfiguration.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.kafka.consumer; - -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.condition.ConditionalOnProperty; -import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.kafka.KafkaConsumerMetrics; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; - -import javax.management.MBeanServer; -import java.util.Collections; - -/** - * Configuration for {@link KafkaConsumerMetrics}. - * - * @author Wardha Perinkadakattu - * @author Chin Huang - */ -@Configuration -@AutoConfigureAfter({ MetricsAutoConfiguration.class, JmxAutoConfiguration.class }) -@ConditionalOnClass(KafkaConsumerMetrics.class) -@ConditionalOnBean(MeterRegistry.class) -public class KafkaMetricsAutoConfiguration { - - @Bean - @ConditionalOnMissingBean - @ConditionalOnBean(MBeanServer.class) - @ConditionalOnProperty(value = "management.metrics.kafka.consumer.enabled", matchIfMissing = true) - public KafkaConsumerMetrics kafkaConsumerMetrics(MBeanServer mbeanServer) { - return new KafkaConsumerMetrics(mbeanServer, Collections.emptyList()); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/orm/jpa/HibernateMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/orm/jpa/HibernateMetricsAutoConfiguration.java deleted file mode 100644 index e066adfc03..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/orm/jpa/HibernateMetricsAutoConfiguration.java +++ /dev/null @@ -1,110 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.orm.jpa; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.jpa.HibernateMetrics; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.hibernate.SessionFactory; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.autoconfigure.condition.AllNestedConditions; -import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; -import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.StringUtils; - -import javax.persistence.EntityManagerFactory; -import javax.persistence.PersistenceException; - -import java.util.Collections; -import java.util.Map; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for metrics on all available - * Hibernate {@link EntityManagerFactory} instances that have statistics enabled. - * - * @author Rui Figueira - * @author Stephane Nicoll - * @author Johnny Lim - * @since 1.1.0 - */ -@Configuration -@AutoConfigureAfter({MetricsAutoConfiguration.class, HibernateJpaAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class}) -@ConditionalOnClass({EntityManagerFactory.class, SessionFactory.class, MeterRegistry.class}) -@Conditional(HibernateMetricsAutoConfiguration.HibernateMetricsConditionalOnBeans.class) -public class HibernateMetricsAutoConfiguration { - private static final String ENTITY_MANAGER_FACTORY_SUFFIX = "entityManagerFactory"; - - private final MeterRegistry registry; - - public HibernateMetricsAutoConfiguration(MeterRegistry registry) { - this.registry = registry; - } - - @Autowired - public void bindEntityManagerFactoriesToRegistry(Map entityManagerFactories) { - entityManagerFactories.forEach(this::bindEntityManagerFactoryToRegistry); - } - - private void bindEntityManagerFactoryToRegistry(String beanName, EntityManagerFactory entityManagerFactory) { - String entityManagerFactoryName = getEntityManagerFactoryName(beanName); - try { - SessionFactory sessionFactory = entityManagerFactory.unwrap(SessionFactory.class); - new HibernateMetrics(sessionFactory, entityManagerFactoryName, - Collections.emptyList()).bindTo(this.registry); - } - catch (PersistenceException ex) { - } - } - - /** - * Get the name of an {@link EntityManagerFactory} based on its {@code beanName}. - * - * @param beanName the name of the {@link EntityManagerFactory} bean - * @return a name for the given entity manager factory - */ - private String getEntityManagerFactoryName(String beanName) { - if (beanName.length() > ENTITY_MANAGER_FACTORY_SUFFIX.length() && - StringUtils.endsWithIgnoreCase(beanName, ENTITY_MANAGER_FACTORY_SUFFIX)) { - return beanName.substring(0, beanName.length() - ENTITY_MANAGER_FACTORY_SUFFIX.length()); - } - return beanName; - } - - static class HibernateMetricsConditionalOnBeans extends AllNestedConditions { - - HibernateMetricsConditionalOnBeans() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @ConditionalOnBean(MeterRegistry.class) - static class ConditionalOnMeterRegistryBean { - } - - @ConditionalOnBean(EntityManagerFactory.class) - static class ConditionalOnEntityManagerFactoryBean { - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfiguration.java deleted file mode 100644 index 2173502668..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfiguration.java +++ /dev/null @@ -1,124 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web.client; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsProperties; -import io.micrometer.spring.autoconfigure.OnlyOnceLoggingDenyMeterFilter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import io.micrometer.spring.web.client.DefaultRestTemplateExchangeTagsProvider; -import io.micrometer.spring.web.client.MetricsRestTemplateCustomizer; -import io.micrometer.spring.web.client.RestTemplateExchangeTagsProvider; -import org.springframework.beans.factory.ObjectProvider; -import org.springframework.beans.factory.SmartInitializingSingleton; -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.condition.AllNestedConditions; -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.web.WebClientAutoConfiguration; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Conditional; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; -import org.springframework.util.CollectionUtils; -import org.springframework.web.client.AsyncRestTemplate; -import org.springframework.web.client.RestTemplate; - -import java.util.List; - -/** - * Configuration for {@link RestTemplate}- and {@link AsyncRestTemplate}-related metrics. - * - * @author Jon Schneider - * @author Phillip Webb - * @author Raheela Aslam - * @author Johnny Lim - */ -@Configuration -@AutoConfigureAfter({ - MetricsAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class, - WebClientAutoConfiguration.class }) -@ConditionalOnClass(name = { - "org.springframework.web.client.RestTemplate", - "org.springframework.web.client.AsyncRestTemplate", - "org.springframework.boot.web.client.RestTemplateCustomizer" // didn't exist until Boot 1.4 -}) -@Conditional(RestTemplateMetricsAutoConfiguration.RestTemplateMetricsConditionalOnBeans.class) -public class RestTemplateMetricsAutoConfiguration { - - private final MetricsProperties properties; - - public RestTemplateMetricsAutoConfiguration(MetricsProperties properties) { - this.properties = properties; - } - - @Bean - @ConditionalOnMissingBean(RestTemplateExchangeTagsProvider.class) - public DefaultRestTemplateExchangeTagsProvider restTemplateTagConfigurer() { - return new DefaultRestTemplateExchangeTagsProvider(); - } - - @Bean - public MetricsRestTemplateCustomizer metricsRestTemplateCustomizer(MeterRegistry meterRegistry, - RestTemplateExchangeTagsProvider restTemplateTagConfigurer) { - return new MetricsRestTemplateCustomizer(meterRegistry, restTemplateTagConfigurer, - properties.getWeb().getClient().getRequestsMetricName()); - } - - @Bean - public SmartInitializingSingleton metricsAsyncRestTemplateInitializer(final ObjectProvider> asyncRestTemplatesProvider, - final MetricsRestTemplateCustomizer customizer) { - return () -> { - final List asyncRestTemplates = asyncRestTemplatesProvider.getIfAvailable(); - if (!CollectionUtils.isEmpty(asyncRestTemplates)) { - asyncRestTemplates.forEach(customizer::customize); - } - }; - } - - @Bean - @Order(0) - public MeterFilter metricsHttpClientUriTagFilter() { - String metricName = this.properties.getWeb().getClient().getRequestsMetricName(); - MeterFilter denyFilter = new OnlyOnceLoggingDenyMeterFilter(() -> String - .format("Reached the maximum number of URI tags for '%s'. Are you using " - + "'uriVariables'?", metricName)); - return MeterFilter.maximumAllowableTags(metricName, "uri", - this.properties.getWeb().getClient().getMaxUriTags(), denyFilter); - } - - static class RestTemplateMetricsConditionalOnBeans extends AllNestedConditions { - - RestTemplateMetricsConditionalOnBeans() { - super(ConfigurationPhase.REGISTER_BEAN); - } - - @ConditionalOnBean(MeterRegistry.class) - static class ConditionalOnMeterRegistryBean { - } - - @ConditionalOnBean(RestTemplateBuilder.class) - static class ConditionalOnRestTemplateBuilderBean { - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/jetty/JettyMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/jetty/JettyMetricsAutoConfiguration.java deleted file mode 100644 index ea16019c9f..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/jetty/JettyMetricsAutoConfiguration.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web.jetty; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.jetty.JettyServerThreadPoolMetrics; -import io.micrometer.spring.web.jetty.JettyServerThreadPoolMetricsBinder; -import org.eclipse.jetty.server.Server; - -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.condition.ConditionalOnWebApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * Auto-configuration for Jetty metrics. - * - * @author Manabu Matsuzaki - * @author Jon Schneider - * @author Michael Weirauch - * @author Johnny Lim - * @author Andy Wilkinson - */ -@Configuration -@ConditionalOnWebApplication -@ConditionalOnClass({ JettyServerThreadPoolMetrics.class, Server.class }) -public class JettyMetricsAutoConfiguration { - - @Bean - @ConditionalOnBean(MeterRegistry.class) - @ConditionalOnMissingBean({ JettyServerThreadPoolMetrics.class, JettyServerThreadPoolMetricsBinder.class }) - public JettyServerThreadPoolMetricsBinder jettyServerThreadPoolMetricsBinder(MeterRegistry meterRegistry) { - return new JettyServerThreadPoolMetricsBinder(meterRegistry); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/servlet/WebMvcMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/servlet/WebMvcMetricsAutoConfiguration.java deleted file mode 100644 index 1afa11dd3f..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/servlet/WebMvcMetricsAutoConfiguration.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web.servlet; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.MetricsProperties; -import io.micrometer.spring.autoconfigure.OnlyOnceLoggingDenyMeterFilter; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import io.micrometer.spring.web.servlet.DefaultWebMvcTagsProvider; -import io.micrometer.spring.web.servlet.WebMvcMetricsFilter; -import io.micrometer.spring.web.servlet.WebMvcTagsProvider; - -import org.springframework.boot.autoconfigure.AutoConfigureAfter; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -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.condition.ConditionalOnWebApplication; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; -import org.springframework.web.context.WebApplicationContext; -import org.springframework.web.servlet.DispatcherServlet; -import org.springframework.web.servlet.handler.HandlerMappingIntrospector; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for instrumentation of Spring Web - * MVC servlet-based request mappings. - * - * @author Jon Schneider - * @author Dmytro Nosan - */ -@Configuration -@AutoConfigureAfter({ MetricsAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class }) -@ConditionalOnWebApplication -@ConditionalOnClass(DispatcherServlet.class) -@ConditionalOnBean(MeterRegistry.class) -@EnableConfigurationProperties(MetricsProperties.class) -public class WebMvcMetricsAutoConfiguration { - - private final MetricsProperties properties; - - public WebMvcMetricsAutoConfiguration(MetricsProperties properties) { - this.properties = properties; - } - - @Bean - @ConditionalOnMissingBean(WebMvcTagsProvider.class) - public DefaultWebMvcTagsProvider servletTagsProvider() { - return new DefaultWebMvcTagsProvider(); - } - - @SuppressWarnings("deprecation") - @Bean - public WebMvcMetricsFilter webMetricsFilter(MeterRegistry registry, - WebMvcTagsProvider tagsProvider, - WebApplicationContext ctx) { - return new WebMvcMetricsFilter(registry, tagsProvider, - properties.getWeb().getServer().getRequestsMetricName(), - properties.getWeb().getServer().isAutoTimeRequests(), - new HandlerMappingIntrospector(ctx)); - } - - @Bean - @Order(0) - public MeterFilter metricsHttpServerUriTagFilter() { - String metricName = this.properties.getWeb().getServer().getRequestsMetricName(); - MeterFilter filter = new OnlyOnceLoggingDenyMeterFilter(() -> String - .format("Reached the maximum number of URI tags for '%s'.", metricName)); - return MeterFilter.maximumAllowableTags(metricName, "uri", - this.properties.getWeb().getServer().getMaxUriTags(), filter); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/tomcat/TomcatMetricsAutoConfiguration.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/tomcat/TomcatMetricsAutoConfiguration.java deleted file mode 100644 index ee685d10c4..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/autoconfigure/web/tomcat/TomcatMetricsAutoConfiguration.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web.tomcat; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.tomcat.TomcatMetrics; -import io.micrometer.spring.web.tomcat.TomcatMetricsBinder; -import org.apache.catalina.Manager; - -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -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.condition.ConditionalOnWebApplication; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * {@link EnableAutoConfiguration Auto-configuration} for {@link TomcatMetrics}. - * - * @author Clint Checketts - * @author Jon Schneider - * @author Andy Wilkinson - * @since 1.1.0 - */ -@Configuration -@ConditionalOnWebApplication -@ConditionalOnClass({ TomcatMetrics.class, Manager.class }) -public class TomcatMetricsAutoConfiguration { - - @Bean - @ConditionalOnBean(MeterRegistry.class) - @ConditionalOnMissingBean({ TomcatMetrics.class, TomcatMetricsBinder.class }) - public TomcatMetricsBinder tomcatMetricsBinder(MeterRegistry meterRegistry) { - return new TomcatMetricsBinder(meterRegistry); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CacheMeterBinderProvider.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CacheMeterBinderProvider.java deleted file mode 100644 index 7cf5a71562..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CacheMeterBinderProvider.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2018 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.cache; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.binder.MeterBinder; -import org.springframework.cache.Cache; - -/** - * Provide a {@link MeterBinder} based on a {@link Cache}. - * - * @param the cache type - * @author Stephane Nicoll - * @since 1.2.0 - */ -@FunctionalInterface -public interface CacheMeterBinderProvider { - - /** - * Return the {@link MeterBinder} managing the specified {@link Cache} or {@code null} - * if the specified {@link Cache} is not supported. - * - * @param cache the cache to instrument - * @param tags tags to apply to all recorded metrics - * @return a {@link MeterBinder} handling the specified {@link Cache} or {@code null} - */ - MeterBinder getMeterBinder(C cache, Iterable tags); - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CacheMetricsRegistrar.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CacheMetricsRegistrar.java deleted file mode 100644 index a35a1f2d1a..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CacheMetricsRegistrar.java +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2012-2018 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.cache; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.spring.util.LambdaSafe; -import org.springframework.cache.Cache; -import org.springframework.cache.transaction.TransactionAwareCacheDecorator; -import org.springframework.util.ClassUtils; - -import java.util.Collection; -import java.util.Objects; - -/** - * Register supported {@link Cache} to a {@link MeterRegistry}. - * - * @author Stephane Nicoll - * @since 1.2.0 - */ -public class CacheMetricsRegistrar { - - private final MeterRegistry registry; - - private final Collection> binderProviders; - - /** - * Creates a new registrar. - * - * @param registry the {@link MeterRegistry} to use - * @param binderProviders the {@link CacheMeterBinderProvider} instances that should - * be used to detect compatible caches - */ - public CacheMetricsRegistrar(MeterRegistry registry, - Collection> binderProviders) { - this.registry = registry; - this.binderProviders = binderProviders; - } - - /** - * Attempt to bind the specified {@link Cache} to the registry. Return {@code true} if - * the cache is supported and was bound to the registry, {@code false} otherwise. - * - * @param cache the cache to handle - * @param tags the tags to associate with the metrics of that cache - * @return {@code true} if the {@code cache} is supported and was registered - */ - public boolean bindCacheToRegistry(Cache cache, Tag... tags) { - MeterBinder meterBinder = getMeterBinder(unwrapIfNecessary(cache), Tags.of(tags)); - if (meterBinder != null) { - meterBinder.bindTo(this.registry); - return true; - } - return false; - } - - @SuppressWarnings({"unchecked"}) - private MeterBinder getMeterBinder(Cache cache, Tags tags) { - Tags cacheTags = tags.and(getAdditionalTags(cache)); - return LambdaSafe - .callbacks(CacheMeterBinderProvider.class, this.binderProviders, cache) - .withLogger(CacheMetricsRegistrar.class) - .invokeAnd((binderProvider) -> binderProvider.getMeterBinder(cache, - cacheTags)) - .filter(Objects::nonNull).findFirst().orElse(null); - } - - /** - * Return additional {@link Tag tags} to be associated with the given {@link Cache}. - * - * @param cache the cache - * @return a list of additional tags to associate to that {@code cache}. - */ - protected Iterable getAdditionalTags(Cache cache) { - return Tags.of("name", cache.getName()); - } - - private Cache unwrapIfNecessary(Cache cache) { - if (ClassUtils.isPresent( - "org.springframework.cache.transaction.TransactionAwareCacheDecorator", - getClass().getClassLoader())) { - return TransactionAwareCacheDecoratorHandler.unwrapIfNecessary(cache); - } - return cache; - } - - private static class TransactionAwareCacheDecoratorHandler { - - private static Cache unwrapIfNecessary(Cache cache) { - try { - if (cache instanceof TransactionAwareCacheDecorator) { - return ((TransactionAwareCacheDecorator) cache).getTargetCache(); - } - } catch (NoClassDefFoundError ex) { - // Ignore - } - return cache; - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CaffeineCacheMeterBinderProvider.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CaffeineCacheMeterBinderProvider.java deleted file mode 100644 index 8b27000199..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/CaffeineCacheMeterBinderProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2018 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.cache; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.instrument.binder.cache.CaffeineCacheMetrics; -import org.springframework.cache.caffeine.CaffeineCache; - -/** - * {@link CacheMeterBinderProvider} implementation for Caffeine. - * - * @author Stephane Nicoll - * @since 1.2.0 - */ -public class CaffeineCacheMeterBinderProvider - implements CacheMeterBinderProvider { - - @Override - public MeterBinder getMeterBinder(CaffeineCache cache, Iterable tags) { - return new CaffeineCacheMetrics(cache.getNativeCache(), cache.getName(), tags); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/ConcurrentMapCacheMetrics.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/ConcurrentMapCacheMetrics.java deleted file mode 100644 index 3ef58cd752..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/ConcurrentMapCacheMetrics.java +++ /dev/null @@ -1,172 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.cache; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.binder.cache.CacheMeterBinder; -import io.micrometer.core.lang.Nullable; -import org.springframework.cache.concurrent.ConcurrentMapCache; - -import java.util.concurrent.Callable; -import java.util.concurrent.atomic.AtomicLong; - -/** - * @author Jon Schneider - */ -public class ConcurrentMapCacheMetrics extends CacheMeterBinder { - private final MonitoredConcurrentMapCache cache; - - /** - * Record metrics on a ConcurrentMapCache cache. - * - * @param registry The registry to bind metrics to. - * @param cache The cache to instrument. - * @param tags Tags to apply to all recorded metrics. Must be an even number of arguments representing key/value pairs of tags. - * @return The instrumented cache, unchanged. The original cache is not wrapped or proxied in any way. - */ - public static ConcurrentMapCache monitor(MeterRegistry registry, ConcurrentMapCache cache, String... tags) { - return monitor(registry, cache, Tags.of(tags)); - } - - /** - * Record metrics on a ConcurrentMapCache cache. - * - * @param registry The registry to bind metrics to. - * @param cache The cache to instrument. - * @param tags Tags to apply to all recorded metrics. - * @return The instrumented cache, unchanged. The original cache is not wrapped or proxied in any way. - */ - public static ConcurrentMapCache monitor(MeterRegistry registry, ConcurrentMapCache cache, Iterable tags) { - new ConcurrentMapCacheMetrics(cache, tags).bindTo(registry); - return cache; - } - - public ConcurrentMapCacheMetrics(ConcurrentMapCache cache, Iterable tags) { - super(cache, cache.getName(), tags); - this.cache = new MonitoredConcurrentMapCache(cache); - } - - /** - * @return A {@link ConcurrentMapCache} wrapper that collects metrics on its use. - */ - public MonitoredConcurrentMapCache getMonitoredCache() { - return cache; - } - - @Override - protected Long size() { - return (long) cache.getNativeCache().size(); - } - - @Override - protected long hitCount() { - return cache.hitCount.get(); - } - - @Override - protected Long missCount() { - return cache.missCount.get(); - } - - @Override - protected Long evictionCount() { - return cache.evictCount.get(); - } - - @Override - protected long putCount() { - return cache.putCount.get(); - } - - @Override - protected void bindImplementationSpecificMetrics(MeterRegistry registry) { - } - - /** - * A {@link ConcurrentMapCache} wrapper that collects metrics on its use. - */ - public static class MonitoredConcurrentMapCache extends ConcurrentMapCache { - private AtomicLong hitCount = new AtomicLong(0); - private AtomicLong missCount = new AtomicLong(0); - private AtomicLong putCount = new AtomicLong(0); - private AtomicLong evictCount = new AtomicLong(0); - - private ConcurrentMapCache delegate; - - MonitoredConcurrentMapCache(ConcurrentMapCache delegate) { - super(delegate.getName(), delegate.getNativeCache(), delegate.isAllowNullValues()); - this.delegate = delegate; - } - - @Override - public ValueWrapper get(Object key) { - countGet(key); - return delegate.get(key); - } - - @Override - public T get(Object key, Class type) { - countGet(key); - return delegate.get(key, type); - } - - @Nullable - @Override - public T get(Object key, Callable valueLoader) { - countGet(key); - return delegate.get(key, valueLoader); - } - - @Nullable - private ValueWrapper countGet(Object key) { - ValueWrapper valueWrapper = delegate.get(key); - if (valueWrapper != null) - hitCount.incrementAndGet(); - else - missCount.incrementAndGet(); - return valueWrapper; - } - - @Override - public void put(Object key, Object value) { - putCount.incrementAndGet(); - delegate.put(key, value); - } - - @Override - public ValueWrapper putIfAbsent(Object key, Object value) { - if (!getNativeCache().containsKey(key)) { - // no need to synchronize this with the subsequent putIfAbsent, as put count is - // OK to be an approximation. - putCount.incrementAndGet(); - } - return delegate.putIfAbsent(key, value); - } - - @Override - public void evict(Object key) { - evictCount.incrementAndGet(); - delegate.evict(key); - } - - @Override - public void clear() { - delegate.clear(); - } - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/EhCache2CacheMeterBinderProvider.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/EhCache2CacheMeterBinderProvider.java deleted file mode 100644 index 131ec6ac89..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/EhCache2CacheMeterBinderProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2018 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.cache; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.instrument.binder.cache.EhCache2Metrics; -import org.springframework.cache.ehcache.EhCacheCache; - -/** - * {@link CacheMeterBinderProvider} implementation for EhCache2. - * - * @author Stephane Nicoll - * @since 1.2.0 - */ -public class EhCache2CacheMeterBinderProvider - implements CacheMeterBinderProvider { - - @Override - public MeterBinder getMeterBinder(EhCacheCache cache, Iterable tags) { - return new EhCache2Metrics(cache.getNativeCache(), tags); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/HazelcastCacheMeterBinderProvider.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/HazelcastCacheMeterBinderProvider.java deleted file mode 100644 index f874cf4425..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/HazelcastCacheMeterBinderProvider.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2018 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.cache; - -import com.hazelcast.core.IMap; -import com.hazelcast.spring.cache.HazelcastCache; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.instrument.binder.cache.HazelcastCacheMetrics; - -/** - * {@link CacheMeterBinderProvider} implementation for Hazelcast. - * - * @author Stephane Nicoll - * @since 1.2.0 - */ -public class HazelcastCacheMeterBinderProvider - implements CacheMeterBinderProvider { - - @SuppressWarnings("unchecked") - @Override - public MeterBinder getMeterBinder(HazelcastCache cache, Iterable tags) { - return new HazelcastCacheMetrics((IMap) cache.getNativeCache(), tags); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/JCacheCacheMeterBinderProvider.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/JCacheCacheMeterBinderProvider.java deleted file mode 100644 index 87cfbcc664..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/JCacheCacheMeterBinderProvider.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2012-2018 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.cache; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.instrument.binder.cache.JCacheMetrics; -import org.springframework.cache.jcache.JCacheCache; - -/** - * {@link CacheMeterBinderProvider} implementation for JCache. - * - * @author Stephane Nicoll - * @since 1.2.0 - */ -public class JCacheCacheMeterBinderProvider - implements CacheMeterBinderProvider { - - @Override - public MeterBinder getMeterBinder(JCacheCache cache, Iterable tags) { - return new JCacheMetrics(cache.getNativeCache(), tags); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/package-info.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/package-info.java deleted file mode 100644 index bc6f412422..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/cache/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -@NonNullApi -@NonNullFields -package io.micrometer.spring.cache; - -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.NonNullFields; diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusPushGatewayManager.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusPushGatewayManager.java deleted file mode 100644 index a55c859b88..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusPushGatewayManager.java +++ /dev/null @@ -1,200 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.export.prometheus; - -import java.net.UnknownHostException; -import java.time.Duration; -import java.util.Map; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; - -import org.springframework.scheduling.TaskScheduler; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.exporter.PushGateway; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -/** - * Class that can be used to manage the pushing of metrics to a {@link PushGateway - * Prometheus PushGateway}. Handles the scheduling of push operations, error handling and - * shutdown operations. - * - * @author David J. M. Karlsen - * @author Phillip Webb - * @since 1.1.0 - */ -public class PrometheusPushGatewayManager { - - private static final Log logger = LogFactory - .getLog(PrometheusPushGatewayManager.class); - - private final PushGateway pushGateway; - - private final CollectorRegistry registry; - - private final String job; - - private final Map groupingKey; - - private final ShutdownOperation shutdownOperation; - - private final TaskScheduler scheduler; - - private ScheduledFuture scheduled; - - /** - * Create a new {@link PrometheusPushGatewayManager} instance using a single threaded - * {@link TaskScheduler}. - * @param pushGateway the source push gateway - * @param registry the collector registry to push - * @param pushRate the rate at which push operations occur - * @param job the job ID for the operation - * @param groupingKey an optional set of grouping keys for the operation - * @param shutdownOperation the shutdown operation that should be performed when - * context is closed. - */ - public PrometheusPushGatewayManager(PushGateway pushGateway, - CollectorRegistry registry, Duration pushRate, String job, - Map groupingKey, ShutdownOperation shutdownOperation) { - this(pushGateway, registry, new PushGatewayTaskScheduler(), pushRate, job, - groupingKey, shutdownOperation); - } - - /** - * Create a new {@link PrometheusPushGatewayManager} instance. - * @param pushGateway the source push gateway - * @param registry the collector registry to push - * @param scheduler the scheduler used for operations - * @param pushRate the rate at which push operations occur - * @param job the job ID for the operation - * @param groupingKey an optional set of grouping keys for the operation - * @param shutdownOperation the shutdown operation that should be performed when - * context is closed. - */ - public PrometheusPushGatewayManager(PushGateway pushGateway, - CollectorRegistry registry, TaskScheduler scheduler, Duration pushRate, - String job, Map groupingKey, - ShutdownOperation shutdownOperation) { - Assert.notNull(pushGateway, "PushGateway must not be null"); - Assert.notNull(registry, "Registry must not be null"); - Assert.notNull(scheduler, "Scheduler must not be null"); - Assert.notNull(pushRate, "PushRate must not be null"); - Assert.hasLength(job, "Job must not be empty"); - this.pushGateway = pushGateway; - this.registry = registry; - this.job = job; - this.groupingKey = groupingKey; - this.shutdownOperation = (shutdownOperation != null) ? shutdownOperation - : ShutdownOperation.NONE; - this.scheduler = scheduler; - this.scheduled = this.scheduler.scheduleAtFixedRate(this::push, pushRate.toMillis()); - } - - private void push() { - try { - this.pushGateway.pushAdd(this.registry, this.job, this.groupingKey); - } - catch (UnknownHostException ex) { - String host = ex.getMessage(); - String message = "Unable to locate prometheus push gateway host" - + (StringUtils.hasLength(host) ? " '" + host + "'" : "") - + ". No longer attempting metrics publication to this host"; - logger.error(message, ex); - shutdown(ShutdownOperation.NONE); - } - catch (Throwable ex) { - logger.error("Unable to push metrics to Prometheus Pushgateway", ex); - } - } - - private void delete() { - try { - this.pushGateway.delete(this.job, this.groupingKey); - } - catch (Throwable ex) { - logger.error("Unable to delete metrics from Prometheus Pushgateway", ex); - } - } - - /** - * Shutdown the manager, running any {@link ShutdownOperation}. - */ - public void shutdown() { - shutdown(this.shutdownOperation); - } - - private void shutdown(ShutdownOperation shutdownOperation) { - if (this.scheduler instanceof PushGatewayTaskScheduler) { - ((PushGatewayTaskScheduler) this.scheduler).shutdown(); - } - this.scheduled.cancel(false); - switch (shutdownOperation) { - case PUSH: - push(); - break; - case DELETE: - delete(); - break; - } - } - - /** - * The operation that should be performed on shutdown. - */ - public enum ShutdownOperation { - - /** - * Don't perform any shutdown operation. - */ - NONE, - - /** - * Perform a 'push' before shutdown. - */ - PUSH, - - /** - * Perform a 'delete' before shutdown. - */ - DELETE - - } - - /** - * {@link TaskScheduler} used when the user doesn't specify one. - */ - static class PushGatewayTaskScheduler extends ThreadPoolTaskScheduler { - - PushGatewayTaskScheduler() { - setPoolSize(1); - setDaemon(true); - setThreadGroupName("prometheus-push-gateway"); - } - - @Override - public ScheduledExecutorService getScheduledExecutor() - throws IllegalStateException { - return Executors.newSingleThreadScheduledExecutor(this::newThread); - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusScrapeEndpoint.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusScrapeEndpoint.java deleted file mode 100644 index a899523dfb..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusScrapeEndpoint.java +++ /dev/null @@ -1,59 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.export.prometheus; - -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.exporter.common.TextFormat; -import org.springframework.boot.actuate.endpoint.AbstractEndpoint; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.http.ResponseEntity; - -import java.io.IOException; -import java.io.StringWriter; -import java.io.Writer; - -import static org.springframework.http.HttpHeaders.CONTENT_TYPE; - -/** - * Spring Boot Actuator endpoint that outputs Prometheus metrics in a format that - * can be scraped by the Prometheus server - * - * @author Jon Schneider - */ -@ConfigurationProperties("endpoints.prometheus") -public class PrometheusScrapeEndpoint extends AbstractEndpoint> { - - private final CollectorRegistry collectorRegistry; - - public PrometheusScrapeEndpoint(CollectorRegistry collectorRegistry) { - super("prometheus"); - this.collectorRegistry = collectorRegistry; - } - - @Override - public ResponseEntity invoke() { - try { - Writer writer = new StringWriter(); - TextFormat.write004(writer, collectorRegistry.metricFamilySamples()); - return ResponseEntity.ok() - .header(CONTENT_TYPE, TextFormat.CONTENT_TYPE_004) - .body(writer.toString()); - } catch (IOException e) { - // This actually never happens since StringWriter::write() doesn't throw any IOException - throw new RuntimeException("Writing metrics failed", e); - } - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusScrapeMvcEndpoint.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusScrapeMvcEndpoint.java deleted file mode 100644 index d30941c18c..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/export/prometheus/PrometheusScrapeMvcEndpoint.java +++ /dev/null @@ -1,32 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.export.prometheus; - -import org.springframework.boot.actuate.endpoint.mvc.EndpointMvcAdapter; -import org.springframework.web.bind.annotation.GetMapping; - -public class PrometheusScrapeMvcEndpoint extends EndpointMvcAdapter { - - public PrometheusScrapeMvcEndpoint(PrometheusScrapeEndpoint delegate) { - super(delegate); - } - - @GetMapping - @Override - public Object invoke() { - return super.invoke(); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/integration/SpringIntegrationMetrics.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/integration/SpringIntegrationMetrics.java deleted file mode 100644 index 79779769a7..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/integration/SpringIntegrationMetrics.java +++ /dev/null @@ -1,143 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.integration; - -import io.micrometer.core.instrument.*; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.NonNullFields; -import org.springframework.beans.factory.SmartInitializingSingleton; -import org.springframework.integration.support.management.*; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.concurrent.TimeUnit; - -import static java.util.Collections.emptyList; - -/** - * @author Jon Schneider - */ -@NonNullApi -@NonNullFields -public class SpringIntegrationMetrics implements MeterBinder, SmartInitializingSingleton { - private final Iterable tags; - private final IntegrationManagementConfigurer configurer; - private Collection registries = new ArrayList<>(); - - public SpringIntegrationMetrics(IntegrationManagementConfigurer configurer) { - this(configurer, emptyList()); - } - - public SpringIntegrationMetrics(IntegrationManagementConfigurer configurer, Iterable tags) { - this.configurer = configurer; - this.tags = tags; - } - - @Override - public void bindTo(MeterRegistry registry) { - Gauge.builder("spring.integration.channelNames", configurer, c -> c.getChannelNames().length) - .tags(tags) - .description("The number of spring integration channels") - .register(registry); - - Gauge.builder("spring.integration.handlerNames", configurer, c -> c.getHandlerNames().length) - .tags(tags) - .description("The number of spring integration handlers") - .register(registry); - - Gauge.builder("spring.integration.sourceNames", configurer, c -> c.getSourceNames().length) - .tags(tags) - .description("The number of spring integration sources") - .register(registry); - - registries.add(registry); - } - - private void addSourceMetrics(MeterRegistry registry) { - for (String source : configurer.getSourceNames()) { - MessageSourceMetrics sourceMetrics = configurer.getSourceMetrics(source); - Iterable tagsWithSource = Tags.concat(tags, "source", source); - - FunctionCounter.builder("spring.integration.source.messages", sourceMetrics, MessageSourceMetrics::getMessageCount) - .tags(tagsWithSource) - .description("The number of successful handler calls") - .register(registry); - } - } - - private void addHandlerMetrics(MeterRegistry registry) { - for (String handler : configurer.getHandlerNames()) { - MessageHandlerMetrics handlerMetrics = configurer.getHandlerMetrics(handler); - - Iterable tagsWithHandler = Tags.concat(tags, "handler", handler); - - TimeGauge.builder("spring.integration.handler.duration.max", handlerMetrics, TimeUnit.MILLISECONDS, MessageHandlerMetrics::getMaxDuration) - .tags(tagsWithHandler) - .description("The maximum handler duration") - .register(registry); - - TimeGauge.builder("spring.integration.handler.duration.min", handlerMetrics, TimeUnit.MILLISECONDS, MessageHandlerMetrics::getMinDuration) - .tags(tagsWithHandler) - .description("The minimum handler duration") - .register(registry); - - TimeGauge.builder("spring.integration.handler.duration.mean", handlerMetrics, TimeUnit.MILLISECONDS, MessageHandlerMetrics::getMeanDuration) - .tags(tagsWithHandler) - .description("The mean handler duration") - .register(registry); - - Gauge.builder("spring.integration.handler.activeCount", handlerMetrics, MessageHandlerMetrics::getActiveCount) - .tags(tagsWithHandler) - .description("The number of active handlers") - .register(registry); - } - } - - private void addChannelMetrics(MeterRegistry registry) { - for (String channel : configurer.getChannelNames()) { - MessageChannelMetrics channelMetrics = configurer.getChannelMetrics(channel); - Iterable tagsWithChannel = Tags.concat(tags, "channel", channel); - - FunctionCounter.builder("spring.integration.channel.sendErrors", channelMetrics, MessageChannelMetrics::getSendErrorCount) - .tags(tagsWithChannel) - .description("The number of failed sends (either throwing an exception or rejected by the channel)") - .register(registry); - - FunctionCounter.builder("spring.integration.channel.sends", channelMetrics, MessageChannelMetrics::getSendCount) - .tags(tagsWithChannel) - .description("The number of successful sends") - .register(registry); - - if (channelMetrics instanceof PollableChannelManagement) { - FunctionCounter.builder("spring.integration.receives", (PollableChannelManagement) channelMetrics, PollableChannelManagement::getReceiveCount) - .tags(tagsWithChannel) - .description("The number of messages received") - .register(registry); - } - } - } - - @Override - public void afterSingletonsInstantiated() { - configurer.afterSingletonsInstantiated(); - registries.forEach(registry -> { - addChannelMetrics(registry); - addHandlerMetrics(registry); - addSourceMetrics(registry); - }); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/jdbc/DataSourcePoolMetrics.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/jdbc/DataSourcePoolMetrics.java deleted file mode 100644 index 3ecf835998..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/jdbc/DataSourcePoolMetrics.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.jdbc; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.NonNullFields; -import io.micrometer.core.lang.Nullable; -import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadata; -import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider; -import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProviders; - -import javax.sql.DataSource; -import java.util.Collection; - -/** - * @author Jon Schneider - */ -@NonNullApi -@NonNullFields -public class DataSourcePoolMetrics implements MeterBinder { - private final DataSource dataSource; - private final String name; - private final Iterable tags; - - @Nullable - private final DataSourcePoolMetadata poolMetadata; - - public DataSourcePoolMetrics(DataSource dataSource, @Nullable Collection metadataProviders, String name, Iterable tags) { - this.name = name; - this.tags = tags; - this.dataSource = dataSource; - DataSourcePoolMetadataProvider provider = new DataSourcePoolMetadataProviders(metadataProviders); - this.poolMetadata = provider.getDataSourcePoolMetadata(dataSource); - } - - @Override - public void bindTo(MeterRegistry registry) { - if (poolMetadata != null) { - registry.gauge(name + ".connections.active", tags, dataSource, dataSource -> poolMetadata.getActive() != null ? poolMetadata.getActive() : 0); - registry.gauge(name + ".connections.max", tags, dataSource, dataSource -> poolMetadata.getMax()); - registry.gauge(name + ".connections.min", tags, dataSource, dataSource -> poolMetadata.getMin()); - } - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/scheduling/ScheduledMethodMetrics.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/scheduling/ScheduledMethodMetrics.java deleted file mode 100644 index 0b611e416c..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/scheduling/ScheduledMethodMetrics.java +++ /dev/null @@ -1,121 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.scheduling; - -import io.micrometer.core.annotation.Timed; -import io.micrometer.core.instrument.LongTaskTimer; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Timer; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.NonNullFields; -import io.micrometer.spring.TimedUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.aspectj.lang.ProceedingJoinPoint; -import org.aspectj.lang.annotation.Around; -import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.reflect.MethodSignature; - -import java.lang.reflect.Method; -import java.util.concurrent.TimeUnit; - -@NonNullApi -@NonNullFields -@Aspect -public class ScheduledMethodMetrics { - private static final Log logger = LogFactory.getLog(ScheduledMethodMetrics.class); - - private final MeterRegistry registry; - - public ScheduledMethodMetrics(MeterRegistry registry) { - this.registry = registry; - } - - - @Around("execution (@org.springframework.scheduling.annotation.Scheduled * *.*(..))") - public Object timeScheduledOperation(ProceedingJoinPoint pjp) throws Throwable { - Method method = ((MethodSignature) pjp.getSignature()).getMethod(); - String signature = pjp.getSignature().toShortString(); - - if (method.getDeclaringClass().isInterface()) { - try { - method = pjp.getTarget().getClass().getDeclaredMethod(pjp.getSignature().getName(), - method.getParameterTypes()); - } catch (final SecurityException | NoSuchMethodException e) { - logger.warn("Unable to perform metrics timing on " + signature, e); - return pjp.proceed(); - } - } - - Timer shortTaskTimer = null; - LongTaskTimer longTaskTimer = null; - - for (Timed timed : TimedUtils.findTimedAnnotations(method)) { - if (timed.longTask()) - longTaskTimer = LongTaskTimer.builder(timed.value()) - .tags(timed.extraTags()) - .description("Timer of @Scheduled long task") - .register(registry); - else { - Timer.Builder timerBuilder = Timer.builder(timed.value()) - .tags(timed.extraTags()) - .description("Timer of @Scheduled task"); - - if (timed.percentiles().length > 0) { - timerBuilder = timerBuilder.publishPercentiles(timed.percentiles()); - } - - shortTaskTimer = timerBuilder.register(registry); - } - } - - if (shortTaskTimer != null && longTaskTimer != null) { - final Timer finalTimer = shortTaskTimer; - //noinspection NullableProblems - return recordThrowable(longTaskTimer, () -> recordThrowable(finalTimer, pjp::proceed)); - } else if (shortTaskTimer != null) { - //noinspection NullableProblems - return recordThrowable(shortTaskTimer, pjp::proceed); - } else if (longTaskTimer != null) { - //noinspection NullableProblems - return recordThrowable(longTaskTimer, pjp::proceed); - } - - return pjp.proceed(); - } - - private Object recordThrowable(LongTaskTimer timer, ThrowableCallable f) throws Throwable { - LongTaskTimer.Sample timing = timer.start(); - try { - return f.call(); - } finally { - timing.stop(); - } - } - - private Object recordThrowable(Timer timer, ThrowableCallable f) throws Throwable { - long start = registry.config().clock().monotonicTime(); - try { - return f.call(); - } finally { - timer.record(registry.config().clock().monotonicTime() - start, TimeUnit.NANOSECONDS); - } - } - - private interface ThrowableCallable { - Object call() throws Throwable; - } -} \ No newline at end of file diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/util/LambdaSafe.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/util/LambdaSafe.java deleted file mode 100644 index 51a5e9c58f..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/util/LambdaSafe.java +++ /dev/null @@ -1,457 +0,0 @@ -/* - * Copyright 2012-2018 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.core.ResolvableType; -import org.springframework.util.Assert; -import org.springframework.util.ClassUtils; -import org.springframework.util.ReflectionUtils; - -import java.lang.reflect.Method; -import java.util.Collection; -import java.util.Optional; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Predicate; -import java.util.function.Supplier; -import java.util.stream.Stream; - -/** - * Utility that can be used to invoke lambdas in a safe way. Primarily designed to help - * support generically typed callbacks where {@link ClassCastException class cast - * exceptions} need to be dealt with due to class erasure. - * - * @author Phillip Webb - * @since 1.2.0 - */ -public final class LambdaSafe { - - private static final Method CLASS_GET_MODULE; - - private static final Method MODULE_GET_NAME; - - static { - CLASS_GET_MODULE = ReflectionUtils.findMethod(Class.class, "getModule"); - MODULE_GET_NAME = (CLASS_GET_MODULE != null) - ? ReflectionUtils.findMethod(CLASS_GET_MODULE.getReturnType(), "getName") - : null; - } - - private LambdaSafe() { - } - - /** - * Start a call to a single callback instance, dealing with common generic type - * concerns and exceptions. - * - * @param callbackType the callback type (a {@link FunctionalInterface functional - * interface}) - * @param callbackInstance the callback instance (may be a lambda) - * @param argument the primary argument passed to the callback - * @param additionalArguments any additional arguments passed to the callback - * @param the callback type - * @param the primary argument type - * @return a {@link Callback} instance that can be invoked. - */ - public static Callback callback(Class callbackType, - C callbackInstance, A argument, Object... additionalArguments) { - Assert.notNull(callbackType, "CallbackType must not be null"); - Assert.notNull(callbackInstance, "CallbackInstance must not be null"); - return new Callback<>(callbackType, callbackInstance, argument, - additionalArguments); - } - - /** - * Start a call to callback instances, dealing with common generic type concerns and - * exceptions. - * - * @param callbackType the callback type (a {@link FunctionalInterface functional - * interface}) - * @param callbackInstances the callback instances (elements may be lambdas) - * @param argument the primary argument passed to the callbacks - * @param additionalArguments any additional arguments passed to the callbacks - * @param the callback type - * @param the primary argument type - * @return a {@link Callbacks} instance that can be invoked. - */ - public static Callbacks callbacks(Class callbackType, - Collection callbackInstances, A argument, - Object... additionalArguments) { - Assert.notNull(callbackType, "CallbackType must not be null"); - Assert.notNull(callbackInstances, "CallbackInstances must not be null"); - return new Callbacks<>(callbackType, callbackInstances, argument, - additionalArguments); - } - - /** - * Abstract base class for lambda safe callbacks. - */ - private abstract static class LambdaSafeCallback> { - - private final Class callbackType; - - private final A argument; - - private final Object[] additionalArguments; - - private Log logger; - - private Filter filter = new GenericTypeFilter<>(); - - protected LambdaSafeCallback(Class callbackType, A argument, - Object[] additionalArguments) { - this.callbackType = callbackType; - this.argument = argument; - this.additionalArguments = additionalArguments; - this.logger = LogFactory.getLog(callbackType); - } - - /** - * Use the specified logger source to report any lambda failures. - * - * @param loggerSource the logger source to use - * @return this instance - */ - public SELF withLogger(Class loggerSource) { - return withLogger(LogFactory.getLog(loggerSource)); - } - - /** - * Use the specified logger to report any lambda failures. - * - * @param logger the logger to use - * @return this instance - */ - public SELF withLogger(Log logger) { - Assert.notNull(logger, "Logger must not be null"); - this.logger = logger; - return self(); - } - - /** - * Use a specific filter to determine when a callback should apply. If no explicit - * filter is set filter will be attempted using the generic type on the callback - * type. - * - * @param filter the filter to use - * @return this instance - */ - public SELF withFilter(Filter filter) { - Assert.notNull(filter, "Filter must not be null"); - this.filter = filter; - return self(); - } - - protected final InvocationResult invoke(C callbackInstance, - Supplier supplier) { - if (this.filter.match(this.callbackType, callbackInstance, this.argument, - this.additionalArguments)) { - try { - return InvocationResult.of(supplier.get()); - } catch (ClassCastException ex) { - if (!isLambdaGenericProblem(ex)) { - throw ex; - } - logNonMatchingType(callbackInstance, ex); - } - } - return InvocationResult.noResult(); - } - - private boolean isLambdaGenericProblem(ClassCastException ex) { - return (ex.getMessage() == null - || startsWithArgumentClassName(ex.getMessage())); - } - - private boolean startsWithArgumentClassName(String message) { - Predicate startsWith = (argument) -> startsWithArgumentClassName( - message, argument); - return startsWith.test(this.argument) - || Stream.of(this.additionalArguments).anyMatch(startsWith); - } - - private boolean startsWithArgumentClassName(String message, Object argument) { - if (argument == null) { - return false; - } - Class argumentType = argument.getClass(); - // On Java 8, the message starts with the class name: "java.lang.String cannot - // be cast..." - if (message.startsWith(argumentType.getName())) { - return true; - } - // On Java 11, the message starts with "class ..." a.k.a. Class.toString() - if (message.startsWith(argumentType.toString())) { - return true; - } - // On Java 9, the message used to contain the module name: - // "java.base/java.lang.String cannot be cast..." - int moduleSeparatorIndex = message.indexOf('/'); - if (moduleSeparatorIndex != -1 && message.startsWith(argumentType.getName(), - moduleSeparatorIndex + 1)) { - return true; - } - if (CLASS_GET_MODULE != null) { - Object module = ReflectionUtils.invokeMethod(CLASS_GET_MODULE, - argumentType); - Object moduleName = ReflectionUtils.invokeMethod(MODULE_GET_NAME, module); - return message.startsWith(moduleName + "/" + argumentType.getName()); - } - return false; - } - - private void logNonMatchingType(C callback, ClassCastException ex) { - if (this.logger.isDebugEnabled()) { - Class expectedType = ResolvableType.forClass(this.callbackType) - .resolveGeneric(); - String expectedTypeName = (expectedType != null) - ? ClassUtils.getShortName(expectedType) + " type" : "type"; - String message = "Non-matching " + expectedTypeName + " for callback " - + ClassUtils.getShortName(this.callbackType) + ": " + callback; - this.logger.debug(message, ex); - } - } - - @SuppressWarnings("unchecked") - private SELF self() { - return (SELF) this; - } - - } - - /** - * Represents a single callback that can be invoked in a lambda safe way. - * - * @param the callback type - * @param the primary argument type - */ - public static final class Callback - extends LambdaSafeCallback> { - - private final C callbackInstance; - - private Callback(Class callbackType, C callbackInstance, A argument, - Object[] additionalArguments) { - super(callbackType, argument, additionalArguments); - this.callbackInstance = callbackInstance; - } - - /** - * Invoke the callback instance where the callback method returns void. - * - * @param invoker the invoker used to invoke the callback - */ - public void invoke(Consumer invoker) { - invoke(this.callbackInstance, () -> { - invoker.accept(this.callbackInstance); - return null; - }); - } - - /** - * Invoke the callback instance where the callback method returns a result. - * - * @param invoker the invoker used to invoke the callback - * @param the result type - * @return the result of the invocation (may be {@link InvocationResult#noResult} - * if the callback was not invoked) - */ - public InvocationResult invokeAnd(Function invoker) { - return invoke(this.callbackInstance, - () -> invoker.apply(this.callbackInstance)); - } - - } - - /** - * Represents a collection of callbacks that can be invoked in a lambda safe way. - * - * @param the callback type - * @param the primary argument type - */ - public static final class Callbacks - extends LambdaSafeCallback> { - - private final Collection callbackInstances; - - private Callbacks(Class callbackType, - Collection callbackInstances, A argument, - Object[] additionalArguments) { - super(callbackType, argument, additionalArguments); - this.callbackInstances = callbackInstances; - } - - /** - * Invoke the callback instances where the callback method returns void. - * - * @param invoker the invoker used to invoke the callback - */ - public void invoke(Consumer invoker) { - this.callbackInstances.forEach((callbackInstance) -> { - invoke(callbackInstance, () -> { - invoker.accept(callbackInstance); - return null; - }); - }); - } - - /** - * Invoke the callback instances where the callback method returns a result. - * - * @param invoker the invoker used to invoke the callback - * @param the result type - * @return the results of the invocation (may be an empty stream if no callbacks - * could be called) - */ - public Stream invokeAnd(Function invoker) { - Function> mapper = (callbackInstance) -> invoke( - callbackInstance, () -> invoker.apply(callbackInstance)); - return this.callbackInstances.stream().map(mapper) - .filter(InvocationResult::hasResult).map(InvocationResult::get); - } - - } - - /** - * A filter that can be used to restrict when a callback is used. - * - * @param the callback type - * @param the primary argument type - */ - @FunctionalInterface - interface Filter { - - /** - * Determine if the given callback matches and should be invoked. - * - * @param callbackType the callback type (the functional interface) - * @param callbackInstance the callback instance (the implementation) - * @param argument the primary argument - * @param additionalArguments any additional arguments - * @return if the callback matches and should be invoked - */ - boolean match(Class callbackType, C callbackInstance, A argument, - Object[] additionalArguments); - - /** - * Return a {@link Filter} that allows all callbacks to be invoked. - * - * @param the callback type - * @param the primary argument type - * @return an "allow all" filter - */ - static Filter allowAll() { - return (callbackType, callbackInstance, argument, - additionalArguments) -> true; - } - - } - - /** - * {@link Filter} that matches when the callback has a single generic and primary - * argument is an instance of it. - */ - private static class GenericTypeFilter implements Filter { - - @Override - public boolean match(Class callbackType, C callbackInstance, A argument, - Object[] additionalArguments) { - ResolvableType type = ResolvableType.forClass(callbackType, - callbackInstance.getClass()); - if (type.getGenerics().length == 1 && type.resolveGeneric() != null) { - return type.resolveGeneric().isInstance(argument); - } - - return true; - } - - } - - /** - * The result of a callback which may be a value, {@code null} or absent entirely if - * the callback wasn't suitable. Similar in design to {@link Optional} but allows for - * {@code null} as a valid value. - * - * @param the result type - */ - public static final class InvocationResult { - - private static final InvocationResult NONE = new InvocationResult<>(null); - - private final R value; - - private InvocationResult(R value) { - this.value = value; - } - - /** - * Return true if a result in present. - * - * @return if a result is present - */ - public boolean hasResult() { - return this != NONE; - } - - /** - * Return the result of the invocation or {@code null} if the callback wasn't - * suitable. - * - * @return the result of the invocation or {@code null} - */ - public R get() { - return this.value; - } - - /** - * Return the result of the invocation or the given fallback if the callback - * wasn't suitable. - * - * @param fallback the fallback to use when there is no result - * @return the result of the invocation or the fallback - */ - public R get(R fallback) { - return (this != NONE) ? this.value : fallback; - } - - /** - * Create a new {@link InvocationResult} instance with the specified value. - * - * @param value the value (may be {@code null}) - * @param the result type - * @return an {@link InvocationResult} - */ - public static InvocationResult of(R value) { - return new InvocationResult<>(value); - } - - /** - * Return an {@link InvocationResult} instance representing no result. - * - * @param the result type - * @return an {@link InvocationResult} - */ - @SuppressWarnings("unchecked") - public static InvocationResult noResult() { - return (InvocationResult) NONE; - } - - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/DefaultRestTemplateExchangeTagsProvider.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/DefaultRestTemplateExchangeTagsProvider.java deleted file mode 100644 index 0515cd88b7..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/DefaultRestTemplateExchangeTagsProvider.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.client; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.lang.Nullable; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.util.StringUtils; - -import java.util.Arrays; - -/** - * Default implementation of {@link RestTemplateExchangeTagsProvider}. - * - * @author Jon Schneider - */ -public class DefaultRestTemplateExchangeTagsProvider - implements RestTemplateExchangeTagsProvider { - - @Override - public Iterable getTags(@Nullable String urlTemplate, HttpRequest request, - @Nullable ClientHttpResponse response) { - Tag uriTag = urlTemplate != null && StringUtils.hasText(urlTemplate) - ? RestTemplateExchangeTags.uri(urlTemplate) - : RestTemplateExchangeTags.uri(request); - return Arrays.asList(RestTemplateExchangeTags.method(request), uriTag, - RestTemplateExchangeTags.status(response), - RestTemplateExchangeTags.clientName(request), - RestTemplateExchangeTags.outcome(response)); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/MetricsClientHttpRequestInterceptor.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/MetricsClientHttpRequestInterceptor.java deleted file mode 100644 index 71999341ab..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/MetricsClientHttpRequestInterceptor.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.client; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Timer; -import io.micrometer.core.lang.Nullable; -import org.springframework.core.NamedThreadLocal; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.*; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.util.concurrent.ListenableFutureCallback; -import org.springframework.web.util.UriTemplateHandler; - -import java.io.IOException; -import java.net.URI; -import java.util.Map; -import java.util.concurrent.TimeUnit; - -/** - * {@link ClientHttpRequestInterceptor} applied via a - * {@link MetricsRestTemplateCustomizer} to record metrics. - * - * @author Jon Schneider - * @author Phillip Webb - */ -class MetricsClientHttpRequestInterceptor implements ClientHttpRequestInterceptor, AsyncClientHttpRequestInterceptor { - - private static final ThreadLocal urlTemplateHolder = new NamedThreadLocal<>( - "Rest Template URL Template"); - - private final MeterRegistry meterRegistry; - private final RestTemplateExchangeTagsProvider tagProvider; - private final String metricName; - - MetricsClientHttpRequestInterceptor(MeterRegistry meterRegistry, String metricName, RestTemplateExchangeTagsProvider tagProvider) { - this.tagProvider = tagProvider; - this.meterRegistry = meterRegistry; - this.metricName = metricName; - } - - @Override - public ClientHttpResponse intercept(HttpRequest request, byte[] body, - ClientHttpRequestExecution execution) throws IOException { - final String urlTemplate = urlTemplateHolder.get(); - urlTemplateHolder.remove(); - final Clock clock = meterRegistry.config().clock(); - final long startTime = clock.monotonicTime(); - ClientHttpResponse response = null; - try { - response = execution.execute(request, body); - return response; - } finally { - getTimeBuilder(urlTemplate, request, response).register(this.meterRegistry) - .record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS); - } - } - - @Override - public ListenableFuture intercept(HttpRequest request, byte[] body, - AsyncClientHttpRequestExecution execution) throws IOException { - final String urlTemplate = urlTemplateHolder.get(); - urlTemplateHolder.remove(); - final Clock clock = meterRegistry.config().clock(); - final long startTime = clock.monotonicTime(); - ListenableFuture future; - try { - future = execution.executeAsync(request, body); - } catch (IOException e) { - getTimeBuilder(urlTemplate, request, null).register(meterRegistry) - .record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS); - throw e; - } - future.addCallback(new ListenableFutureCallback() { - @Override - public void onSuccess(final ClientHttpResponse response) { - getTimeBuilder(urlTemplate, request, response).register(meterRegistry) - .record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS); - } - - @Override - public void onFailure(final Throwable ex) { - getTimeBuilder(urlTemplate, request, null).register(meterRegistry) - .record(clock.monotonicTime() - startTime, TimeUnit.NANOSECONDS); - } - }); - return future; - } - - UriTemplateHandler createUriTemplateHandler(UriTemplateHandler delegate) { - return new UriTemplateHandler() { - - @Override - public URI expand(String url, Map arguments) { - urlTemplateHolder.set(url); - return delegate.expand(url, arguments); - } - - @Override - public URI expand(String url, Object... arguments) { - urlTemplateHolder.set(url); - return delegate.expand(url, arguments); - } - }; - } - - private Timer.Builder getTimeBuilder(@Nullable String urlTemplate, HttpRequest request, - @Nullable ClientHttpResponse response) { - return Timer.builder(this.metricName) - .tags(this.tagProvider.getTags(urlTemplate, request, response)) - .description("Timer of RestTemplate operation"); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/MetricsRestTemplateCustomizer.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/MetricsRestTemplateCustomizer.java deleted file mode 100644 index 56c514d5a8..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/MetricsRestTemplateCustomizer.java +++ /dev/null @@ -1,74 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.client; - -import io.micrometer.core.instrument.MeterRegistry; -import org.springframework.boot.web.client.RestTemplateCustomizer; -import org.springframework.http.client.AsyncClientHttpRequestInterceptor; -import org.springframework.http.client.ClientHttpRequestInterceptor; -import org.springframework.web.client.AsyncRestTemplate; -import org.springframework.web.client.RestTemplate; -import org.springframework.web.util.UriTemplateHandler; - -import java.util.ArrayList; -import java.util.List; - -/** - * {@link RestTemplateCustomizer} that configures the {@link RestTemplate} to record - * request metrics. - * - * @author Andy Wilkinson - * @author Phillip Webb - */ -public class MetricsRestTemplateCustomizer implements RestTemplateCustomizer { - - private final MetricsClientHttpRequestInterceptor interceptor; - - /** - * Creates a new {@code MetricsRestTemplateInterceptor} that will record metrics using - * the given {@code meterRegistry} with tags provided by the given - * {@code tagProvider}. - * - * @param meterRegistry the meter registry - * @param tagProvider the tag provider - * @param metricName the name of the recorded metric - */ - public MetricsRestTemplateCustomizer(MeterRegistry meterRegistry, - RestTemplateExchangeTagsProvider tagProvider, String metricName) { - this.interceptor = new MetricsClientHttpRequestInterceptor(meterRegistry, metricName, tagProvider); - } - - @Override - public void customize(RestTemplate restTemplate) { - UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler(); - templateHandler = this.interceptor.createUriTemplateHandler(templateHandler); - restTemplate.setUriTemplateHandler(templateHandler); - List interceptors = new ArrayList<>(); - interceptors.add(this.interceptor); - interceptors.addAll(restTemplate.getInterceptors()); - restTemplate.setInterceptors(interceptors); - } - - public void customize(final AsyncRestTemplate restTemplate) { - UriTemplateHandler templateHandler = restTemplate.getUriTemplateHandler(); - templateHandler = this.interceptor.createUriTemplateHandler(templateHandler); - restTemplate.setUriTemplateHandler(templateHandler); - List interceptors = new ArrayList<>(); - interceptors.add(this.interceptor); - interceptors.addAll(restTemplate.getInterceptors()); - restTemplate.setInterceptors(interceptors); - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/RestTemplateExchangeTags.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/RestTemplateExchangeTags.java deleted file mode 100644 index 7cc37ff4a4..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/RestTemplateExchangeTags.java +++ /dev/null @@ -1,170 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.client; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.lang.Nullable; -import org.springframework.http.HttpRequest; -import org.springframework.http.HttpStatus; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.util.StringUtils; -import org.springframework.web.client.RestTemplate; - -import java.io.IOException; -import java.net.URI; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * Factory methods for creating {@link Tag Tags} related to a request-response exchange - * performed by a {@link RestTemplate}. - * - * @author Andy Wilkinson - * @author Jon Schneider - */ -public final class RestTemplateExchangeTags { - - private static final Tag OUTCOME_UNKNOWN = Tag.of("outcome", "UNKNOWN"); - - private static final Tag OUTCOME_INFORMATIONAL = Tag.of("outcome", "INFORMATIONAL"); - - private static final Tag OUTCOME_SUCCESS = Tag.of("outcome", "SUCCESS"); - - private static final Tag OUTCOME_REDIRECTION = Tag.of("outcome", "REDIRECTION"); - - private static final Tag OUTCOME_CLIENT_ERROR = Tag.of("outcome", "CLIENT_ERROR"); - - private static final Tag OUTCOME_SERVER_ERROR = Tag.of("outcome", "SERVER_ERROR"); - - private static final Map SERIES_OUTCOMES; - - static { - Map seriesOutcomes = new HashMap<>(); - seriesOutcomes.put(HttpStatus.Series.INFORMATIONAL, OUTCOME_INFORMATIONAL); - seriesOutcomes.put(HttpStatus.Series.SUCCESSFUL, OUTCOME_SUCCESS); - seriesOutcomes.put(HttpStatus.Series.REDIRECTION, OUTCOME_REDIRECTION); - seriesOutcomes.put(HttpStatus.Series.CLIENT_ERROR, OUTCOME_CLIENT_ERROR); - seriesOutcomes.put(HttpStatus.Series.SERVER_ERROR, OUTCOME_SERVER_ERROR); - SERIES_OUTCOMES = Collections.unmodifiableMap(seriesOutcomes); - } - - private RestTemplateExchangeTags() { - } - - /** - * Creates a {@code method} {@code Tag} for the {@link HttpRequest#getMethod() method} - * of the given {@code request}. - * - * @param request the request - * @return the method tag - */ - public static Tag method(HttpRequest request) { - return Tag.of("method", request.getMethod().name()); - } - - /** - * Creates a {@code uri} {@code Tag} for the URI of the given {@code request}. - * - * @param request the request - * @return the uri tag - */ - public static Tag uri(HttpRequest request) { - return Tag.of("uri", ensureLeadingSlash(stripUri(request.getURI().toString()))); - } - - /** - * Creates a {@code uri} {@code Tag} from the given {@code uriTemplate}. - * - * @param uriTemplate the template - * @return the uri tag - */ - public static Tag uri(String uriTemplate) { - String uri = StringUtils.hasText(uriTemplate) ? uriTemplate : "none"; - return Tag.of("uri", ensureLeadingSlash(stripUri(uri))); - } - - private static String stripUri(String uri) { - return uri.replaceAll("^https?://[^/]+/", ""); - } - - // This normalization improves tag value matching when one code path requests test/{id} and another - // requests /test/{id} - private static String ensureLeadingSlash(@Nullable String uri) { - if (uri == null) - return "/"; - return uri.startsWith("/") ? uri : "/" + uri; - } - - /** - * Creates a {@code status} {@code Tag} derived from the - * {@link ClientHttpResponse#getRawStatusCode() status} of the given {@code response}. - * - * @param response the response - * @return the status tag - */ - public static Tag status(@Nullable ClientHttpResponse response) { - return Tag.of("status", getStatusMessage(response)); - } - - private static String getStatusMessage(@Nullable ClientHttpResponse response) { - try { - if (response == null) { - return "CLIENT_ERROR"; - } - return String.valueOf(response.getRawStatusCode()); - } catch (IOException ex) { - return "IO_ERROR"; - } - } - - /** - * Create a {@code clientName} {@code Tag} derived from the {@link URI#getHost host} - * of the {@link HttpRequest#getURI() URI} of the given {@code request}. - * - * @param request the request - * @return the clientName tag - */ - public static Tag clientName(HttpRequest request) { - String host = request.getURI().getHost(); - if (host == null) { - host = "none"; - } - return Tag.of("clientName", host); - } - - /** - * Creates an {@code outcome} {@code Tag} derived from the - * {@link ClientHttpResponse#getStatusCode() status} of the given {@code response}. - * @param response the response - * @return the outcome tag - * @since 1.1.2 - */ - public static Tag outcome(ClientHttpResponse response) { - try { - if (response != null) { - HttpStatus.Series series = HttpStatus.Series.valueOf(response.getRawStatusCode()); - if (series != null) { - return SERIES_OUTCOMES.getOrDefault(series, OUTCOME_UNKNOWN); - } - } - } - catch (IOException | IllegalArgumentException ex) { - // Continue - } - return OUTCOME_UNKNOWN; - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/RestTemplateExchangeTagsProvider.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/RestTemplateExchangeTagsProvider.java deleted file mode 100644 index 45439c82d0..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/RestTemplateExchangeTagsProvider.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.client; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.lang.Nullable; -import org.springframework.http.HttpRequest; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.web.client.RestTemplate; - -/** - * Provides {@link Tag Tags} for an exchange performed by a {@link RestTemplate}. - * - * @author Jon Schneider - * @author Andy Wilkinson - */ -@FunctionalInterface -public interface RestTemplateExchangeTagsProvider { - - /** - * Provides the tags to be associated with metrics that are recorded for the given - * {@code request} and {@code response} exchange. - * - * @param urlTemplate the source URl template, if available - * @param request the request - * @param response the response (may be {@code null} if the exchange failed) - * @return the tags - */ - Iterable getTags(@Nullable String urlTemplate, HttpRequest request, - @Nullable ClientHttpResponse response); - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/package-info.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/package-info.java deleted file mode 100644 index 579250858f..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/client/package-info.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -@NonNullApi -@NonNullFields -package io.micrometer.spring.web.client; - -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.NonNullFields; diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/jetty/JettyServerThreadPoolMetricsBinder.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/jetty/JettyServerThreadPoolMetricsBinder.java deleted file mode 100644 index 950f6dabe6..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/jetty/JettyServerThreadPoolMetricsBinder.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.jetty; - -import java.util.Collections; - -import org.springframework.boot.context.embedded.EmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainer; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationListener; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.binder.jetty.JettyServerThreadPoolMetrics; -import org.eclipse.jetty.util.thread.ThreadPool; - -/** - * Binds {@link JettyServerThreadPoolMetrics} in response to the - * {@link ApplicationReadyEvent}. - * - * @author Andy Wilkinson - * @since 1.1.0 - */ -public class JettyServerThreadPoolMetricsBinder - implements ApplicationListener { - - private final MeterRegistry meterRegistry; - - private final Iterable tags; - - public JettyServerThreadPoolMetricsBinder(MeterRegistry meterRegistry) { - this(meterRegistry, Collections.emptyList()); - } - - public JettyServerThreadPoolMetricsBinder(MeterRegistry meterRegistry, Iterable tags) { - this.meterRegistry = meterRegistry; - this.tags = tags; - } - - @Override - public void onApplicationEvent(ApplicationReadyEvent event) { - ApplicationContext applicationContext = event.getApplicationContext(); - ThreadPool threadPool = findThreadPool(applicationContext); - if (threadPool != null) { - new JettyServerThreadPoolMetrics(threadPool, this.tags) - .bindTo(this.meterRegistry); - } - } - - private ThreadPool findThreadPool(ApplicationContext applicationContext) { - if (applicationContext instanceof EmbeddedWebApplicationContext) { - EmbeddedServletContainer container = ((EmbeddedWebApplicationContext) applicationContext).getEmbeddedServletContainer(); - if (container instanceof JettyEmbeddedServletContainer) { - return ((JettyEmbeddedServletContainer) container).getServer().getThreadPool(); - } - } - return null; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/DefaultWebMvcTagsProvider.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/DefaultWebMvcTagsProvider.java deleted file mode 100644 index 753fe0ea4b..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/DefaultWebMvcTagsProvider.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.servlet; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.Nullable; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Arrays; - -/** - * Default implementation of {@link WebMvcTagsProvider}. - * - * @author Jon Schneider - */ -@NonNullApi -public class DefaultWebMvcTagsProvider implements WebMvcTagsProvider { - - /** - * Supplies default tags to long task timers. - * - * @param request The HTTP request. - * @param handler The request method that is responsible for handling the request. - * @return A set of tags added to every Spring MVC HTTP request - */ - @Override - public Iterable httpLongRequestTags(@Nullable HttpServletRequest request, @Nullable Object handler) { - return Arrays.asList(WebMvcTags.method(request), WebMvcTags.uri(request, null)); - } - - /** - * Supplies default tags to the Web MVC server programming model. - * - * @param request The HTTP request. - * @param response The HTTP response. - * @param ex The current exception, if any - * @return A set of tags added to every Spring MVC HTTP request. - */ - @Override - public Iterable httpRequestTags(@Nullable HttpServletRequest request, - @Nullable HttpServletResponse response, - @Nullable Object handler, - @Nullable Throwable ex) { - return Arrays.asList(WebMvcTags.method(request), WebMvcTags.uri(request, response), - WebMvcTags.exception(ex), WebMvcTags.status(response), WebMvcTags.outcome(response)); - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilter.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilter.java deleted file mode 100644 index 3b207d74ab..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilter.java +++ /dev/null @@ -1,178 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.servlet; - -import io.micrometer.core.annotation.Timed; -import io.micrometer.core.instrument.LongTaskTimer; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Timer; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.spring.TimedUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.core.Ordered; -import org.springframework.core.annotation.Order; -import org.springframework.http.HttpStatus; -import org.springframework.web.filter.OncePerRequestFilter; -import org.springframework.web.method.HandlerMethod; -import org.springframework.web.servlet.DispatcherServlet; -import org.springframework.web.servlet.HandlerExecutionChain; -import org.springframework.web.servlet.handler.HandlerMappingIntrospector; -import org.springframework.web.servlet.handler.MatchableHandlerMapping; -import org.springframework.web.util.NestedServletException; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.Collection; -import java.util.Collections; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * Intercepts incoming HTTP requests and records metrics about execution time and results. - * - * @author Jon Schneider - * @author Johnny Lim - */ -@NonNullApi -@Order(Ordered.HIGHEST_PRECEDENCE + 1) -public class WebMvcMetricsFilter extends OncePerRequestFilter { - private static final String TIMING_SAMPLE = "micrometer.timingSample"; - - private static final Log logger = LogFactory.getLog(WebMvcMetricsFilter.class); - - private final MeterRegistry registry; - private final WebMvcTagsProvider tagsProvider; - private final String metricName; - private final boolean autoTimeRequests; - private final HandlerMappingIntrospector mappingIntrospector; - - public WebMvcMetricsFilter(MeterRegistry registry, WebMvcTagsProvider tagsProvider, - String metricName, boolean autoTimeRequests, - HandlerMappingIntrospector mappingIntrospector) { - this.registry = registry; - this.tagsProvider = tagsProvider; - this.metricName = metricName; - this.autoTimeRequests = autoTimeRequests; - this.mappingIntrospector = mappingIntrospector; - } - - @Override - protected boolean shouldNotFilterAsyncDispatch() { - return false; - } - - @SuppressWarnings("ConstantConditions") - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - HandlerExecutionChain handler = null; - try { - MatchableHandlerMapping matchableHandlerMapping = mappingIntrospector.getMatchableHandlerMapping(request); - if (matchableHandlerMapping != null) { - handler = matchableHandlerMapping.getHandler(request); - } - } catch (Exception e) { - logger.debug("Unable to time request", e); - filterChain.doFilter(request, response); - return; - } - - final Object handlerObject = handler == null ? null : handler.getHandler(); - - // If this is the second invocation of the filter in an async request, we don't - // want to start sampling again (effectively bumping the active count on any long task timers). - // Rather, we'll just use the sampling context we started on the first invocation. - TimingSampleContext timingContext = (TimingSampleContext) request.getAttribute(TIMING_SAMPLE); - if (timingContext == null) { - timingContext = new TimingSampleContext(request, handlerObject); - } - - try { - filterChain.doFilter(request, response); - - if (request.isAsyncSupported()) { - // this won't be "started" until after the first call to doFilter - if (request.isAsyncStarted()) { - request.setAttribute(TIMING_SAMPLE, timingContext); - } - } - - if (!request.isAsyncStarted()) { - record(timingContext, response, request, - handlerObject, (Throwable) request.getAttribute(DispatcherServlet.EXCEPTION_ATTRIBUTE)); - } - } catch (NestedServletException e) { - response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); - record(timingContext, response, request, handlerObject, e.getCause()); - throw e; - } catch (ServletException | IOException | RuntimeException ex) { - record(timingContext, response, request, handlerObject, ex); - throw ex; - } - } - - private void record(TimingSampleContext timingContext, HttpServletResponse response, HttpServletRequest request, - Object handlerObject, Throwable e) { - for (Timed timedAnnotation : timingContext.timedAnnotations) { - timingContext.timerSample.stop(Timer.builder(timedAnnotation, metricName) - .tags(tagsProvider.httpRequestTags(request, response, handlerObject, e)) - .register(registry)); - } - - if (timingContext.timedAnnotations.isEmpty() && autoTimeRequests) { - timingContext.timerSample.stop(Timer.builder(metricName) - .tags(tagsProvider.httpRequestTags(request, response, handlerObject, e)) - .register(registry)); - } - - for (LongTaskTimer.Sample sample : timingContext.longTaskTimerSamples) { - sample.stop(); - } - } - - private class TimingSampleContext { - private final Set timedAnnotations; - private final Timer.Sample timerSample; - private final Collection longTaskTimerSamples; - - TimingSampleContext(HttpServletRequest request, Object handlerObject) { - timedAnnotations = annotations(handlerObject); - timerSample = Timer.start(registry); - longTaskTimerSamples = timedAnnotations.stream() - .filter(Timed::longTask) - .map(t -> LongTaskTimer.builder(t) - .tags(tagsProvider.httpLongRequestTags(request, handlerObject)) - .register(registry) - .start()) - .collect(Collectors.toList()); - } - - private Set annotations(Object handler) { - if (handler instanceof HandlerMethod) { - HandlerMethod handlerMethod = (HandlerMethod) handler; - Set timed = TimedUtils.findTimedAnnotations(handlerMethod.getMethod()); - if (timed.isEmpty()) { - return TimedUtils.findTimedAnnotations(handlerMethod.getBeanType()); - } - return timed; - } - return Collections.emptySet(); - } - } -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcTags.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcTags.java deleted file mode 100644 index 1c47eacfa1..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcTags.java +++ /dev/null @@ -1,187 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.servlet; - -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.Nullable; -import org.springframework.http.HttpStatus; -import org.springframework.util.StringUtils; -import org.springframework.web.servlet.HandlerMapping; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Factory methods for {@link Tag Tags} associated with a request-response exchange that - * is instrumented by {@link WebMvcMetricsFilter}. - * - * @author Jon Schneider - * @author Andy Wilkinson - * @author Michael McFadyen - */ -@NonNullApi -public final class WebMvcTags { - - private static final Tag URI_NOT_FOUND = Tag.of("uri", "NOT_FOUND"); - - private static final Tag URI_REDIRECTION = Tag.of("uri", "REDIRECTION"); - - private static final Tag URI_ROOT = Tag.of("uri", "root"); - - private static final Tag URI_UNKNOWN = Tag.of("uri", "UNKNOWN"); - - private static final Tag EXCEPTION_NONE = Tag.of("exception", "None"); - - private static final Tag STATUS_UNKNOWN = Tag.of("status", "UNKNOWN"); - - private static final Tag OUTCOME_UNKNOWN = Tag.of("outcome", "UNKNOWN"); - - private static final Tag OUTCOME_INFORMATIONAL = Tag.of("outcome", "INFORMATIONAL"); - - private static final Tag OUTCOME_SUCCESS = Tag.of("outcome", "SUCCESS"); - - private static final Tag OUTCOME_REDIRECTION = Tag.of("outcome", "REDIRECTION"); - - private static final Tag OUTCOME_CLIENT_ERROR = Tag.of("outcome", "CLIENT_ERROR"); - - private static final Tag OUTCOME_SERVER_ERROR = Tag.of("outcome", "SERVER_ERROR"); - - private static final Tag METHOD_UNKNOWN = Tag.of("method", "UNKNOWN"); - - private WebMvcTags() { - } - - /** - * Creates a {@code method} tag based on the {@link HttpServletRequest#getMethod() - * method} of the given {@code request}. - * - * @param request the request - * @return the method tag whose value is a capitalized method (e.g. GET). - */ - public static Tag method(@Nullable HttpServletRequest request) { - return request == null ? METHOD_UNKNOWN : Tag.of("method", request.getMethod()); - } - - /** - * Creates a {@code method} tag based on the status of the given {@code response}. - * - * @param response the HTTP response - * @return the status tag derived from the status of the response - */ - public static Tag status(@Nullable HttpServletResponse response) { - return response == null ? STATUS_UNKNOWN : Tag.of("status", Integer.toString(response.getStatus())); - } - - /** - * Creates a {@code uri} tag based on the URI of the given {@code request}. Uses the - * {@link HandlerMapping#BEST_MATCHING_PATTERN_ATTRIBUTE} best matching pattern if - * available. Falling back to {@code REDIRECTION} for 3xx responses, {@code NOT_FOUND} - * for 404 responses, {@code root} for requests with no path info, and {@code UNKNOWN} - * for all other requests. - * - * @param request the request - * @param response the response - * @return the uri tag derived from the request - */ - public static Tag uri(@Nullable HttpServletRequest request, @Nullable HttpServletResponse response) { - if (request != null) { - String pattern = getMatchingPattern(request); - if (pattern != null) { - return Tag.of("uri", pattern); - } else if (response != null) { - HttpStatus status = extractStatus(response); - if (status != null && status.is3xxRedirection()) { - return URI_REDIRECTION; - } - if (status != null && status.equals(HttpStatus.NOT_FOUND)) { - return URI_NOT_FOUND; - } - } - String pathInfo = getPathInfo(request); - if (pathInfo.isEmpty()) { - return URI_ROOT; - } - } - return URI_UNKNOWN; - } - - @Nullable - private static HttpStatus extractStatus(HttpServletResponse response) { - try { - return HttpStatus.valueOf(response.getStatus()); - } catch (IllegalArgumentException ex) { - return null; - } - } - - @Nullable - private static String getMatchingPattern(HttpServletRequest request) { - return (String) request.getAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE); - } - - private static String getPathInfo(HttpServletRequest request) { - String uri = StringUtils.hasText(request.getPathInfo()) ? - request.getPathInfo() : "/"; - return uri.replaceAll("//+", "/") - .replaceAll("/$", ""); - } - - - /** - * Creates a {@code exception} tag based on the {@link Class#getSimpleName() simple - * name} of the class of the given {@code exception}. - * - * @param exception the exception, may be {@code null} - * @return the exception tag derived from the exception - */ - public static Tag exception(@Nullable Throwable exception) { - if (exception == null) { - return EXCEPTION_NONE; - } - String simpleName = exception.getClass().getSimpleName(); - return Tag.of("exception", simpleName.isEmpty() ? exception.getClass().getName() : simpleName); - } - - /** - * Creates an {@code outcome} tag based on the status of the given {@code response}. - * @param response the HTTP response - * @return the outcome tag derived from the status of the response - * @since 1.1.0 - */ - public static Tag outcome(@Nullable HttpServletResponse response) { - if (response != null) { - HttpStatus status = extractStatus(response); - if (status != null) { - if (status.is1xxInformational()) { - return OUTCOME_INFORMATIONAL; - } - if (status.is2xxSuccessful()) { - return OUTCOME_SUCCESS; - } - if (status.is3xxRedirection()) { - return OUTCOME_REDIRECTION; - } - if (status.is4xxClientError()) { - return OUTCOME_CLIENT_ERROR; - } - } - return OUTCOME_SERVER_ERROR; - } - return OUTCOME_UNKNOWN; - } - -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcTagsProvider.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcTagsProvider.java deleted file mode 100644 index 606e18bddb..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/servlet/WebMvcTagsProvider.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.servlet; - -import io.micrometer.core.instrument.LongTaskTimer; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.lang.NonNull; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.core.lang.Nullable; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Provides {@link Tag Tags} for Spring MVC-based request handling. - * - * @author Jon Schneider - * @author Andy Wilkinson - */ -@NonNullApi -public interface WebMvcTagsProvider { - - /** - * Provides tags to be used by {@link LongTaskTimer long task timers}. - * - * @param request the HTTP request - * @param handler the handler for the request - * @return tags to associate with metrics recorded for the request - */ - @NonNull - Iterable httpLongRequestTags(@Nullable HttpServletRequest request, @Nullable Object handler); - - /** - * Provides tags to be associated with metrics for the given {@code request} and - * {@code response} exchange. - * - * @param request the request - * @param response the response - * @param handler the handler for the request - * @param ex the current exception, if any - * @return tags to associate with metrics for the request and response exchange - */ - @NonNull - Iterable httpRequestTags(@Nullable HttpServletRequest request, - @Nullable HttpServletResponse response, - @Nullable Object handler, - @Nullable Throwable ex); -} diff --git a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/tomcat/TomcatMetricsBinder.java b/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/tomcat/TomcatMetricsBinder.java deleted file mode 100644 index bc064bf989..0000000000 --- a/micrometer-spring-legacy/src/main/java/io/micrometer/spring/web/tomcat/TomcatMetricsBinder.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.tomcat; - -import java.util.Collections; - -import org.springframework.boot.context.embedded.EmbeddedServletContainer; -import org.springframework.boot.context.embedded.EmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationListener; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.binder.tomcat.TomcatMetrics; -import org.apache.catalina.Container; -import org.apache.catalina.Context; -import org.apache.catalina.Manager; - -/** - * Binds {@link TomcatMetrics} in response to the {@link ApplicationReadyEvent}. - * - * @author Andy Wilkinson - * @since 1.1.0 - */ -public class TomcatMetricsBinder implements ApplicationListener { - - private final MeterRegistry meterRegistry; - - private final Iterable tags; - - public TomcatMetricsBinder(MeterRegistry meterRegistry) { - this(meterRegistry, Collections.emptyList()); - } - - public TomcatMetricsBinder(MeterRegistry meterRegistry, Iterable tags) { - this.meterRegistry = meterRegistry; - this.tags = tags; - } - - @Override - public void onApplicationEvent(ApplicationReadyEvent event) { - ApplicationContext applicationContext = event.getApplicationContext(); - Manager manager = findManager(applicationContext); - new TomcatMetrics(manager, this.tags).bindTo(this.meterRegistry); - } - - private Manager findManager(ApplicationContext applicationContext) { - if (applicationContext instanceof EmbeddedWebApplicationContext) { - EmbeddedServletContainer container = ((EmbeddedWebApplicationContext) applicationContext).getEmbeddedServletContainer(); - if (container instanceof TomcatEmbeddedServletContainer) { - Context context = findContext((TomcatEmbeddedServletContainer) container); - return context.getManager(); - } - } - return null; - } - - private Context findContext(TomcatEmbeddedServletContainer tomcatWebServer) { - for (Container container : tomcatWebServer.getTomcat().getHost().findChildren()) { - if (container instanceof Context) { - return (Context) container; - } - } - return null; - } - -} diff --git a/micrometer-spring-legacy/src/main/resources/META-INF/additional-spring-configuration-metadata.json b/micrometer-spring-legacy/src/main/resources/META-INF/additional-spring-configuration-metadata.json deleted file mode 100644 index 88af43a832..0000000000 --- a/micrometer-spring-legacy/src/main/resources/META-INF/additional-spring-configuration-metadata.json +++ /dev/null @@ -1,106 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -{ - "properties": [ - { - "name": "management.metrics.binders.files.enabled", - "type": "java.lang.Boolean", - "description": "Whether to enable files metrics.", - "defaultValue": true, - "deprecation": { - "replacement": "management.metrics.enable.process.files", - "reason": "Instead, filter 'process.files' metrics." - } - }, - { - "name": "management.metrics.binders.jvm.enabled", - "type": "java.lang.Boolean", - "description": "Whether to enable JVM metrics.", - "defaultValue": true, - "deprecation": { - "replacement": "management.metrics.enable.jvm", - "reason": "Instead, disable JvmMetricsAutoConfiguration or filter 'jvm' metrics." - } - }, - { - "name": "management.metrics.binders.log4j2.enabled", - "type": "java.lang.Boolean", - "description": "Whether to enable Log4j 2 metrics.", - "defaultValue": true, - "deprecation": { - "replacement": "management.metrics.enable.logback", - "reason": "Instead, disable Log4J2MetricsAutoConfiguration or filter 'log4j2' metrics." - } - }, - { - "name": "management.metrics.binders.logback.enabled", - "type": "java.lang.Boolean", - "description": "Whether to enable Logback metrics.", - "defaultValue": true, - "deprecation": { - "replacement": "management.metrics.enable.logback", - "reason": "Instead, disable LogbackMetricsAutoConfiguration or filter 'logback' metrics." - } - }, - { - "name": "management.metrics.binders.processor.enabled", - "type": "java.lang.Boolean", - "description": "Whether to enable processor metrics.", - "defaultValue": true, - "deprecation": { - "reason": "Instead, filter 'system.cpu' and 'process.cpu' metrics." - } - }, - { - "name": "management.metrics.binders.uptime.enabled", - "type": "java.lang.Boolean", - "description": "Whether to enable uptime metrics.", - "defaultValue": true, - "deprecation": { - "reason": "Instead, filter 'process.uptime' and 'process.start.time' metrics." - } - }, - { - "name": "management.metrics.jersey2.server.enabled", - "type": "java.lang.Boolean", - "description": "Whether to enable Jersey 2 metrics.", - "defaultValue": true, - "deprecation": { - "reason": "Instead, disable JerseyServerMetricsAutoConfiguration." - } - }, - { - "name": "management.metrics.jersey2.server.requests-metric-name", - "type": "java.lang.String", - "description": "Name of the metric for received requests.", - "defaultValue": "http.server.requests", - "deprecation": { - "replacement": "management.metrics.web.server.requests-metric-name", - "reason": "Use common version for web server requests metric name." - } - }, - { - "name": "management.metrics.jersey2.server.auto-time-requests", - "type": "java.lang.Boolean", - "description": "Whether requests handled by Jersey should be automatically timed.", - "defaultValue": true, - "deprecation": { - "replacement": "management.metrics.web.server.auto-time-requests", - "reason": "Use common version for web server auto time requests." - } - } - ] -} diff --git a/micrometer-spring-legacy/src/main/resources/META-INF/spring.factories b/micrometer-spring-legacy/src/main/resources/META-INF/spring.factories deleted file mode 100644 index 9eed460f06..0000000000 --- a/micrometer-spring-legacy/src/main/resources/META-INF/spring.factories +++ /dev/null @@ -1,39 +0,0 @@ -org.springframework.boot.env.EnvironmentPostProcessor=\ -io.micrometer.spring.MetricsEnvironmentPostProcessor - -org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -io.micrometer.spring.autoconfigure.CompositeMeterRegistryAutoConfiguration,\ -io.micrometer.spring.autoconfigure.JvmMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.Log4J2MetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.LogbackMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.MetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.SystemMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.cache.CacheMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.appoptics.AppOpticsMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.atlas.AtlasMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.azuremonitor.AzureMonitorMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.datadog.DatadogMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.dynatrace.DynatraceMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.elastic.ElasticMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.ganglia.GangliaMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.graphite.GraphiteMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.humio.HumioMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.influx.InfluxMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.jmx.JmxMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.kairos.KairosMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.logging.LoggingMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.newrelic.NewRelicMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.prometheus.PrometheusMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.signalfx.SignalFxMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.stackdriver.StackdriverMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.statsd.StatsdMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.export.wavefront.WavefrontMetricsExportAutoConfiguration,\ -io.micrometer.spring.autoconfigure.jdbc.DataSourcePoolMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.jersey.JerseyServerMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.kafka.consumer.KafkaMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.orm.jpa.HibernateMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.web.client.RestTemplateMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.web.jetty.JettyMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.web.servlet.WebMvcMetricsAutoConfiguration,\ -io.micrometer.spring.autoconfigure.web.tomcat.TomcatMetricsAutoConfiguration diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/CountedAspectTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/CountedAspectTest.java deleted file mode 100644 index f822b1feef..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/CountedAspectTest.java +++ /dev/null @@ -1,180 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring; - -import io.micrometer.core.annotation.Counted; -import io.micrometer.core.aop.CountedAspect; -import io.micrometer.core.instrument.Counter; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.search.MeterNotFoundException; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.context.annotation.Import; -import org.springframework.stereotype.Service; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -/** - * Spring integration tests for {@link CountedAspect} aspect. - * - * @author Ali Dehghani - */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = CountedAspectTest.TestCountedAspectConfig.class) -public class CountedAspectTest { - - @Autowired - private MeterRegistry meterRegistry; - - @Autowired - private CountedService countedService; - - @Autowired - private AbstractCountedService abstractCountedService; - - @Test - public void countedWithoutSuccessfulMetrics() { - countedService.succeedWithoutMetrics(); - - assertThatThrownBy(() -> meterRegistry.get("metric.none").counter()) - .isInstanceOf(MeterNotFoundException.class); - } - - @Test - public void countedWithSuccessfulMetrics() { - String worked = countedService.succeedWithMetrics(); - - Counter counter = meterRegistry.get("metric.success") - .tag("method", "succeedWithMetrics") - .tag("result", "success") - .tag("exception", "none").counter(); - - assertThat(worked).isEqualTo("Worked!"); - assertThat(counter.count()).isOne(); - } - - @Test - public void countedWithFailure() { - try { - countedService.fail(); - } catch (Exception ignored) { - } - - Counter counter = meterRegistry.get("metric.failing") - .tag("method", "fail") - .tag("exception", "RuntimeException") - .tag("result", "failure").counter(); - - assertThat(counter.count()).isOne(); - } - - @Test - public void countedWithEmptyMetricNames() { - countedService.emptyMetricName(); - try { - countedService.emptyMetricNameWithException(); - } catch (Exception ignored) { - } - - assertThat(meterRegistry.get("method.counted").counters()).hasSize(2); - assertThat(meterRegistry.get("method.counted").tag("result", "success").counter().count()).isOne(); - assertThat(meterRegistry.get("method.counted").tag("result", "failure").counter().count()).isOne(); - } - - @Test - public void countedShouldWorkWhenImplementingAnInterface() { - abstractCountedService.doCount(); - - Counter counter = meterRegistry.get("metric.interface") - .tag("method", "doCount") - .tag("result", "success").counter(); - - assertThat(counter.count()).isOne(); - } - - - @Configuration - @EnableAspectJAutoProxy - @Import(CountedService.class) - static class TestCountedAspectConfig { - - @Bean - public SimpleMeterRegistry simpleMeterRegistry() { - return new SimpleMeterRegistry(); - } - - @Bean - public CountedAspect countedAspect(MeterRegistry meterRegistry) { - return new CountedAspect(meterRegistry); - } - - @Bean - public AbstractCountedService abstractCountedService() { - return new DefaultAbstractCountedService(); - } - } - - @Service - static class CountedService { - - @Counted(value = "metric.none", recordFailuresOnly = true) - void succeedWithoutMetrics() { - - } - - @Counted(value = "metric.success") - String succeedWithMetrics() { - return "Worked!"; - } - - @Counted(value = "metric.failing", description = "To record something") - void fail() { - throw new RuntimeException("Failing always"); - } - - @Counted - void emptyMetricName() { - - } - - @Counted - void emptyMetricNameWithException() { - throw new RuntimeException("This is it"); - } - } - - interface AbstractCountedService { - - void doCount(); - } - - static class DefaultAbstractCountedService implements AbstractCountedService { - - @Override - @Counted(value = "metric.interface") - public void doCount() { - - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/TimedAspectTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/TimedAspectTest.java deleted file mode 100644 index 3ba5b82dab..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/TimedAspectTest.java +++ /dev/null @@ -1,200 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring; - -import io.micrometer.core.annotation.Timed; -import io.micrometer.core.aop.TimedAspect; -import io.micrometer.core.instrument.Meter; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.EnableAspectJAutoProxy; -import org.springframework.context.annotation.Import; -import org.springframework.stereotype.Service; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.concurrent.atomic.AtomicReference; - -import static io.micrometer.core.aop.TimedAspect.EXCEPTION_TAG; -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertThrows; - -/** - * Tests for {@link TimedAspect}. - * - * @author Jon Schneider - * @author Johnny Lim - * @author Nejc Korasa - */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = TimedAspectTest.TestAspectConfig.class) -public class TimedAspectTest { - @Autowired - private TimedService service; - - @Autowired - private MeterRegistry registry; - - @Autowired - private SomeService someService; - - @Test - public void serviceIsTimed() { - service.timeMe(); - assertThat(registry.get("something").timer().count()).isEqualTo(1); - } - - @Test - public void serviceIsTimedWhenNoValue() { - service.timeWithoutValue(); - assertThat(registry.get(TimedAspect.DEFAULT_METRIC_NAME).timer().count()).isEqualTo(1); - } - - @Test - public void serviceIsTimedWhenThereIsAnException() { - assertThrows(RuntimeException.class, () -> service.timeWithException()); - assertThat(registry.get("somethingElse").tags(EXCEPTION_TAG, "RuntimeException").timer().count()).isEqualTo(1); - } - - @Test - public void serviceIsTimedWhenThereIsNoException() { - service.timeWithoutException(); - assertThat(registry.get("somethingElse").tags(EXCEPTION_TAG, "none").timer().count()).isEqualTo(1); - } - - @Test - public void serviceIsTimedWithLongTaskTimer() { - service.timeWithLongTaskTimer(); - assertThat(registry.get("alsoSomething").longTaskTimers().size()).isEqualTo(1); - } - - @Test - public void serviceIsTimedWithLongTaskTimerWhenThereIsAnException() { - assertThrows(RuntimeException.class, () -> service.timeWithLongTaskTimerOnException()); - assertThat(registry.get("alsoSomethingElse").longTaskTimers().size()).isEqualTo(1); - } - - @Test - public void serviceIsTimedWithHistogram() { - // given... - // ... we are waiting for a metric to be created with a histogram - AtomicReference myConfig = new AtomicReference<>(); - registry.config().meterFilter(new MeterFilter() { - @Override - public DistributionStatisticConfig configure(Meter.Id id, DistributionStatisticConfig config) { - if (id.getName().equals("something")) { - myConfig.set(config); - } - return config; - } - }); - - // when... - // ... the service is being called - service.timeWithHistogram(); - - // then... - assertThat(myConfig.get()).as("the metric has been created").isNotNull(); - assertThat(myConfig.get().isPublishingHistogram()).as("the metric has a histogram").isTrue(); - } - - @Test - public void timedWhenImplementingInterfaceShouldWork() { - assertThat(someService.doService("Hello, world!")).isEqualTo("Done: Hello, world!"); - assertThat(registry.get("some").timer().count()).isEqualTo(1); - } - - @Configuration - @EnableAspectJAutoProxy - @Import(TimedService.class) - static class TestAspectConfig { - @Bean - public SimpleMeterRegistry simpleMeterRegistry() { - return new SimpleMeterRegistry(); - } - - @Bean - public TimedAspect micrometerAspect(MeterRegistry meterRegistry) { - return new TimedAspect(meterRegistry); - } - - @Bean - public DefaultSomeService someService() { - return new DefaultSomeService(); - } - } - - @Service - static class TimedService { - @Timed("something") - public String timeMe() { - return "hello world"; - } - - @Timed - public String timeWithoutValue() { - return "hello universe"; - } - - @Timed("somethingElse") - public String timeWithException() { - throw new RuntimeException("universe destroyed."); - } - - @Timed("somethingElse") - public String timeWithoutException() { - return "hello world"; - } - - @Timed(value = "something", histogram = true) - public String timeWithHistogram() { - return "hello histogram"; - } - - @Timed(value = "alsoSomething", longTask = true) - public String timeWithLongTaskTimer() { - return "hello, it's been a while"; - } - - @Timed(value = "alsoSomethingElse", longTask = true) - public String timeWithLongTaskTimerOnException() { - throw new RuntimeException("bye"); - } - } - - interface SomeService { - - String doService(String data); - - } - - static class DefaultSomeService implements SomeService { - - @Timed("some") - @Override - public String doService(String data) { - return "Done: " + data; - } - - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/TimedUtilsTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/TimedUtilsTest.java deleted file mode 100644 index 37ab1c1b56..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/TimedUtilsTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring; - -import io.micrometer.core.annotation.Timed; -import org.junit.Test; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import static org.assertj.core.api.Assertions.assertThat; - -public class TimedUtilsTest { - @Test - public void timedClass() { - assertThat(TimedUtils.findTimedAnnotations(TimedClass.class)).isNotEmpty(); - } - - @Test - public void timedMethod() throws NoSuchMethodException { - assertThat(TimedUtils.findTimedAnnotations(TimedClass.class.getDeclaredMethod("foo"))) - .isNotEmpty(); - } - - @Test - public void subclassedTimedClass() { - assertThat(TimedUtils.findTimedAnnotations(SpecialTimedClass.class)).isNotEmpty(); - } - - @Test - public void subclassedTimedMethod() throws NoSuchMethodException { - assertThat(TimedUtils.findTimedAnnotations(SpecialTimedClass.class.getDeclaredMethod("foo"))) - .isNotEmpty(); - } - - @Test - public void inheritedTimedClass() { - assertThat(TimedUtils.findTimedAnnotations(SpecialTimedClass.class)).isNotEmpty(); - } - - @Test - public void inheritedTimedMethod() throws NoSuchMethodException { - assertThat(TimedUtils.findTimedAnnotations(SpecialTimedClass.class.getDeclaredMethod("foo"))) - .isNotEmpty(); - } - - @Target({ElementType.TYPE, ElementType.METHOD}) - @Retention(RetentionPolicy.RUNTIME) - @Timed(percentiles = 0.95) - @interface Timed95 { - } - - @Timed - static class TimedClass { - @Timed - public void foo() { - } - } - - @Timed95 - static class SpecialTimedClass { - @Timed95 - void foo() { - } - } - - class InheritedTimedClass extends TimedClass { - @Override - public void foo() { - super.foo(); - } - } - -} \ No newline at end of file diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetricsIntegrationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetricsIntegrationTest.java deleted file mode 100644 index 64ccb6e134..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetricsIntegrationTest.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.async; - -import io.micrometer.core.Issue; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Metrics; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.core.task.AsyncTaskExecutor; -import org.springframework.scheduling.annotation.AsyncConfigurerSupport; -import org.springframework.scheduling.annotation.EnableAsync; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.test.context.junit4.SpringRunner; - -import static java.util.Collections.emptyList; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = ThreadPoolTaskExecutorMetricsIntegrationTest.App.class) -public class ThreadPoolTaskExecutorMetricsIntegrationTest { - - @Autowired - MeterRegistry registry; - - @Issue("#459") - @Test - public void executorMetricsPhase() { - registry.get("jvm.memory.max").gauge(); - } - - @SpringBootApplication(scanBasePackages = "ignore") - @Import(AsyncExecutorConfig.class) - static class App { - @Bean - public AsyncTaskExecutor executor(MeterRegistry registry) { - return new TimedThreadPoolTaskExecutor(registry, "threads", emptyList()); - } - } - - /** - * Injecting the registry instead would cause early evaluation of the registry and the registry - * wouldn't be discovered by {@code MeterRegistryPostProcessor}. - */ - @Configuration - @EnableAsync - static class AsyncExecutorConfig extends AsyncConfigurerSupport { - @Bean - public AsyncTaskExecutor getAsyncExecutor() { - final ThreadPoolTaskExecutor executor = new TimedThreadPoolTaskExecutor(Metrics.globalRegistry, "workers", emptyList()); - executor.initialize(); - return executor; - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetricsTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetricsTest.java deleted file mode 100644 index 58cda3bfd6..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/async/ThreadPoolTaskExecutorMetricsTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.async; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Tags; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Before; -import org.junit.Test; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; - -public class ThreadPoolTaskExecutorMetricsTest { - private MeterRegistry registry; - private Iterable userTags = Tags.of("userTagKey", "userTagValue"); - - @Before - public void before() { - registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock()); - } - - @Test - public void executor() throws InterruptedException { - CountDownLatch lock = new CountDownLatch(1); - ThreadPoolTaskExecutor pool = ThreadPoolTaskExecutorMetrics.monitor(registry, "exec", userTags); - pool.setAwaitTerminationSeconds(1); - pool.initialize(); - pool.execute(() -> { - System.out.println("hello"); - lock.countDown(); - }); - lock.await(); - pool.shutdown(); - - assertThat(registry.get("exec").tags(userTags).timer().count()).isEqualTo(1L); - registry.get("exec.completed").tags(userTags).functionCounter(); - registry.get("exec.queued").tags(userTags).gauge(); - registry.get("exec.active").tags(userTags).gauge(); - registry.get("exec.pool").tags(userTags).gauge(); - } - - @Test - public void monitorExecutorService() throws InterruptedException { - CountDownLatch taskStart = new CountDownLatch(1); - CountDownLatch taskComplete = new CountDownLatch(1); - - ThreadPoolTaskExecutor pool = ThreadPoolTaskExecutorMetrics.monitor(registry, "beep.pool", userTags); - pool.setMaxPoolSize(1); - pool.setAwaitTerminationSeconds(1); - pool.setWaitForTasksToCompleteOnShutdown(true); - pool.initialize(); - pool.submit(() -> { - taskStart.countDown(); - taskComplete.await(1, TimeUnit.SECONDS); - System.out.println("beep"); - return 0; - }); - pool.submit(() -> System.out.println("boop")); - - taskStart.await(1, TimeUnit.SECONDS); - assertThat(registry.get("beep.pool.queued").tags(userTags).gauge().value()).isEqualTo(1.0); - - taskComplete.countDown(); - pool.shutdown(); - - assertThat(registry.get("beep.pool").tags(userTags).timer().count()).isEqualTo(2L); - assertThat(registry.get("beep.pool.queued").tags(userTags).gauge().value()).isEqualTo(0.0); - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationDefaultSimpleRegistryTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationDefaultSimpleRegistryTest.java deleted file mode 100644 index ddea0a63ce..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationDefaultSimpleRegistryTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = CompositeMeterRegistryConfigurationTest.MetricsApp.class) -public class CompositeMeterRegistryConfigurationDefaultSimpleRegistryTest { - - @Autowired - private MeterRegistry registry; - - /** - * The simple registry is off by default UNLESS there is no other registry implementation on - * the classpath, in which case it is on. - */ - @Test - public void simpleWithNoCompositeCreated() { - assertThat(registry).isInstanceOf(SimpleMeterRegistry.class); - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationExistingPrimaryRegistryTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationExistingPrimaryRegistryTest.java deleted file mode 100644 index 5b5fb2ed31..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationExistingPrimaryRegistryTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Primary; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = CompositeMeterRegistryConfigurationExistingPrimaryRegistryTest.MetricsApp.class) -public class CompositeMeterRegistryConfigurationExistingPrimaryRegistryTest { - - @Autowired - private MeterRegistry registry; - - @Test - public void compositeNotCreatedWhenPrimaryRegistryExists() { - assertThat(registry).isInstanceOf(SimpleMeterRegistry.class); - } - - @SpringBootApplication(scanBasePackages = "ignored") - static class MetricsApp { - @Primary - @Bean - MeterRegistry simpleMeterRegistry() { - return new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock()); - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationNoRegistryTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationNoRegistryTest.java deleted file mode 100644 index 564f62d2a6..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationNoRegistryTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = CompositeMeterRegistryConfigurationTest.MetricsApp.class) -@TestPropertySource(properties = "management.metrics.export.simple.enabled=false") -public class CompositeMeterRegistryConfigurationNoRegistryTest { - - @Autowired - private MeterRegistry registry; - - /** - * An empty composite is created in the absence of any other registry implementation. - * This effectively no-ops instrumentation code throughout the application. - */ - @Test - public void emptyCompositeCreated() { - assertThat(registry) - .isInstanceOf(CompositeMeterRegistry.class) - .matches(r -> ((CompositeMeterRegistry) r).getRegistries().isEmpty()); - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationSingleRegistryTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationSingleRegistryTest.java deleted file mode 100644 index c39442e0a1..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationSingleRegistryTest.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.graphite.GraphiteMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = CompositeMeterRegistryConfigurationTest.MetricsApp.class) -@TestPropertySource(properties = "management.metrics.export.graphite.enabled=true") -public class CompositeMeterRegistryConfigurationSingleRegistryTest { - - @Autowired - private MeterRegistry registry; - - @Test - public void noCompositeCreated() { - assertThat(registry).isInstanceOf(GraphiteMeterRegistry.class); - } -} \ No newline at end of file diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationTest.java deleted file mode 100644 index e4e7cdfe5d..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeMeterRegistryConfigurationTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; -import io.micrometer.jmx.JmxMeterRegistry; -import io.micrometer.prometheus.PrometheusMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = CompositeMeterRegistryConfigurationTest.MetricsApp.class) -@TestPropertySource(properties = { - "management.metrics.export.jmx.enabled=true", - "management.metrics.export.prometheus.enabled=true", - "management.metrics.export.prometheus.pushgateway.enabled=false", -}) -public class CompositeMeterRegistryConfigurationTest { - @Autowired - private MeterRegistry registry; - - @Test - public void compositeRegistryIsCreated() { - assertThat(registry).isInstanceOf(CompositeMeterRegistry.class); - - assertThat(((CompositeMeterRegistry) registry).getRegistries()) - .hasAtLeastOneElementOfType(JmxMeterRegistry.class) - .hasAtLeastOneElementOfType(PrometheusMeterRegistry.class); - - assertThat(registry.config().clock()).isNotNull(); - } - - @SpringBootApplication(scanBasePackages = "ignored") - static class MetricsApp { - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeRegistryDoubleCountingTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeRegistryDoubleCountingTest.java deleted file mode 100644 index 5799b25e7e..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/CompositeRegistryDoubleCountingTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; -import io.micrometer.jmx.JmxMeterRegistry; -import io.micrometer.prometheus.PrometheusMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = CompositeRegistryDoubleCountingTest.MetricsApp.class) -@TestPropertySource(properties = { - "management.metrics.export.prometheus.enabled=true", - "management.metrics.export.prometheus.pushgateway.enabled=false", - "management.metrics.export.jmx.enabled=true", -}) -public class CompositeRegistryDoubleCountingTest { - @Autowired - private MeterRegistry registry; - - @Autowired - private ApplicationContext context; - - @Test - public void compositeRegistryIsCreated() { - assertThat(registry).isInstanceOf(CompositeMeterRegistry.class); - - assertThat(((CompositeMeterRegistry) registry).getRegistries()) - .hasAtLeastOneElementOfType(JmxMeterRegistry.class) - .hasAtLeastOneElementOfType(PrometheusMeterRegistry.class); - - assertThat(registry.config().clock()).isNotNull(); - } - - @Test - public void metricsAreNotCountedTwice() { - Logger logger = LoggerFactory.getLogger("test-logger"); - logger.error("Error."); - - Map registriesByName = context - .getBeansOfType(MeterRegistry.class); - assertThat(registriesByName).hasSize(3); - registriesByName.forEach((name, registry) -> - assertThat(registry - .get("logback.events") - .tag("level", "error") - .counter() - .count()) - .isEqualTo(1)); - } - - @SpringBootApplication(scanBasePackages = "ignored") - static class MetricsApp { - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/JvmMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/JvmMetricsAutoConfigurationTest.java deleted file mode 100644 index 709e8b5236..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/JvmMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; -import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; -import io.micrometer.core.instrument.binder.jvm.JvmMemoryMetrics; -import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link JvmMetricsAutoConfiguration}. - * - * @author Andy Wilkinson - * @author Stephane Nicoll - * @author Johnny Lim - */ -public class JvmMetricsAutoConfigurationTest { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - public void autoConfiguresJvmMetrics() { - registerAndRefresh(); - assertThat(context.getBean(JvmGcMetrics.class)).isNotNull(); - assertThat(context.getBean(JvmMemoryMetrics.class)).isNotNull(); - assertThat(context.getBean(JvmThreadMetrics.class)).isNotNull(); - assertThat(context.getBean(ClassLoaderMetrics.class)).isNotNull(); - } - - @Test - @Deprecated - public void allowsJvmMetricsToBeDisabled() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.binders.jvm.enabled=false"); - registerAndRefresh(); - assertThat(context.getBeansOfType(JvmGcMetrics.class)).isEmpty(); - assertThat(context.getBeansOfType(JvmMemoryMetrics.class)).isEmpty(); - assertThat(context.getBeansOfType(JvmThreadMetrics.class)).isEmpty(); - assertThat(context.getBeansOfType(ClassLoaderMetrics.class)).isEmpty(); - } - - @Test - public void allowsCustomJvmGcMetricsToBeUsed() { - registerAndRefresh(CustomJvmGcMetricsConfiguration.class); - assertThat(context.getBean(JvmGcMetrics.class)).isEqualTo(context.getBean("customJvmGcMetrics")); - assertThat(context.getBean(JvmMemoryMetrics.class)).isNotNull(); - assertThat(context.getBean(JvmThreadMetrics.class)).isNotNull(); - assertThat(context.getBean(ClassLoaderMetrics.class)).isNotNull(); - } - - @Test - public void allowsCustomJvmMemoryMetricsToBeUsed() { - registerAndRefresh(CustomJvmMemoryMetricsConfiguration.class); - assertThat(context.getBean(JvmGcMetrics.class)).isNotNull(); - assertThat(context.getBean(JvmMemoryMetrics.class)).isEqualTo(context.getBean("customJvmMemoryMetrics")); - assertThat(context.getBean(JvmThreadMetrics.class)).isNotNull(); - assertThat(context.getBean(ClassLoaderMetrics.class)).isNotNull(); - } - - @Test - public void allowsCustomJvmThreadMetricsToBeUsed() { - registerAndRefresh(CustomJvmThreadMetricsConfiguration.class); - assertThat(context.getBean(JvmGcMetrics.class)).isNotNull(); - assertThat(context.getBean(JvmMemoryMetrics.class)).isNotNull(); - assertThat(context.getBean(JvmThreadMetrics.class)).isEqualTo(context.getBean("customJvmThreadMetrics")); - assertThat(context.getBean(ClassLoaderMetrics.class)).isNotNull(); - } - - @Test - public void allowsCustomClassLoaderMetricsToBeUsed() { - registerAndRefresh(CustomClassLoaderMetricsConfiguration.class); - assertThat(context.getBean(JvmGcMetrics.class)).isNotNull(); - assertThat(context.getBean(JvmMemoryMetrics.class)).isNotNull(); - assertThat(context.getBean(JvmThreadMetrics.class)).isNotNull(); - assertThat(context.getBean(ClassLoaderMetrics.class)).isEqualTo(context.getBean("customClassLoaderMetrics")); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length != 0) { - this.context.register(configurationClasses); - } - this.context.register(MeterRegistryConfiguration.class, JvmMetricsAutoConfiguration.class); - this.context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public MeterRegistry meterRegistry() { - return mock(MeterRegistry.class); - } - - } - - @Configuration - static class CustomJvmGcMetricsConfiguration { - - @Bean - public JvmGcMetrics customJvmGcMetrics() { - return new JvmGcMetrics(); - } - - } - - @Configuration - static class CustomJvmMemoryMetricsConfiguration { - - @Bean - public JvmMemoryMetrics customJvmMemoryMetrics() { - return new JvmMemoryMetrics(); - } - - } - - @Configuration - static class CustomJvmThreadMetricsConfiguration { - - @Bean - public JvmThreadMetrics customJvmThreadMetrics() { - return new JvmThreadMetrics(); - } - - } - - @Configuration - static class CustomClassLoaderMetricsConfiguration { - - @Bean - public ClassLoaderMetrics customClassLoaderMetrics() { - return new ClassLoaderMetrics(); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/Log4J2MetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/Log4J2MetricsAutoConfigurationTest.java deleted file mode 100644 index 18bc7ca31f..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/Log4J2MetricsAutoConfigurationTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.logging.Log4j2Metrics; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link Log4J2MetricsAutoConfiguration}. - * - * @author Andy Wilkinson - * @author Johnny Lim - */ -public class Log4J2MetricsAutoConfigurationTest { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - public void autoConfiguresLog4J2Metrics() { - registerAndRefresh(); - assertThat(context.getBean(Log4j2Metrics.class)).isNotNull(); - } - - @Test - @Deprecated - public void allowsLogbackMetricsToBeDisabled() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.binders.log4j2.enabled=false"); - registerAndRefresh(); - assertThat(context.getBeansOfType(Log4j2Metrics.class)).isEmpty(); - } - - @Test - public void allowsCustomLog4J2MetricsToBeUsed() { - registerAndRefresh(CustomLog4J2MetricsConfiguration.class); - assertThat(context.getBean(Log4j2Metrics.class)).isEqualTo(context.getBean("customLog4J2Metrics")); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length != 0) { - this.context.register(configurationClasses); - } - this.context.register(MeterRegistryConfiguration.class, Log4J2MetricsAutoConfiguration.class); - this.context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public MeterRegistry meterRegistry() { - return mock(MeterRegistry.class); - } - - } - - @Configuration - static class CustomLog4J2MetricsConfiguration { - - @Bean - public Log4j2Metrics customLog4J2Metrics() { - return new Log4j2Metrics(); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/LogbackMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/LogbackMetricsAutoConfigurationTest.java deleted file mode 100644 index 6153e3e177..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/LogbackMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.logging.LogbackMetrics; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link LogbackMetricsAutoConfiguration}. - * - * @author Andy Wilkinson - * @author Stephane Nicoll - * @author Johnny Lim - */ -public class LogbackMetricsAutoConfigurationTest { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - public void autoConfiguresLogbackMetrics() { - registerAndRefresh(); - assertThat(context.getBean(LogbackMetrics.class)).isNotNull(); - } - - @Test - @Deprecated - public void allowsLogbackMetricsToBeDisabled() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.binders.logback.enabled=false"); - registerAndRefresh(); - assertThat(context.getBeansOfType(LogbackMetrics.class)).isEmpty(); - } - - @Test - public void allowsCustomLogbackMetricsToBeUsed() { - registerAndRefresh(CustomLogbackMetricsConfiguration.class); - assertThat(context.getBean(LogbackMetrics.class)).isEqualTo(context.getBean("customLogbackMetrics")); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length != 0) { - this.context.register(configurationClasses); - } - this.context.register(MeterRegistryConfiguration.class, LogbackMetricsAutoConfiguration.class); - this.context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public MeterRegistry meterRegistry() { - return mock(MeterRegistry.class); - } - - } - - @Configuration - static class CustomLogbackMetricsConfiguration { - - @Bean - public LogbackMetrics customLogbackMetrics() { - return new LogbackMetrics(); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MeterRegistryCustomizerTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MeterRegistryCustomizerTest.java deleted file mode 100644 index b07fd5d48c..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MeterRegistryCustomizerTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.atlas.AtlasMeterRegistry; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.prometheus.PrometheusMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Jon Schneider - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(properties = { - "management.metrics.export.prometheus.enabled=true", - "management.metrics.export.atlas.enabled=true" -}) -public class MeterRegistryCustomizerTest { - - @Autowired - private AtlasMeterRegistry atlasRegistry; - - @Autowired - private PrometheusMeterRegistry prometheusRegistry; - - @Test - public void commonTagsAreAppliedToAutoConfiguredBinders() { - atlasRegistry.get("jvm.memory.used").tags("region", "us-east-1").gauge(); - prometheusRegistry.get("jvm.memory.used").tags("region", "us-east-1").gauge(); - - assertThat(atlasRegistry.find("jvm.memory.used").tags("job", "myjob").gauge()).isNull(); - prometheusRegistry.get("jvm.memory.used").tags("job", "myjob").gauge(); - } - - @SpringBootApplication(scanBasePackages = "isolated") - static class MetricsApp { - @Bean - public MeterRegistryCustomizer commonTags() { - return registry -> registry.config().commonTags("region", "us-east-1"); - } - - @Bean - public MeterRegistryCustomizer prometheusOnlyCommonTags() { - return registry -> registry.config().commonTags("job", "myjob"); - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MeterValueTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MeterValueTest.java deleted file mode 100644 index 028d635cc5..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MeterValueTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.Meter; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link MeterValue}. - * - * @author Phillip Webb - */ -class MeterValueTest { - - @Test - void getValueForDistributionSummaryWhenFromLongShouldReturnLongValue() { - MeterValue meterValue = MeterValue.valueOf(123L); - assertThat(meterValue.getValue(Meter.Type.DISTRIBUTION_SUMMARY)).isEqualTo(123); - } - - @Test - void getValueForDistributionSummaryWhenFromNumberStringShouldReturnLongValue() { - MeterValue meterValue = MeterValue.valueOf("123"); - assertThat(meterValue.getValue(Meter.Type.DISTRIBUTION_SUMMARY)).isEqualTo(123); - } - - @Test - void getValueForDistributionSummaryWhenFromDurationStringShouldReturnNull() { - MeterValue meterValue = MeterValue.valueOf("123ms"); - assertThat(meterValue.getValue(Meter.Type.DISTRIBUTION_SUMMARY)).isNull(); - } - - @Test - void getValueForTimerWhenFromLongShouldReturnMsToNanosValue() { - MeterValue meterValue = MeterValue.valueOf(123L); - assertThat(meterValue.getValue(Meter.Type.TIMER)).isEqualTo(123000000); - } - - @Test - void getValueForTimerWhenFromNumberStringShouldMsToNanosValue() { - MeterValue meterValue = MeterValue.valueOf("123"); - assertThat(meterValue.getValue(Meter.Type.TIMER)).isEqualTo(123000000); - } - - @Test - void getValueForTimerWhenFromDurationStringShouldReturnDurationNanos() { - MeterValue meterValue = MeterValue.valueOf("123ms"); - assertThat(meterValue.getValue(Meter.Type.TIMER)).isEqualTo(123000000); - } - - @Test - void getValueForOthersShouldReturnNull() { - MeterValue meterValue = MeterValue.valueOf("123"); - assertThat(meterValue.getValue(Meter.Type.COUNTER)).isNull(); - assertThat(meterValue.getValue(Meter.Type.GAUGE)).isNull(); - assertThat(meterValue.getValue(Meter.Type.LONG_TASK_TIMER)).isNull(); - assertThat(meterValue.getValue(Meter.Type.OTHER)).isNull(); - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MetricsAutoConfigurationIntegrationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MetricsAutoConfigurationIntegrationTest.java deleted file mode 100644 index 6f588fa04d..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MetricsAutoConfigurationIntegrationTest.java +++ /dev/null @@ -1,149 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.instrument.binder.jvm.ClassLoaderMetrics; -import io.micrometer.core.instrument.binder.jvm.JvmGcMetrics; -import io.micrometer.core.instrument.binder.jvm.JvmThreadMetrics; -import io.micrometer.core.instrument.binder.logging.LogbackMetrics; -import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics; -import io.micrometer.core.instrument.binder.system.ProcessorMetrics; -import io.micrometer.core.instrument.binder.system.UptimeMetrics; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.ApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Import; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.RestTemplate; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.web.client.ExpectedCount.once; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; - -/** - * Integration tests for {@link MetricsAutoConfiguration}. - * - * @author Jon Schneider - */ -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, classes = MetricsAutoConfigurationIntegrationTest.MetricsApp.class) -public class MetricsAutoConfigurationIntegrationTest { - - @Autowired - private ApplicationContext context; - - @Autowired - private RestTemplate external; - - @Autowired - private TestRestTemplate loopback; - - @Autowired - private MeterRegistry registry; - - @SuppressWarnings("unchecked") - @Test - public void restTemplateIsInstrumented() { - MockRestServiceServer server = MockRestServiceServer.bindTo(external).build(); - server.expect(once(), requestTo("/api/external")) - .andExpect(method(HttpMethod.GET)).andRespond(withSuccess( - "hello", MediaType.APPLICATION_JSON)); - - assertThat(external.getForObject("/api/external", String.class)).isEqualTo("hello"); - - assertThat(registry.get("http.client.requests").timer().count()).isEqualTo(1L); - } - - @Test - public void requestMappingIsInstrumented() { - loopback.getForObject("/api/people", String.class); - - assertThat(registry.get("http.server.requests").timer().count()).isEqualTo(1L); - } - - @Test - public void automaticallyRegisteredBinders() { - assertThat(context.getBeansOfType(MeterBinder.class).values()) - .hasAtLeastOneElementOfType(LogbackMetrics.class) - .hasAtLeastOneElementOfType(JvmGcMetrics.class) - .hasAtLeastOneElementOfType(JvmGcMetrics.class) - .hasAtLeastOneElementOfType(JvmThreadMetrics.class) - .hasAtLeastOneElementOfType(ClassLoaderMetrics.class) - .hasAtLeastOneElementOfType(UptimeMetrics.class) - .hasAtLeastOneElementOfType(ProcessorMetrics.class) - .hasAtLeastOneElementOfType(FileDescriptorMetrics.class); - } - - @Test - public void registryCustomizersAreAppliedBeforeRegistryIsInjectableElsewhere() { - registry.get("my.thing").tags("common", "tag").gauge(); - } - - @SpringBootApplication(scanBasePackages = "ignored") - @Import(PersonController.class) - static class MetricsApp { - @Bean - MockClock mockClock() { - return new MockClock(); - } - - @Bean - public MeterRegistryCustomizer commonTags() { - return r -> r.config().commonTags("common", "tag"); - } - - @Bean - public MyThing myBinder(MeterRegistry registry) { - // this should have the common tag - registry.gauge("my.thing", 0); - return new MyThing(); - } - - @Bean - public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) { - return restTemplateBuilder.build(); - } - - private class MyThing { - } - - } - - @RestController - static class PersonController { - @GetMapping("/api/people") - String personName() { - return "Jon"; - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MetricsAutoConfigurationTest.java deleted file mode 100644 index e040efd54e..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/MetricsAutoConfigurationTest.java +++ /dev/null @@ -1,218 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; -import org.springframework.test.util.ReflectionTestUtils; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.Meter; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.MeterBinder; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.core.instrument.config.MeterFilterReply; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; - -import io.micrometer.spring.scheduling.ScheduledMethodMetrics; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -/** - * Tests for {@link MetricsAutoConfiguration}. - * - * @author Andy Wilkinson - * @author Johnny Lim - * @author Stephane Nicoll - */ -class MetricsAutoConfigurationTest { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - void autoConfiguresAClock() { - registerAndRefresh(BaseMeterRegistryConfiguration.class); - assertThat(context.getBean(Clock.class)).isNotNull(); - } - - @Test - void allowsACustomClockToBeUsed() { - registerAndRefresh(BaseMeterRegistryConfiguration.class, CustomClockConfiguration.class); - assertThat(context.getBean(Clock.class)).isEqualTo(context.getBean("customClock")); - } - - @SuppressWarnings("unchecked") - @Test - void configuresMeterRegistries() { - registerAndRefresh(CustomMeterRegistryConfiguration.class); - MeterRegistry meterRegistry = context.getBean(MeterRegistry.class); - MeterFilter[] filters = (MeterFilter[]) ReflectionTestUtils.getField(meterRegistry, "filters"); - assertThat(filters).hasSize(3); - assertThat(filters[0].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.DENY); - assertThat(filters[1]).isInstanceOf(PropertiesMeterFilter.class); - assertThat(filters[2].accept((Meter.Id) null)).isEqualTo(MeterFilterReply.ACCEPT); - verify((MeterBinder) context.getBean("meterBinder")).bindTo(meterRegistry); - verify(context.getBean(MeterRegistryCustomizer.class)).customize(meterRegistry); - } - - @Test - void backsOffWhenSpringAopEnabledIsFalse() { - EnvironmentTestUtils.addEnvironment(context, "spring.aop.auto=false"); - - registerAndRefresh(BaseMeterRegistryConfiguration.class); - - assertThatThrownBy(() -> context.getBean(ScheduledMethodMetrics.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - void backsOffWhenScheduledEnabledIsFalse() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.binders.scheduled.enabled=false"); - - registerAndRefresh(BaseMeterRegistryConfiguration.class); - - assertThatThrownBy(() -> context.getBean(ScheduledMethodMetrics.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - void backsOffWhenCustomScheduledMethodMetricsIsProvided() { - registerAndRefresh(BaseMeterRegistryConfiguration.class, ScheduledMethodMetricsConfiguration.class); - - assertThat(context.getBean(ScheduledMethodMetrics.class)).isInstanceOf(MyScheduledMethodMetrics.class); - } - - @Test - void scheduledMethodMetricsIsAvailableByDefault() { - registerAndRefresh(BaseMeterRegistryConfiguration.class); - - assertThat(context.getBean(ScheduledMethodMetrics.class)).isInstanceOf(ScheduledMethodMetrics.class); - } - - @Test - void definesTagsProviderAndFilterWhenMeterRegistryIsPresent() { - prepareEnvironment("management.metrics.tags.region=test", - "management.metrics.tags.origin=local"); - registerAndRefresh(MetricsAutoConfiguration.class, - CompositeMeterRegistryAutoConfiguration.class); - - MeterRegistry registry = this.context.getBean(MeterRegistry.class); - registry.counter("my.counter", "env", "qa"); - assertThat(registry.find("my.counter").tags("env", "qa") - .tags("region", "test").tags("origin", "local").counter()) - .isNotNull(); - } - - private void prepareEnvironment(String... properties) { - EnvironmentTestUtils.addEnvironment(this.context, properties); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length > 0) { - this.context.register(configurationClasses); - } - this.context.register(MetricsAutoConfiguration.class); - this.context.refresh(); - } - - @Configuration - static class BaseMeterRegistryConfiguration { - - @Bean - MeterRegistry meterRegistry() { - return new SimpleMeterRegistry(); - } - - } - - @Configuration - static class CustomClockConfiguration { - - @Bean - Clock customClock() { - return Clock.SYSTEM; - } - - } - - @Configuration - static class CustomMeterRegistryConfiguration { - - @Bean - MeterRegistry meterRegistry() { - return new SimpleMeterRegistry(); - } - - @Bean - @SuppressWarnings("rawtypes") - MeterRegistryCustomizer meterRegistryCustomizer() { - return mock(MeterRegistryCustomizer.class); - } - - @Bean - MeterBinder meterBinder() { - return mock(MeterBinder.class); - } - - @Bean - @Order(1) - MeterFilter acceptMeterFilter() { - return MeterFilter.accept(); - } - - @Bean - @Order(-1) - MeterFilter denyMeterFilter() { - return MeterFilter.deny(); - } - - } - - @Configuration - static class ScheduledMethodMetricsConfiguration { - - @Bean - public ScheduledMethodMetrics scheduledMethodMetrics(MeterRegistry registry) { - return new MyScheduledMethodMetrics(registry); - } - - } - - static class MyScheduledMethodMetrics extends ScheduledMethodMetrics { - - public MyScheduledMethodMetrics(MeterRegistry registry) { - super(registry); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PrometheusEndpointIntegrationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PrometheusEndpointIntegrationTest.java deleted file mode 100644 index 677a1b1d22..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PrometheusEndpointIntegrationTest.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, - classes = PrometheusEndpointIntegrationTest.MetricsApp.class, - properties = { - "management.security.enabled=false", - "management.metrics.export.prometheus.enabled=true" - } -) -public class PrometheusEndpointIntegrationTest { - - @Autowired - private TestRestTemplate testRestTemplate; - - @Test - public void producesTextPlain() { - HttpHeaders headers = new HttpHeaders(); - headers.add(HttpHeaders.ACCEPT, MediaType.TEXT_PLAIN_VALUE); - HttpEntity request = new HttpEntity<>(headers); - ResponseEntity result = testRestTemplate.exchange("/prometheus", HttpMethod.GET, request, String.class); - assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - @SpringBootApplication(scanBasePackages = "ignore") - static class MetricsApp { - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilterIntegrationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilterIntegrationTest.java deleted file mode 100644 index 22275921d3..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilterIntegrationTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.config.MeterFilter; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.core.Ordered; -import org.springframework.core.annotation.Order; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, classes = PropertiesMeterFilterIntegrationTest.MetricsApp.class) -@TestPropertySource(properties = { - "management.metrics.enable[my.timer]=true", /* overriden by programmatic filter */ - "management.metrics.enable[my.counter]=false" -}) -public class PropertiesMeterFilterIntegrationTest { - - @Autowired - private MeterRegistry registry; - - @Test - public void propertyBasedMeterFilters() { - registry.counter("my.counter"); - assertThat(registry.find("my.counter").counter()).isNull(); - } - - @Test - public void propertyBasedMeterFiltersCanTakeLowerPrecedenceThanProgrammaticallyBoundFilters() { - registry.timer("my.timer"); - assertThat(registry.find("my.timer").meter()).isNull(); - } - - @SpringBootApplication(scanBasePackages = "ignore") - static class MetricsApp { - @Bean - @Order(Ordered.HIGHEST_PRECEDENCE) - public MeterRegistryCustomizer meterFilter() { - return r -> r.config().meterFilter(MeterFilter.deny(id -> id.getName().contains("my.timer"))); - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilterTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilterTest.java deleted file mode 100644 index 09204cc779..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/PropertiesMeterFilterTest.java +++ /dev/null @@ -1,321 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.Meter; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.config.MeterFilterReply; -import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link PropertiesMeterFilter}. - * - * @author Phillip Webb - * @author Jon Schneider - * @author Artsiom Yudovin - */ -@SuppressWarnings("ConstantConditions") -public class PropertiesMeterFilterTest { - @Rule - public ExpectedException thrown = ExpectedException.none(); - - private MetricsProperties properties = new MetricsProperties(); - - private PropertiesMeterFilter filter = new PropertiesMeterFilter(properties); - - @Test - public void createWhenPropertiesIsNullShouldThrowException() { - thrown.expect(IllegalArgumentException.class); - thrown.expectMessage("Properties must not be null"); - new PropertiesMeterFilter(null); - } - - @Test - public void acceptWhenHasNoEnabledPropertiesShouldReturnNeutral() { - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.NEUTRAL); - } - - @Test - public void acceptWhenHasNoMatchingEnabledPropertyShouldReturnNeutral() { - properties.getEnable().put("something.else", false); - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.NEUTRAL); - } - - @Test - public void acceptWhenHasEnableFalseShouldReturnDeny() { - enable("spring.boot", false); - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.DENY); - } - - @Test - public void acceptWhenHasEnableTrueShouldReturnNeutral() { - enable("spring.boot", true); - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.NEUTRAL); - } - - @Test - public void acceptWhenHasHigherEnableFalseShouldReturnDeny() { - enable("spring", false); - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.DENY); - } - - @Test - public void acceptWhenHasHigherEnableTrueShouldReturnNeutral() { - enable("spring", true); - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.NEUTRAL); - } - - @Test - public void acceptWhenHasHigherEnableFalseExactEnableTrueShouldReturnNeutral() { - enable("spring", false); - enable("spring.boot", true); - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.NEUTRAL); - } - - @Test - public void acceptWhenHasHigherEnableTrueExactEnableFalseShouldReturnDeny() { - enable("spring", true); - enable("spring.boot", false); - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.DENY); - } - - @Test - public void acceptWhenHasAllEnableFalseShouldReturnDeny() { - enable("all", false); - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.DENY); - } - - @Test - public void acceptWhenHasAllEnableFalseButHigherEnableTrueShouldReturnNeutral() { - enable("all", false); - enable("spring", true); - assertThat(filter.accept(createSpringBootMeter())) - .isEqualTo(MeterFilterReply.NEUTRAL); - } - - @Test - public void configureWhenHasHistogramTrueShouldSetPercentilesHistogramToTrue() { - percentilesHistogram("spring.boot", true); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .isPercentileHistogram()).isTrue(); - } - - @Test - public void configureWhenHasHistogramFalseShouldSetPercentilesHistogramToFalse() { - percentilesHistogram("spring.boot", false); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .isPercentileHistogram()).isFalse(); - } - - @Test - public void configureWhenHasHigherHistogramTrueShouldSetPercentilesHistogramToTrue() { - percentilesHistogram("spring", true); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .isPercentileHistogram()).isTrue(); - } - - @Test - public void configureWhenHasHigherHistogramFalseShouldSetPercentilesHistogramToFalse() { - percentilesHistogram("spring", false); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .isPercentileHistogram()).isFalse(); - } - - @Test - public void configureWhenHasHigherHistogramTrueAndLowerFalseShouldSetPercentilesHistogramToFalse() { - percentilesHistogram("spring", true); - percentilesHistogram("spring.boot", false); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .isPercentileHistogram()).isFalse(); - } - - @Test - public void configureWhenHasHigherHistogramFalseAndLowerTrueShouldSetPercentilesHistogramToFalse() { - percentilesHistogram("spring", false); - percentilesHistogram("spring.boot", true); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .isPercentileHistogram()).isTrue(); - } - - @Test - public void configureWhenAllHistogramTrueSetPercentilesHistogramToTrue() { - percentilesHistogram("all", true); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .isPercentileHistogram()).isTrue(); - } - - @Test - public void configureWhenHasPercentilesShouldSetPercentilesToValue() { - percentiles("spring.boot", 0.5, 0.9); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .getPercentiles()).containsExactly(0.5, 0.9); - } - - @Test - public void configureWhenHasHigherPercentilesShouldSetPercentilesToValue() { - percentiles("spring", 0.5, 0.9); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .getPercentiles()).containsExactly(0.5, 0.9); - } - - @Test - public void configureWhenHasHigherPercentilesAndLowerShouldSetPercentilesToHigher() { - percentiles("spring", 0.5); - percentiles("spring.boot", 0.9); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .getPercentiles()).containsExactly(0.9); - } - - @Test - public void configureWhenAllPercentilesSetShouldSetPercentilesToValue() { - percentiles("all", 0.5); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .getPercentiles()).containsExactly(0.5); - } - - @Test - public void configureWhenHasSlaShouldSetSlaToValue() { - slas("spring.boot", "1", "2", "3"); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .getSlaBoundaries()).containsExactly(1000000, 2000000, 3000000); - } - - @Test - public void configureWhenHasHigherSlaShouldSetPercentilesToValue() { - slas("spring", "1", "2", "3"); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .getSlaBoundaries()).containsExactly(1000000, 2000000, 3000000); - } - - @Test - public void configureWhenHasHigherSlaAndLowerShouldSetSlaToHigher() { - slas("spring", "1", "2", "3"); - slas("spring.boot", "4", "5", "6"); - assertThat(filter.configure(createSpringBootMeter(), DistributionStatisticConfig.DEFAULT) - .getSlaBoundaries()).containsExactly(4000000, 5000000, 6000000); - } - - @Test - public void configureWhenHasMinimumExpectedValueShouldSetMinimumExpectedToValue() { - setMinimumExpectedValue("spring.boot", 10); - assertThat(filter.configure(createSpringBootMeter(), - DistributionStatisticConfig.DEFAULT).getMinimumExpectedValue()) - .isEqualTo(Duration.ofMillis(10).toNanos()); - } - - @Test - public void configureWhenHasHigherMinimumExpectedValueShouldSetMinimumExpectedValueToValue() { - setMinimumExpectedValue("spring", 10); - assertThat(filter.configure(createSpringBootMeter(), - DistributionStatisticConfig.DEFAULT).getMinimumExpectedValue()) - .isEqualTo(Duration.ofMillis(10).toNanos()); - } - - @Test - public void configureWhenHasHigherMinimumExpectedValueAndLowerShouldSetMinimumExpectedValueToHigher() { - setMinimumExpectedValue("spring", 10); - setMinimumExpectedValue("spring.boot", 50); - assertThat(filter.configure(createSpringBootMeter(), - DistributionStatisticConfig.DEFAULT).getMinimumExpectedValue()) - .isEqualTo(Duration.ofMillis(50).toNanos()); - } - - @Test - public void configureWhenHasMaximumExpectedValueShouldSetMaximumExpectedToValue() { - setMaximumExpectedValue("spring.boot", 5000); - assertThat(filter.configure(createSpringBootMeter(), - DistributionStatisticConfig.DEFAULT).getMaximumExpectedValue()) - .isEqualTo(Duration.ofMillis(5000).toNanos()); - } - - @Test - public void configureWhenHasHigherMaximumExpectedValueShouldSetMaximumExpectedValueToValue() { - setMaximumExpectedValue("spring", 5000); - assertThat(filter.configure(createSpringBootMeter(), - DistributionStatisticConfig.DEFAULT).getMaximumExpectedValue()) - .isEqualTo(Duration.ofMillis(5000).toNanos()); - } - - @Test - public void configureWhenHasHigherMaximumExpectedValueAndLowerShouldSetMaximumExpectedValueToHigher() { - setMaximumExpectedValue("spring", 5000); - setMaximumExpectedValue("spring.boot", 10000); - assertThat(filter.configure(createSpringBootMeter(), - DistributionStatisticConfig.DEFAULT).getMaximumExpectedValue()) - .isEqualTo(Duration.ofMillis(10000).toNanos()); - } - - private Meter.Id createSpringBootMeter() { - Meter.Type meterType = Meter.Type.TIMER; - return createSpringBootMeter(meterType); - } - - private Meter.Id createSpringBootMeter(Meter.Type meterType) { - MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, Clock.SYSTEM); - return Meter.builder("spring.boot", meterType, Collections.emptyList()).register(registry) - .getId(); - } - - private void enable(String metricPrefix, boolean enabled) { - properties.getEnable().put(metricPrefix, enabled); - } - - private void percentilesHistogram(String metricPrefix, boolean enabled) { - properties.getDistribution().getPercentilesHistogram().put(metricPrefix, enabled); - } - - private void percentiles(String metricPrefix, double... percentiles) { - properties.getDistribution().getPercentiles().put(metricPrefix, percentiles); - } - - private void slas(String metricPrefix, String... slas) { - properties.getDistribution().getSla().put(metricPrefix, - Arrays.stream(slas).map(ServiceLevelAgreementBoundary::valueOf) - .toArray(ServiceLevelAgreementBoundary[]::new)); - } - - private void setMinimumExpectedValue(String metricPrefix, long minimumExpectedValue) { - properties.getDistribution().getMinimumExpectedValue() - .put(metricPrefix, Long.toString(minimumExpectedValue)); - } - - private void setMaximumExpectedValue(String metricPrefix, long maximumExpectedValue) { - properties.getDistribution().getMaximumExpectedValue() - .put(metricPrefix, Long.toString(maximumExpectedValue)); - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/ServiceLevelAgreementBoundaryTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/ServiceLevelAgreementBoundaryTest.java deleted file mode 100644 index a972922a40..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/ServiceLevelAgreementBoundaryTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.Meter; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link ServiceLevelAgreementBoundary}. - * - * @author Phillip Webb - */ -class ServiceLevelAgreementBoundaryTest { - - @Test - void getValueForTimerWhenFromLongShouldReturnMsToNanosValue() { - ServiceLevelAgreementBoundary sla = ServiceLevelAgreementBoundary.valueOf(123L); - assertThat(sla.getValue(Meter.Type.TIMER)).isEqualTo(123000000); - } - - @Test - void getValueForTimerWhenFromNumberStringShouldMsToNanosValue() { - ServiceLevelAgreementBoundary sla = ServiceLevelAgreementBoundary.valueOf("123"); - assertThat(sla.getValue(Meter.Type.TIMER)).isEqualTo(123000000); - } - - @Test - void getValueForTimerWhenFromDurationStringShouldReturnDurationNanos() { - ServiceLevelAgreementBoundary sla = ServiceLevelAgreementBoundary.valueOf("123ms"); - assertThat(sla.getValue(Meter.Type.TIMER)).isEqualTo(123000000); - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/SingleRegistryDoubleCountingTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/SingleRegistryDoubleCountingTest.java deleted file mode 100644 index 6c801d079e..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/SingleRegistryDoubleCountingTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.ApplicationContext; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = SingleRegistryDoubleCountingTest.MetricsApp.class) -@TestPropertySource(properties = { - "management.metrics.export.prometheus.enabled=true", - "management.metrics.export.prometheus.pushgateway.enabled=false", -}) -public class SingleRegistryDoubleCountingTest { - @Autowired - private MeterRegistry registry; - - @Autowired - private ApplicationContext context; - - @Test - public void singleRegistryIsCreated() { - assertThat(registry).isNotInstanceOf(CompositeMeterRegistry.class); - - assertThat(registry.config().clock()).isNotNull(); - } - - @Test - public void metricsAreNotCountedTwice() { - Logger logger = LoggerFactory.getLogger("test-logger"); - logger.error("Error."); - - Map registriesByName = context - .getBeansOfType(MeterRegistry.class); - assertThat(registriesByName).hasSize(1); - registriesByName.forEach((name, registry) -> - assertThat(registry - .get("logback.events") - .tag("level", "error") - .counter() - .count()) - .isEqualTo(1)); - } - - @SpringBootApplication(scanBasePackages = "ignored") - static class MetricsApp { - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/SystemMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/SystemMetricsAutoConfigurationTest.java deleted file mode 100644 index 1d761bcc11..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/SystemMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure; - -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.system.FileDescriptorMetrics; -import io.micrometer.core.instrument.binder.system.ProcessorMetrics; -import io.micrometer.core.instrument.binder.system.UptimeMetrics; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link SystemMetricsAutoConfiguration}. - * - * @author Andy Wilkinson - * @author Stephane Nicoll - * @author Johnny Lim - */ -public class SystemMetricsAutoConfigurationTest { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - public void autoConfiguresUptimeMetrics() { - registerAndRefresh(); - assertThat(context.getBean(UptimeMetrics.class)).isNotNull(); - } - - @Test - @Deprecated - public void allowsUptimeMetricsToBeDisabled() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.binders.uptime.enabled=false"); - registerAndRefresh(); - assertThat(context.getBeansOfType(UptimeMetrics.class)).isEmpty(); - } - - @Test - public void allowsCustomUptimeMetricsToBeUsed() { - registerAndRefresh(CustomUptimeMetricsConfiguration.class); - assertThat(context.getBean(UptimeMetrics.class)).isEqualTo(context.getBean("customUptimeMetrics")); - } - - @Test - public void autoConfiguresProcessorMetrics() { - registerAndRefresh(); - assertThat(context.getBean(ProcessorMetrics.class)).isNotNull(); - } - - @Test - @Deprecated - public void allowsProcessorMetricsToBeDisabled() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.binders.processor.enabled=false"); - registerAndRefresh(); - assertThat(context.getBeansOfType(ProcessorMetrics.class)).isEmpty(); - } - - @Test - public void allowsCustomProcessorMetricsToBeUsed() { - registerAndRefresh(CustomProcessorMetricsConfiguration.class); - assertThat(context.getBean(ProcessorMetrics.class)).isEqualTo(context.getBean("customProcessorMetrics")); - } - - @Test - public void autoConfiguresFileDescriptorMetrics() { - registerAndRefresh(); - assertThat(context.getBean(FileDescriptorMetrics.class)).isNotNull(); - } - - @Test - @Deprecated - public void allowsFileDescriptorMetricsToBeDisabled() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.binders.files.enabled=false"); - registerAndRefresh(); - assertThat(context.getBeansOfType(FileDescriptorMetrics.class)).isEmpty(); - } - - @Test - public void allowsCustomFileDescriptorMetricsToBeUsed() { - registerAndRefresh(CustomFileDescriptorMetricsConfiguration.class); - assertThat(context.getBean(FileDescriptorMetrics.class)).isEqualTo(context.getBean("customFileDescriptorMetrics")); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length != 0) { - this.context.register(configurationClasses); - } - this.context.register(MeterRegistryConfiguration.class, SystemMetricsAutoConfiguration.class); - this.context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public MeterRegistry meterRegistry() { - return mock(MeterRegistry.class); - } - - } - - @Configuration - static class CustomUptimeMetricsConfiguration { - - @Bean - public UptimeMetrics customUptimeMetrics() { - return new UptimeMetrics(); - } - - } - - @Configuration - static class CustomProcessorMetricsConfiguration { - - @Bean - public ProcessorMetrics customProcessorMetrics() { - return new ProcessorMetrics(); - } - - } - - @Configuration - static class CustomFileDescriptorMetricsConfiguration { - - @Bean - public FileDescriptorMetrics customFileDescriptorMetrics() { - return new FileDescriptorMetrics(); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsAutoConfigurationTest.java deleted file mode 100644 index 81e543ffeb..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/cache/CacheMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2012-2019 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.micrometer.spring.autoconfigure.cache; - -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.spring.cache.CacheMetricsRegistrar; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.cache.CacheManager; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link CacheMetricsAutoConfiguration}. - * - * @author Johnny Lim - */ -class CacheMetricsAutoConfigurationTest { - - private final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - void autoConfigureWorks() { - registerAndRefresh( - CacheManagerConfiguration.class, - MeterRegistryConfiguration.class, - CacheMetricsAutoConfiguration.class); - assertThat(context.getBean(CacheMetricsRegistrar.class)).isNotNull(); - } - - @Test - void backsOffWhenMeterRegistryIsMissing() { - registerAndRefresh( - CacheManagerConfiguration.class, - CacheMetricsAutoConfiguration.class); - assertThat(context.getBeansOfType(CacheMetricsRegistrar.class)).isEmpty(); - } - - private void registerAndRefresh(Class... configurationClasses) { - context.register(configurationClasses); - context.refresh(); - } - - @Configuration - static class CacheManagerConfiguration { - - @Bean - public CacheManager cacheManager() { - return mock(CacheManager.class); - } - - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public SimpleMeterRegistry meterRegistry() { - return new SimpleMeterRegistry(); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/StringToDurationConverterTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/StringToDurationConverterTest.java deleted file mode 100644 index 7de30759c2..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/StringToDurationConverterTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export; - -import org.junit.Test; - -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - -public class StringToDurationConverterTest { - private StringToDurationConverter converter = new StringToDurationConverter(); - - @Test - public void rfc() { - assertThat(converter.convert("PT10M")).isEqualTo(Duration.ofMinutes(10)); - } - - @Test - public void shorthand() { - assertThat(converter.convert("10s")).isEqualTo(Duration.ofSeconds(10)); - } - - @Test - public void invalidShorthand() { - assertThatThrownBy(() -> converter.convert("10rs")) - .isInstanceOf(IllegalArgumentException.class); - } -} \ No newline at end of file diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsMetricsExportAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsMetricsExportAutoConfigurationTest.java deleted file mode 100644 index 787265d8cd..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsMetricsExportAutoConfigurationTest.java +++ /dev/null @@ -1,152 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.appoptics; - -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -import io.micrometer.appoptics.AppOpticsConfig; -import io.micrometer.appoptics.AppOpticsMeterRegistry; -import io.micrometer.core.instrument.Clock; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - -/** - * Tests for {@link AppOpticsMetricsExportAutoConfiguration}. - * - * @author Stephane Nicoll - * @author Johnny Lim - */ -class AppOpticsMetricsExportAutoConfigurationTest { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - void backsOffWithoutAClock() { - registerAndRefresh(); - assertThatExceptionOfType(NoSuchBeanDefinitionException.class) - .isThrownBy(() -> context.getBean(AppOpticsMeterRegistry.class)); - } - - @Test - void autoConfiguresItsConfigAndMeterRegistry() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.appoptics.api-token=fakeToken"); - registerAndRefresh(BaseConfiguration.class); - assertThat(context.getBean(AppOpticsMeterRegistry.class)).isNotNull(); - assertThat(context.getBean(AppOpticsConfig.class)).isNotNull(); - } - - @Test - void autoConfigurationCanBeDisabled() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.appoptics.enabled=false"); - registerAndRefresh(BaseConfiguration.class); - assertThatExceptionOfType(NoSuchBeanDefinitionException.class) - .isThrownBy(() -> context.getBean(AppOpticsMeterRegistry.class)); - assertThatExceptionOfType(NoSuchBeanDefinitionException.class) - .isThrownBy(() -> context.getBean(AppOpticsConfig.class)); - } - - @Test - void allowsCustomConfigToBeUsed() { - registerAndRefresh(CustomConfigConfiguration.class); - assertThat(context.getBean(AppOpticsMeterRegistry.class)).isNotNull(); - assertThat(context.getBean(AppOpticsConfig.class)).isEqualTo(context.getBean("customConfig")); - } - - @Test - void allowsCustomRegistryToBeUsed() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.appoptics.api-token=fakeToken"); - registerAndRefresh(CustomRegistryConfiguration.class); - assertThat(context.getBean(AppOpticsMeterRegistry.class)).isEqualTo(context.getBean("customRegistry")); - assertThat(context.getBean(AppOpticsConfig.class)).isNotNull(); - } - - @Test - public void stopsMeterRegistryWhenContextIsClosed() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.appoptics.api-token=fakeToken"); - registerAndRefresh(BaseConfiguration.class); - AppOpticsMeterRegistry registry = context.getBean(AppOpticsMeterRegistry.class); - assertThat(registry.isClosed()).isFalse(); - context.close(); - assertThat(registry.isClosed()).isTrue(); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length > 0) { - context.register(configurationClasses); - } - context.register(AppOpticsMetricsExportAutoConfiguration.class); - context.refresh(); - } - - @Configuration - static class BaseConfiguration { - - @Bean - public Clock clock() { - return Clock.SYSTEM; - } - - } - - @Configuration - @Import(BaseConfiguration.class) - static class CustomConfigConfiguration { - - @Bean - public AppOpticsConfig customConfig() { - return new AppOpticsConfig() { - @Override - public String get(String key) { - return null; - } - - @Override - public String apiToken() { - return "fake"; - } - }; - } - - } - - @Configuration - @Import(BaseConfiguration.class) - static class CustomRegistryConfiguration { - - @Bean - public AppOpticsMeterRegistry customRegistry(AppOpticsConfig config, - Clock clock) { - return new AppOpticsMeterRegistry(config, clock); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapterTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapterTest.java deleted file mode 100644 index 042bd25017..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesConfigAdapterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.appoptics; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapterTest; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link AppOpticsPropertiesConfigAdapter}. - * - * @author Stephane Nicoll - */ -public class AppOpticsPropertiesConfigAdapterTest extends - StepRegistryPropertiesConfigAdapterTest { - - @Override - protected AppOpticsProperties createProperties() { - return new AppOpticsProperties(); - } - - @Override - protected AppOpticsPropertiesConfigAdapter createConfigAdapter( - AppOpticsProperties properties) { - return new AppOpticsPropertiesConfigAdapter(properties); - } - - @Test - public void whenPropertiesUrisIsSetAdapterUriReturnsIt() { - AppOpticsProperties properties = createProperties(); - properties.setUri("https://appoptics.example.com/v1/measurements"); - assertThat(createConfigAdapter(properties).uri()) - .isEqualTo("https://appoptics.example.com/v1/measurements"); - } - - @Test - public void whenPropertiesApiTokenIsSetAdapterApiTokenReturnsIt() { - AppOpticsProperties properties = createProperties(); - properties.setApiToken("ABC123"); - assertThat(createConfigAdapter(properties).apiToken()).isEqualTo("ABC123"); - } - - @Test - public void whenPropertiesHostTagIsSetAdapterHostTagReturnsIt() { - AppOpticsProperties properties = createProperties(); - properties.setHostTag("node"); - assertThat(createConfigAdapter(properties).hostTag()).isEqualTo("node"); - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesTest.java deleted file mode 100644 index 48ad739256..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/appoptics/AppOpticsPropertiesTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.appoptics; - -import io.micrometer.appoptics.AppOpticsConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesTest; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link AppOpticsProperties}. - * - * @author Stephane Nicoll - */ -public class AppOpticsPropertiesTest extends StepRegistryPropertiesTest { - - @Override - public void defaultValuesAreConsistent() { - AppOpticsProperties properties = new AppOpticsProperties(); - AppOpticsConfig config = (key) -> null; - assertStepRegistryDefaultValues(properties, config); - assertThat(properties.getUri()).isEqualToIgnoringWhitespace(config.uri()); - assertThat(properties.getHostTag()).isEqualToIgnoringWhitespace(config.hostTag()); - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/humio/HumioMetricsExportAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/humio/HumioMetricsExportAutoConfigurationTest.java deleted file mode 100644 index 3c223740d9..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/humio/HumioMetricsExportAutoConfigurationTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.humio; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.humio.HumioConfig; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link HumioMetricsExportAutoConfiguration}. - */ -class HumioMetricsExportAutoConfigurationTest { - - private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - - @Test - void anyAdditionToTagsReplacesDefault() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.humio.tags.app=myapp"); - registerAndRefresh(ClockConfiguration.class, HumioMetricsExportAutoConfiguration.class); - assertThat(context.getBean(HumioConfig.class).tags()).containsOnlyKeys("app"); - } - - @Test - void defaultTag() { - registerAndRefresh(ClockConfiguration.class, HumioMetricsExportAutoConfiguration.class); - assertThat(context.getBean(HumioConfig.class).tags()).isEmpty(); - } - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - private void registerAndRefresh(Class... configurationClasses) { - context.register(configurationClasses); - context.refresh(); - } - - @Configuration - static class ClockConfiguration { - @Bean - public Clock clock() { - return Clock.SYSTEM; - } - - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfigurationTest.java deleted file mode 100644 index 9f523806f2..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosMetricsExportAutoConfigurationTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.kairos; - -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.kairos.KairosConfig; -import io.micrometer.kairos.KairosMeterRegistry; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatExceptionOfType; - -/** - * Tests for {@link KairosMetricsExportAutoConfiguration}. - * - * @author Stephane Nicoll - * @author Johnny Lim - */ -class KairosMetricsExportAutoConfigurationTest { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - void backsOffWithoutAClock() { - registerAndRefresh(); - assertThatExceptionOfType(NoSuchBeanDefinitionException.class) - .isThrownBy(() -> context.getBean(KairosMeterRegistry.class)); - } - - @Test - void autoConfiguresItsConfigAndMeterRegistry() { - registerAndRefresh(BaseConfiguration.class); - assertThat(context.getBean(KairosMeterRegistry.class)).isNotNull(); - assertThat(context.getBean(KairosConfig.class)).isNotNull(); - } - - @Test - void autoConfigurationCanBeDisabled() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.kairos.enabled=false"); - registerAndRefresh(BaseConfiguration.class); - assertThatExceptionOfType(NoSuchBeanDefinitionException.class) - .isThrownBy(() -> context.getBean(KairosMeterRegistry.class)); - assertThatExceptionOfType(NoSuchBeanDefinitionException.class) - .isThrownBy(() -> context.getBean(KairosConfig.class)); - } - - @Test - void allowsCustomConfigToBeUsed() { - registerAndRefresh(CustomConfigConfiguration.class); - assertThat(context.getBean(KairosMeterRegistry.class)).isNotNull(); - assertThat(context.getBean(KairosConfig.class)).isEqualTo(context.getBean("customConfig")); - } - - @Test - void allowsCustomRegistryToBeUsed() { - registerAndRefresh(CustomRegistryConfiguration.class); - assertThat(context.getBean(KairosMeterRegistry.class)).isEqualTo(context.getBean("customRegistry")); - assertThat(context.getBean(KairosConfig.class)).isNotNull(); - } - - @Test - void stopsMeterRegistryWhenContextIsClosed() { - registerAndRefresh(BaseConfiguration.class); - KairosMeterRegistry registry = context.getBean(KairosMeterRegistry.class); - assertThat(registry.isClosed()).isFalse(); - context.close(); - assertThat(registry.isClosed()).isTrue(); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length > 0) { - context.register(configurationClasses); - } - context.register(KairosMetricsExportAutoConfiguration.class); - context.refresh(); - } - - @Configuration - static class BaseConfiguration { - - @Bean - public Clock clock() { - return Clock.SYSTEM; - } - - } - - @Configuration - @Import(BaseConfiguration.class) - static class CustomConfigConfiguration { - - @Bean - public KairosConfig customConfig() { - return (key) -> null; - } - - } - - @Configuration - @Import(BaseConfiguration.class) - static class CustomRegistryConfiguration { - - @Bean - public KairosMeterRegistry customRegistry(KairosConfig config, Clock clock) { - return new KairosMeterRegistry(config, clock); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapterTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapterTest.java deleted file mode 100644 index 0cf8840475..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesConfigAdapterTest.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.kairos; - -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesConfigAdapterTest; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link KairosPropertiesConfigAdapter}. - * - * @author Stephane Nicoll - */ -public class KairosPropertiesConfigAdapterTest extends - StepRegistryPropertiesConfigAdapterTest { - - @Override - protected KairosProperties createProperties() { - return new KairosProperties(); - } - - @Override - protected KairosPropertiesConfigAdapter createConfigAdapter( - KairosProperties properties) { - return new KairosPropertiesConfigAdapter(properties); - } - - @Test - public void whenPropertiesUriIsSetAdapterUriReturnsIt() { - KairosProperties properties = createProperties(); - properties.setUri("https://kairos.example.com:8080/api/v1/datapoints"); - assertThat(createConfigAdapter(properties).uri()) - .isEqualTo("https://kairos.example.com:8080/api/v1/datapoints"); - } - - @Test - public void whenPropertiesUserNameIsSetAdapterUserNameReturnsIt() { - KairosProperties properties = createProperties(); - properties.setUserName("alice"); - assertThat(createConfigAdapter(properties).userName()).isEqualTo("alice"); - } - - @Test - public void whenPropertiesPasswordIsSetAdapterPasswordReturnsIt() { - KairosProperties properties = createProperties(); - properties.setPassword("secret"); - assertThat(createConfigAdapter(properties).password()).isEqualTo("secret"); - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesTest.java deleted file mode 100644 index 74b84db7dd..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/kairos/KairosPropertiesTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.kairos; - -import io.micrometer.kairos.KairosConfig; -import io.micrometer.spring.autoconfigure.export.properties.StepRegistryPropertiesTest; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link KairosProperties}. - * - * @author Stephane Nicoll - */ -public class KairosPropertiesTest extends StepRegistryPropertiesTest { - - @Override - public void defaultValuesAreConsistent() { - KairosProperties properties = new KairosProperties(); - KairosConfig config = KairosConfig.DEFAULT; - assertStepRegistryDefaultValues(properties, config); - assertThat(properties.getUri()).isEqualToIgnoringWhitespace(config.uri()); - assertThat(properties.getUserName()) - .isEqualToIgnoringWhitespace(config.userName()); - assertThat(properties.getPassword()) - .isEqualToIgnoringWhitespace(config.password()); - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusMetricsExportAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusMetricsExportAutoConfigurationTest.java deleted file mode 100644 index 7b20ac9e10..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/prometheus/PrometheusMetricsExportAutoConfigurationTest.java +++ /dev/null @@ -1,176 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.prometheus; - -import io.micrometer.spring.export.prometheus.PrometheusScrapeMvcEndpoint; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.test.util.ReflectionTestUtils; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.prometheus.PrometheusMeterRegistry; -import io.micrometer.spring.export.prometheus.PrometheusPushGatewayManager; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link PrometheusMetricsExportAutoConfiguration}. - * - * @author Johnny Lim - */ -class PrometheusMetricsExportAutoConfigurationTest { - - private final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - - @AfterEach - void cleanUp() { - context.close(); - } - - @Test - void autoConfigureByDefault() { - registerAndRefresh(); - - assertThat(context.getBean(PrometheusMeterRegistry.class)).isNotNull(); - } - - @Test - void autoConfigureDisabledByProperty() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.prometheus.enabled=false"); - - registerAndRefresh(); - - assertThatThrownBy(() -> context.getBean(PrometheusMeterRegistry.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - void autoConfigurePrometheusPushGatewayDisabledByDefault() { - registerAndRefresh(); - - assertThatThrownBy(() -> context.getBean(PrometheusMetricsExportAutoConfiguration.PrometheusPushGatewayConfiguration.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - void autoConfigurePrometheusPushGatewayEnabledByProperty() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.prometheus.pushgateway.enabled=true"); - - registerAndRefresh(); - - assertThat(context.getBean(PrometheusMetricsExportAutoConfiguration.PrometheusPushGatewayConfiguration.class)).isNotNull(); - } - - @Test - void autoConfigurePrometheusPushGatewayDisabledByPrometheusEnabledProperty() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.prometheus.enabled=false", "management.metrics.export.prometheus.pushgateway.enabled=true"); - - registerAndRefresh(); - - assertThatThrownBy(() -> context.getBean(PrometheusMetricsExportAutoConfiguration.PrometheusPushGatewayConfiguration.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - void withPushGatewayEnabled() { - EnvironmentTestUtils.addEnvironment(context, "management.metrics.export.prometheus.pushgateway.enabled=true"); - - registerAndRefresh(); - - hasGatewayURL("http://localhost:9091/metrics/"); - } - - @Test - @Deprecated - void withCustomLegacyPushGatewayURL() { - EnvironmentTestUtils.addEnvironment(context, - "management.metrics.export.prometheus.pushgateway.enabled=true", - "management.metrics.export.prometheus.pushgateway.base-url=localhost:9090"); - - registerAndRefresh(); - - hasGatewayURL("http://localhost:9090/metrics/"); - } - - @Test - void withCustomPushGatewayURL() { - EnvironmentTestUtils.addEnvironment(context, - "management.metrics.export.prometheus.pushgateway.enabled=true", - "management.metrics.export.prometheus.pushgateway.base-url=https://example.com:8080"); - - registerAndRefresh(); - - hasGatewayURL("https://example.com:8080/metrics/"); - } - - @Test - void autoConfigurePrometheusScrapeMvcEndpoint() { - EnvironmentTestUtils.addEnvironment(this.context); - - registerAndRefresh(ClockConfiguration.class, PrometheusMetricsExportAutoConfiguration.class); - - assertThat(this.context.getBean(PrometheusScrapeMvcEndpoint.class)).isNotNull(); - } - - @Test - void autoConfigurePrometheusScrapeMvcEndpointDisabledByEndpointsEnabledFalse() { - EnvironmentTestUtils.addEnvironment(this.context, "endpoints.enabled=false"); - - registerAndRefresh(ClockConfiguration.class, PrometheusMetricsExportAutoConfiguration.class); - - assertThatThrownBy(() -> this.context.getBean(PrometheusScrapeMvcEndpoint.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - void autoConfigurePrometheusScrapeMvcEndpointDisabledByEndpointsPrometheusEnabledFalse() { - EnvironmentTestUtils.addEnvironment(this.context, "endpoints.prometheus.enabled=false"); - - registerAndRefresh(ClockConfiguration.class, PrometheusMetricsExportAutoConfiguration.class); - - assertThatThrownBy(() -> this.context.getBean(PrometheusScrapeMvcEndpoint.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - private void hasGatewayURL(String url) { - PrometheusPushGatewayManager gatewayManager = context.getBean(PrometheusPushGatewayManager.class); - Object pushGateway = ReflectionTestUtils.getField(gatewayManager, "pushGateway"); - assertThat(pushGateway).hasFieldOrPropertyWithValue("gatewayBaseURL", url); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length > 0) { - context.register(configurationClasses); - } - context.register(ClockConfiguration.class, PrometheusMetricsExportAutoConfiguration.class); - context.refresh(); - } - - @Configuration - static class ClockConfiguration { - @Bean - public Clock clock() { - return mock(Clock.class); - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesConfigAdapterTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesConfigAdapterTest.java deleted file mode 100644 index ae6710ad40..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesConfigAdapterTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.properties; - -import java.time.Duration; - -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Base test for {@link StepRegistryPropertiesConfigAdapter} implementations. - * - * @param

properties used by the tests - * @param adapter used by the tests - * @author Stephane Nicoll - */ -public abstract class StepRegistryPropertiesConfigAdapterTest

> { - - protected abstract P createProperties(); - - protected abstract A createConfigAdapter(P properties); - - @Test - public void whenPropertiesStepIsSetAdapterStepReturnsIt() { - P properties = createProperties(); - properties.setStep(Duration.ofSeconds(42)); - assertThat(createConfigAdapter(properties).step()) - .isEqualTo(Duration.ofSeconds(42)); - } - - @Test - public void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() { - P properties = createProperties(); - properties.setEnabled(false); - assertThat(createConfigAdapter(properties).enabled()).isFalse(); - } - - @Test - public void whenPropertiesConnectTimeoutIsSetAdapterConnectTimeoutReturnsIt() { - P properties = createProperties(); - properties.setConnectTimeout(Duration.ofMinutes(42)); - assertThat(createConfigAdapter(properties).connectTimeout()) - .isEqualTo(Duration.ofMinutes(42)); - } - - @Test - public void whenPropertiesReadTimeoutIsSetAdapterReadTimeoutReturnsIt() { - P properties = createProperties(); - properties.setReadTimeout(Duration.ofMillis(42)); - assertThat(createConfigAdapter(properties).readTimeout()) - .isEqualTo(Duration.ofMillis(42)); - } - - @Test - public void whenPropertiesNumThreadsIsSetAdapterNumThreadsReturnsIt() { - P properties = createProperties(); - properties.setNumThreads(42); - assertThat(createConfigAdapter(properties).numThreads()).isEqualTo(42); - } - - @Test - public void whenPropertiesBatchSizeIsSetAdapterBatchSizeReturnsIt() { - P properties = createProperties(); - properties.setBatchSize(10042); - assertThat(createConfigAdapter(properties).batchSize()).isEqualTo(10042); - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesTest.java deleted file mode 100644 index 6684477313..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/properties/StepRegistryPropertiesTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.properties; - -import io.micrometer.core.instrument.step.StepRegistryConfig; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Base tests for {@link StepRegistryProperties} implementation. - * - * @author Stephane Nicoll - */ -public abstract class StepRegistryPropertiesTest { - - protected void assertStepRegistryDefaultValues(StepRegistryProperties properties, - StepRegistryConfig config) { - assertThat(properties.getStep()).isEqualTo(config.step()); - assertThat(properties.isEnabled()).isEqualTo(config.enabled()); - assertThat(properties.getConnectTimeout()).isEqualTo(config.connectTimeout()); - assertThat(properties.getReadTimeout()).isEqualTo(config.readTimeout()); - assertThat(properties.getNumThreads()).isEqualTo(config.numThreads()); - assertThat(properties.getBatchSize()).isEqualTo(config.batchSize()); - } - - @Test - public abstract void defaultValuesAreConsistent(); - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverMetricsExportAutoConfigurationTests.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverMetricsExportAutoConfigurationTests.java deleted file mode 100644 index 2e0daba50f..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/export/stackdriver/StackdriverMetricsExportAutoConfigurationTests.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.export.stackdriver; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.stackdriver.StackdriverMeterRegistry; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link StackdriverMetricsExportAutoConfiguration}. - * - * @author Johnny Lim - */ -public class StackdriverMetricsExportAutoConfigurationTests { - - private final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - - @AfterEach - void cleanUp() { - context.close(); - } - - @Test - void autoConfigureByDefault() { - EnvironmentTestUtils.addEnvironment(context, - "management.metrics.export.stackdriver.project-id=my-project-id"); - - registerAndRefresh(); - - assertThat(context.getBean(StackdriverMeterRegistry.class)).isNotNull(); - } - - @Test - void autoConfigureDisabledByProperty() { - EnvironmentTestUtils.addEnvironment(context, - "management.metrics.export.stackdriver.project-id=my-project-id", - "management.metrics.export.stackdriver.enabled=false"); - - registerAndRefresh(); - - assertThatThrownBy(() -> context.getBean(StackdriverMeterRegistry.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - void injectedClockShouldBeUsed() { - EnvironmentTestUtils.addEnvironment(context, - "management.metrics.export.stackdriver.project-id=my-project-id"); - - registerAndRefresh(); - - StackdriverMeterRegistry meterRegistry = context.getBean(StackdriverMeterRegistry.class); - assertThat(meterRegistry).hasFieldOrPropertyWithValue("clock", context.getBean(Clock.class)); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length > 0) { - context.register(configurationClasses); - } - context.register(ClockConfiguration.class, StackdriverMetricsExportAutoConfiguration.class); - context.refresh(); - } - - @Configuration - static class ClockConfiguration { - - @Bean - public Clock clock() { - return mock(Clock.class); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/jdbc/DataSourcePoolMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/jdbc/DataSourcePoolMetricsAutoConfigurationTest.java deleted file mode 100644 index 7c9aadee77..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/jdbc/DataSourcePoolMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.jdbc; - -import javax.sql.DataSource; - -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link DataSourcePoolMetricsAutoConfiguration}. - * - * @author Johnny Lim - */ -class DataSourcePoolMetricsAutoConfigurationTest { - - private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (this.context != null) { - this.context.close(); - } - } - - @Test - void backsOffWhenMeterRegistryIsMissing() { - registerAndRefresh(DataSourceConfiguration.class, - DataSourcePoolMetricsAutoConfiguration.class); - - assertThatThrownBy(() -> this.context.getBean(DataSourcePoolMetricsAutoConfiguration.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - void backsOffWhenDataSourceIsMissing() { - registerAndRefresh(MeterRegistryConfiguration.class, - DataSourcePoolMetricsAutoConfiguration.class); - - assertThatThrownBy(() -> this.context.getBean(DataSourcePoolMetricsAutoConfiguration.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - void autoConfigurationKicksIn() { - registerAndRefresh(DataSourceConfiguration.class, MeterRegistryConfiguration.class, - DataSourcePoolMetricsAutoConfiguration.class); - - assertThat(this.context.getBean(DataSourcePoolMetricsAutoConfiguration.class)).isNotNull(); - } - - private void registerAndRefresh(Class... configurationClasses) { - this.context.register(configurationClasses); - this.context.refresh(); - } - - @Configuration - static class DataSourceConfiguration { - - @Bean - public DataSource dataSource() { - return mock(DataSource.class); - } - - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public MeterRegistry meterRegistry() { - return mock(MeterRegistry.class); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/jersey/JerseyServerMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/jersey/JerseyServerMetricsAutoConfigurationTest.java deleted file mode 100644 index 69e1e93b51..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/jersey/JerseyServerMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,190 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.jersey; - -import java.net.URI; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; - -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration; -import org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer; -import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration; -import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfiguration; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.RestTemplate; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.Timer; -import io.micrometer.jersey2.server.JerseyTagsProvider; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.export.simple.SimpleMetricsExportAutoConfiguration; -import org.glassfish.jersey.server.ResourceConfig; -import org.glassfish.jersey.server.monitoring.RequestEvent; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link JerseyServerMetricsAutoConfiguration}. - * - * @author Michael Weirauch - * @author Michael Simons - * @author Johnny Lim - */ -class JerseyServerMetricsAutoConfigurationTest { - - private final AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(); - - private final Class[] commonClasses = { - ResourceConfiguration.class, ServerPropertiesAutoConfiguration.class, - EmbeddedServletContainerAutoConfiguration.class, - JerseyAutoConfiguration.class, MetricsAutoConfiguration.class, - SimpleMetricsExportAutoConfiguration.class, - JerseyServerMetricsAutoConfiguration.class - }; - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - void shouldOnlyBeActiveInWebApplicationContext() { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - context.register(commonClasses); - context.refresh(); - - assertThatThrownBy(() -> context.getBean(ResourceConfigCustomizer.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - context.close(); - } - - @Test - void shouldProvideAllNecessaryBeans() { - registerAndRefresh(); - assertThat(context.getBean(JerseyTagsProvider.class)).isNotNull(); - assertThat(context.getBean(ResourceConfigCustomizer.class)).isNotNull(); - } - - @Test - void shouldHonorExistingTagProvider() { - registerAndRefresh(CustomJerseyTagsProviderConfiguration.class); - assertThat(context.getBean(JerseyTagsProvider.class)) - .isExactlyInstanceOf(CustomJerseyTagsProvider.class); - } - - @Test - void httpRequestsAreTimed() throws InterruptedException { - registerAndRefresh(); - doRequest(); - - // NOTE: An immediate fetching doesn't seem to work as meter collection for Jersey is event-driven. - TimeUnit.SECONDS.sleep(1); - - MeterRegistry registry = context.getBean(MeterRegistry.class); - Timer timer = registry.get("http.server.requests").tag("uri", "/users/{id}").timer(); - assertThat(timer.count()).isEqualTo(1); - } - - private void doRequest() { - int port = context.getEmbeddedServletContainer().getPort(); - RestTemplate restTemplate = new RestTemplate(); - restTemplate.getForEntity(URI.create("http://localhost:" + port + "/users/3"), String.class); - } - - private void registerAndRefresh(Class... configurationClasses) { - EnvironmentTestUtils.addEnvironment(context, "server.port=0"); - - List> classes = new ArrayList<>(); - Arrays.stream(configurationClasses).forEach(classes::add); - Arrays.stream(commonClasses).forEach(classes::add); - context.register(classes.toArray(new Class[0])); - context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public MeterRegistry meterRegistry() { - return mock(MeterRegistry.class); - } - - } - - @Configuration - static class ResourceConfiguration { - - @Bean - ResourceConfig resourceConfig() { - return new ResourceConfig().register(new TestResource()); - } - - @Path("/users") - public class TestResource { - - @GET - @Path("/{id}") - public String getUser(@PathParam("id") String id) { - return id; - } - - } - - } - - @Configuration - static class CustomJerseyTagsProviderConfiguration { - - @Bean - JerseyTagsProvider customJerseyTagsProvider() { - return new CustomJerseyTagsProvider(); - } - - } - - static class CustomJerseyTagsProvider implements JerseyTagsProvider { - - @Override - public Iterable httpRequestTags(RequestEvent event) { - return null; - } - - @Override - public Iterable httpLongRequestTags(RequestEvent event) { - return null; - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/kafka/consumer/KafkaMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/kafka/consumer/KafkaMetricsAutoConfigurationTest.java deleted file mode 100644 index 7f5aa32815..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/kafka/consumer/KafkaMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/** - * Copyright 2018 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.kafka.consumer; - -import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.kafka.KafkaConsumerMetrics; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link KafkaMetricsAutoConfiguration}. - */ -public class KafkaMetricsAutoConfigurationTest { - - private final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - public void whenThereIsNoMBeanServerAutoConfigurationBacksOff() { - registerAndRefresh(); - assertThat(context.getBeansOfType(KafkaConsumerMetrics.class)).isEmpty(); - } - - @Test - public void whenThereIsAnMBeanServerKafkaConsumerMetricsIsConfigured() { - registerAndRefresh(JmxAutoConfiguration.class); - assertThat(context.getBean(KafkaConsumerMetrics.class)).isNotNull(); - } - - @Test - public void allowsCustomKafkaConsumerMetricsToBeUsed() { - registerAndRefresh(JmxAutoConfiguration.class, CustomKafkaConsumerMetricsConfiguration.class); - assertThat(context.getBean(KafkaConsumerMetrics.class)).isEqualTo(context.getBean("customKafkaConsumerMetrics")); - } - - private void registerAndRefresh(Class... configurationClasses) { - if (configurationClasses.length != 0) { - this.context.register(configurationClasses); - } - this.context.register(MeterRegistryConfiguration.class, KafkaMetricsAutoConfiguration.class); - this.context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public MeterRegistry meterRegistry() { - return mock(MeterRegistry.class); - } - - } - - @Configuration - static class CustomKafkaConsumerMetricsConfiguration { - - @Bean - public KafkaConsumerMetrics customKafkaConsumerMetrics() { - return new KafkaConsumerMetrics(); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/orm/jpa/HibernateMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/orm/jpa/HibernateMetricsAutoConfigurationTest.java deleted file mode 100644 index f33115583b..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/orm/jpa/HibernateMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.orm.jpa; - -import io.micrometer.core.instrument.MeterRegistry; -import org.hibernate.SessionFactory; -import org.hibernate.stat.Statistics; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import javax.persistence.EntityManagerFactory; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -/** - * Tests for {@link HibernateMetricsAutoConfiguration}. - * - * @author Johnny Lim - */ -class HibernateMetricsAutoConfigurationTest { - - private AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); - - @AfterEach - void cleanUp() { - if (this.context != null) { - this.context.close(); - } - } - - @Test - void autoConfigureKicksIn() { - registerAndRefresh( - MeterRegistryConfiguration.class, - EntityManagerFactoryConfiguration.class, - HibernateMetricsAutoConfiguration.class); - assertThat(context.getBean(HibernateMetricsAutoConfiguration.class)).isNotNull(); - } - - @Test - void autoConfigureWhenMeterRegistryBeanIsNotPresentShouldBackOff() { - registerAndRefresh( - EntityManagerFactoryConfiguration.class, - HibernateMetricsAutoConfiguration.class); - assertThat(context.getBeansOfType(HibernateMetricsAutoConfiguration.class)).isEmpty(); - } - - @Test - void autoConfigureWhenEntityManagerFactoryBeanIsNotPresentShouldBackOff() { - registerAndRefresh( - MeterRegistryConfiguration.class, - HibernateMetricsAutoConfiguration.class); - assertThat(context.getBeansOfType(HibernateMetricsAutoConfiguration.class)).isEmpty(); - } - - private void registerAndRefresh(Class... configurationClasses) { - this.context.register(configurationClasses); - this.context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public MeterRegistry meterRegistry() { - return mock(MeterRegistry.class); - } - - } - - @Configuration - static class EntityManagerFactoryConfiguration { - - @Bean - public EntityManagerFactory entityManagerFactory() { - EntityManagerFactory entityManagerFactory = mock(EntityManagerFactory.class); - SessionFactory sessionFactory = mock(SessionFactory.class); - when(sessionFactory.getStatistics()).thenReturn(mock(Statistics.class)); - when(entityManagerFactory.unwrap(SessionFactory.class)).thenReturn(sessionFactory); - return entityManagerFactory; - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/TestController.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/TestController.java deleted file mode 100644 index e69a620bc0..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/TestController.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * Test controller used by metrics tests. - * - * @author Dmytro Nosan - * @author Stephane Nicoll - */ -@RestController -public class TestController { - - @GetMapping("test0") - public String test0() { - return "test0"; - } - - @GetMapping("test1") - public String test1() { - return "test1"; - } - - @GetMapping("test2") - public String test2() { - return "test2"; - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfigurationIntegrationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfigurationIntegrationTest.java deleted file mode 100644 index 81cdd4fddf..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfigurationIntegrationTest.java +++ /dev/null @@ -1,146 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web.client; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.spring.autoconfigure.MetricsProperties; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.context.embedded.LocalServerPort; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Import; -import org.springframework.core.task.SimpleAsyncTaskExecutor; -import org.springframework.http.ResponseEntity; -import org.springframework.http.client.SimpleClientHttpRequestFactory; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.util.concurrent.ListenableFuture; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.client.AsyncRestTemplate; -import org.springframework.web.client.RestTemplate; - -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.fail; - -/** - * Integration tests for {@link RestTemplateMetricsAutoConfiguration}. - * - * @author Jon Schneider - */ -@RunWith(SpringRunner.class) -@SpringBootTest(classes = RestTemplateMetricsAutoConfigurationIntegrationTest.ClientApp.class, webEnvironment = WebEnvironment.RANDOM_PORT) -@TestPropertySource(properties = { - "management.port=-1", // Disable the entire Spring Boot actuator, so that it does not get needlessly instrumented - "security.ignored=/**", -}) -@DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) -public class RestTemplateMetricsAutoConfigurationIntegrationTest { - @Autowired - private MeterRegistry registry; - - @Autowired - private MetricsProperties metricsProperties; - - @LocalServerPort - private int port; - - @Autowired - private RestTemplateBuilder restTemplateBuilder; - - @Autowired - private AsyncRestTemplate asyncClient; - - private String rootUri; - - private RestTemplate client; - - @Before - public void before() { - rootUri = "http://localhost:" + port; - client = restTemplateBuilder - .rootUri(rootUri) - .build(); - } - - @Test - public void restTemplatesCreatedWithBuilderAreInstrumented() { - client.getForObject("/it/1", String.class); - assertThat(registry.get("http.client.requests").meters()).hasSize(1); - } - - @Test - public void asyncRestTemplatesInContextAreInstrumented() throws Exception { - // therefore a full absolute URI is used - ListenableFuture> future = asyncClient.getForEntity(rootUri + "/it/2", String.class); - - final CountDownLatch latch = new CountDownLatch(1); - future.addCallback(result -> latch.countDown(), - result -> fail("should not have failed")); - - future.get(); - - latch.await(10, TimeUnit.SECONDS); - assertThat(registry.get("http.client.requests").timer().count()).isEqualTo(1); - } - - @Test - public void afterMaxUrisReachedFurtherUrisAreDenied() { - int maxUriTags = metricsProperties.getWeb().getClient().getMaxUriTags(); - for (int i = 0; i < maxUriTags + 10; i++) { - client.getForObject("/it/" + i, String.class); - } - - assertThat(registry.get("http.client.requests").meters()).hasSize(maxUriTags); - } - - @SpringBootApplication(scanBasePackages = "ignore") - @Import(SampleController.class) - static class ClientApp { - @Bean - public MeterRegistry registry() { - return new SimpleMeterRegistry(); - } - - @Bean - public AsyncRestTemplate asyncRestTemplate() { - final SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); - requestFactory.setTaskExecutor(new SimpleAsyncTaskExecutor()); - return new AsyncRestTemplate(requestFactory); - } - } - - @RestController - static class SampleController { - @GetMapping("/it/{id}") - public String it(@PathVariable String id) { - return id; - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfigurationTest.java deleted file mode 100644 index 5ed6f195c6..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/client/RestTemplateMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web.client; - -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.spring.autoconfigure.MetricsProperties; -import io.micrometer.spring.web.client.DefaultRestTemplateExchangeTagsProvider; -import io.micrometer.spring.web.client.MetricsRestTemplateCustomizer; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link RestTemplateMetricsAutoConfiguration}. - * - * @author Raheela Aslam - * @author Johnny Lim - */ -class RestTemplateMetricsAutoConfigurationTest { - - private final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - void autoConfigureWorks() { - registerAndRefresh( - MetricsPropertiesConfiguration.class, - MeterRegistryConfiguration.class, - RestTemplateBuilderConfiguration.class, - RestTemplateMetricsAutoConfiguration.class); - assertThat(context.getBean(DefaultRestTemplateExchangeTagsProvider.class)).isNotNull(); - assertThat(context.getBean(MetricsRestTemplateCustomizer.class)).isNotNull(); - } - - @Test - void backsOffWhenRestTemplateBuilderIsMissing() { - registerAndRefresh( - MetricsPropertiesConfiguration.class, - MeterRegistryConfiguration.class, - RestTemplateMetricsAutoConfiguration.class); - assertThat(context.getBeansOfType(DefaultRestTemplateExchangeTagsProvider.class)).isEmpty(); - assertThat(context.getBeansOfType(MetricsRestTemplateCustomizer.class)).isEmpty(); - } - - private void registerAndRefresh(Class... configurationClasses) { - context.register(configurationClasses); - context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public SimpleMeterRegistry meterRegistry() { - return new SimpleMeterRegistry(); - } - - } - - @Configuration - @EnableConfigurationProperties(MetricsProperties.class) - static class MetricsPropertiesConfiguration { - } - - @Configuration - static class RestTemplateBuilderConfiguration { - - @Bean - public RestTemplateBuilder restTemplateBuilder() { - return new RestTemplateBuilder(); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/jetty/JettyMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/jetty/JettyMetricsAutoConfigurationTest.java deleted file mode 100644 index 3702128883..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/jetty/JettyMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web.jetty; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.spring.web.jetty.JettyServerThreadPoolMetricsBinder; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link JettyMetricsAutoConfiguration}. - * - * @author Johnny Lim - * @author Andy Wilkinson - */ -class JettyMetricsAutoConfigurationTest { - - private final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - public void autoConfiguresThreadPoolMetricsWithEmbeddedServletJetty() { - AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(); - context.register(MeterRegistryConfiguration.class, ServletWebServerConfiguration.class, - JettyMetricsAutoConfiguration.class); - context.refresh(); - - context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), null, context)); - assertThat(context.getBean(JettyServerThreadPoolMetricsBinder.class)).isNotNull(); - SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class); - assertThat(registry.find("jetty.threads.config.min").meter()).isNotNull(); - - context.close(); - } - - @Test - public void allowsCustomJettyServerThreadPoolMetricsBinderToBeUsed() { - registerAndRefresh(MeterRegistryConfiguration.class, - CustomJettyServerThreadPoolMetricsBinder.class, - JettyMetricsAutoConfiguration.class); - assertThat(context.getBean(JettyServerThreadPoolMetricsBinder.class)) - .isEqualTo(context.getBean("customJettyServerThreadPoolMetricsBinder")); - } - - private void registerAndRefresh(Class... configurationClasses) { - context.register(configurationClasses); - context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public SimpleMeterRegistry meterRegistry() { - return new SimpleMeterRegistry(); - } - - } - - @Configuration - static class ServletWebServerConfiguration { - - @Bean - public JettyEmbeddedServletContainerFactory jettyFactory() { - return new JettyEmbeddedServletContainerFactory(0); - } - - } - - @Configuration - static class CustomJettyServerThreadPoolMetricsBinder { - - @Bean - public JettyServerThreadPoolMetricsBinder customJettyServerThreadPoolMetricsBinder( - MeterRegistry meterRegistry) { - return new JettyServerThreadPoolMetricsBinder(meterRegistry); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/servlet/WebMvcMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/servlet/WebMvcMetricsAutoConfigurationTest.java deleted file mode 100644 index 58de184435..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/servlet/WebMvcMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,177 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web.servlet; - -import java.util.Collections; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration; -import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; -import org.springframework.boot.test.util.EnvironmentTestUtils; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.mock.web.MockServletContext; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.spring.autoconfigure.MetricsAutoConfiguration; -import io.micrometer.spring.autoconfigure.web.TestController; -import io.micrometer.spring.web.servlet.DefaultWebMvcTagsProvider; -import io.micrometer.spring.web.servlet.WebMvcMetricsFilter; -import io.micrometer.spring.web.servlet.WebMvcTagsProvider; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * Tests for {@link WebMvcMetricsAutoConfiguration}. - * - * @author Andy Wilkinson - * @author Johnny Lim - * @author Dmytro Nosan - */ -class WebMvcMetricsAutoConfigurationTest { - - private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - - @AfterEach - void cleanUp() { - if (this.context != null) { - this.context.close(); - } - } - - @Test - void backsOffWhenMeterRegistryIsMissing() { - registerAndRefresh(WebMvcMetricsAutoConfiguration.class); - - assertThatThrownBy(() -> this.context.getBean(WebMvcMetricsAutoConfiguration.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - } - - @Test - public void definesTagsProviderAndFilterWhenMeterRegistryIsPresent() { - registerAndRefresh(MeterRegistryConfiguration.class, WebMvcMetricsAutoConfiguration.class); - - assertThat(this.context.getBean(DefaultWebMvcTagsProvider.class)).isNotNull(); - assertThat(this.context.getBean(WebMvcMetricsFilter.class)).isNotNull(); - } - - @Test - public void tagsProviderBacksOff() { - registerAndRefresh(MeterRegistryConfiguration.class, TagsProviderConfiguration.class, - WebMvcMetricsAutoConfiguration.class); - - assertThatThrownBy(() -> this.context.getBean(DefaultWebMvcTagsProvider.class)) - .isInstanceOf(NoSuchBeanDefinitionException.class); - assertThat(this.context.getBean(TestWebMvcTagsProvider.class)).isNotNull(); - } - - @Test - public void afterMaxUrisReachedFurtherUrisAreDenied() throws Exception { - this.context.setServletContext(new MockServletContext()); - - EnvironmentTestUtils.addEnvironment(this.context, "management.metrics.web.server.max-uri-tags=2"); - - registerAndRefresh(MeterRegistryConfiguration.class, TestController.class, - HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class, - MetricsAutoConfiguration.class, WebMvcMetricsAutoConfiguration.class); - - WebMvcMetricsFilter filter = this.context.getBean(WebMvcMetricsFilter.class); - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).addFilters(filter) - .build(); - for (int i = 0; i < 3; i++) { - mockMvc.perform(get("/test" + i)) - .andExpect(status().isOk()); - } - - MeterRegistry registry = this.context.getBean(MeterRegistry.class); - assertThat(registry.get("http.server.requests").meters()).hasSize(2); - } - - @Test - public void shouldNotDenyIfMaxUrisIsNotReached() throws Exception { - this.context.setServletContext(new MockServletContext()); - - EnvironmentTestUtils.addEnvironment(this.context, "management.metrics.web.server.max-uri-tags=5"); - - registerAndRefresh(MeterRegistryConfiguration.class, TestController.class, - HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class, - MetricsAutoConfiguration.class, WebMvcMetricsAutoConfiguration.class); - - WebMvcMetricsFilter filter = this.context.getBean(WebMvcMetricsFilter.class); - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).addFilters(filter) - .build(); - for (int i = 0; i < 3; i++) { - mockMvc.perform(get("/test" + i)) - .andExpect(status().isOk()); - } - - MeterRegistry registry = this.context.getBean(MeterRegistry.class); - assertThat(registry.get("http.server.requests").meters()).hasSize(3); - } - - private void registerAndRefresh(Class... configurationClasses) { - this.context.register(configurationClasses); - this.context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public MeterRegistry meterRegistry() { - return new SimpleMeterRegistry(); - } - - } - - @Configuration - static class TagsProviderConfiguration { - - @Bean - public TestWebMvcTagsProvider tagsProvider() { - return new TestWebMvcTagsProvider(); - } - - } - - private static final class TestWebMvcTagsProvider implements WebMvcTagsProvider { - - @Override - public Iterable httpLongRequestTags(HttpServletRequest request, Object handler) { - return Collections.emptyList(); - } - - @Override - public Iterable httpRequestTags(HttpServletRequest request, HttpServletResponse response, Object handler, Throwable ex) { - return Collections.emptyList(); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/tomcat/TomcatMetricsAutoConfigurationTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/tomcat/TomcatMetricsAutoConfigurationTest.java deleted file mode 100644 index 9dd4eab77a..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/autoconfigure/web/tomcat/TomcatMetricsAutoConfigurationTest.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.autoconfigure.web.tomcat; - -import java.util.Collections; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext; -import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; -import org.springframework.boot.context.event.ApplicationReadyEvent; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.tomcat.TomcatMetrics; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.spring.web.tomcat.TomcatMetricsBinder; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link TomcatMetricsAutoConfiguration}. - * - * @author Andy Wilkinson - * @author Johnny Lim - */ -class TomcatMetricsAutoConfigurationTest { - - private final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); - - @AfterEach - void cleanUp() { - if (context != null) { - context.close(); - } - } - - @Test - void autoConfiguresTomcatMetricsWithEmbeddedServletTomcat() { - AnnotationConfigEmbeddedWebApplicationContext context = new AnnotationConfigEmbeddedWebApplicationContext(); - context.register(MeterRegistryConfiguration.class, ServletWebServerConfiguration.class, - TomcatMetricsAutoConfiguration.class); - context.refresh(); - - context.publishEvent(new ApplicationReadyEvent(new SpringApplication(), null, context)); - assertThat(context.getBean(TomcatMetricsBinder.class)).isNotNull(); - SimpleMeterRegistry registry = context.getBean(SimpleMeterRegistry.class); - assertThat(registry.find("tomcat.sessions.active.max").meter()).isNotNull(); - assertThat(registry.find("tomcat.threads.current").meter()).isNotNull(); - - context.close(); - } - - @Test - void autoConfiguresTomcatMetricsWithStandaloneTomcat() { - registerAndRefresh(MeterRegistryConfiguration.class, TomcatMetricsAutoConfiguration.class); - assertThat(context.getBean(TomcatMetricsBinder.class)).isNotNull(); - } - - @Test - void allowsCustomTomcatMetricsBinderToBeUsed() { - registerAndRefresh(MeterRegistryConfiguration.class, CustomTomcatMetricsBinder.class, - TomcatMetricsAutoConfiguration.class); - assertThat(context.getBean(TomcatMetricsBinder.class)) - .isEqualTo(context.getBean("customTomcatMetricsBinder")); - } - - @Test - void allowsCustomTomcatMetricsToBeUsed() { - registerAndRefresh(MeterRegistryConfiguration.class, CustomTomcatMetrics.class, - TomcatMetricsAutoConfiguration.class); - assertThat(context.getBean(TomcatMetrics.class)) - .isEqualTo(context.getBean("customTomcatMetrics")); - } - - private void registerAndRefresh(Class... configurationClasses) { - context.register(configurationClasses); - context.refresh(); - } - - @Configuration - static class MeterRegistryConfiguration { - - @Bean - public SimpleMeterRegistry meterRegistry() { - return new SimpleMeterRegistry(); - } - - } - - @Configuration - static class ServletWebServerConfiguration { - - @Bean - public TomcatEmbeddedServletContainerFactory tomcatFactory() { - return new TomcatEmbeddedServletContainerFactory(0); - } - - } - - @Configuration - static class CustomTomcatMetrics { - - @Bean - public TomcatMetrics customTomcatMetrics() { - return new TomcatMetrics(null, Collections.emptyList()); - } - - } - - @Configuration - static class CustomTomcatMetricsBinder { - - @Bean - public TomcatMetricsBinder customTomcatMetricsBinder(MeterRegistry meterRegistry) { - return new TomcatMetricsBinder(meterRegistry); - } - - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/cache/ConcurrentMapCacheMetricsCompatibilityTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/cache/ConcurrentMapCacheMetricsCompatibilityTest.java deleted file mode 100644 index d9ed2fb1cc..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/cache/ConcurrentMapCacheMetricsCompatibilityTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.cache; - -import io.micrometer.core.instrument.binder.cache.CacheMeterBinder; -import io.micrometer.core.instrument.binder.cache.CacheMeterBinderCompatibilityKit; -import io.micrometer.core.lang.Nullable; -import org.springframework.cache.Cache; -import org.springframework.cache.concurrent.ConcurrentMapCache; - -import static java.util.Collections.emptyList; - -public class ConcurrentMapCacheMetricsCompatibilityTest extends CacheMeterBinderCompatibilityKit { - @Nullable - private ConcurrentMapCache cache; - - @Override - public CacheMeterBinder binder() { - ConcurrentMapCacheMetrics binder = new ConcurrentMapCacheMetrics(new ConcurrentMapCache("mycache"), emptyList()); - this.cache = binder.getMonitoredCache(); - return binder; - } - - @Override - public void put(String key, String value) { - cache.put(key, value); - } - - @Override - public String get(String key) { - Cache.ValueWrapper valueWrapper = cache.get(key); - return valueWrapper == null ? null : (String) valueWrapper.get(); - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/export/prometheus/PrometheusPushGatewayManagerTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/export/prometheus/PrometheusPushGatewayManagerTest.java deleted file mode 100644 index 34d6892896..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/export/prometheus/PrometheusPushGatewayManagerTest.java +++ /dev/null @@ -1,214 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.export.prometheus; - -import java.net.UnknownHostException; -import java.time.Duration; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ScheduledFuture; - -import org.springframework.scheduling.TaskScheduler; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; - -import io.micrometer.spring.export.prometheus.PrometheusPushGatewayManager.PushGatewayTaskScheduler; -import io.micrometer.spring.export.prometheus.PrometheusPushGatewayManager.ShutdownOperation; -import io.prometheus.client.CollectorRegistry; -import io.prometheus.client.exporter.PushGateway; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Matchers.eq; -import static org.mockito.Matchers.isA; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; - -/** - * Tests for {@link PrometheusPushGatewayManager}. - * - * @author Phillip Webb - */ -class PrometheusPushGatewayManagerTest { - - @Mock - private PushGateway pushGateway; - - @Mock - private CollectorRegistry registry; - - private TaskScheduler scheduler; - - private Duration pushRate = Duration.ofSeconds(1); - - private Map groupingKey = Collections.singletonMap("foo", "bar"); - - @Captor - private ArgumentCaptor task; - - @Mock - private ScheduledFuture future; - - @BeforeEach - public void setup() { - MockitoAnnotations.initMocks(this); - this.scheduler = mockScheduler(TaskScheduler.class); - } - - @Test - void createWhenPushGatewayIsNullThrowsException() { - assertThatIllegalArgumentException() - .isThrownBy(() -> new PrometheusPushGatewayManager(null, this.registry, - this.scheduler, this.pushRate, "job", this.groupingKey, null)) - .withMessage("PushGateway must not be null"); - } - - @Test - void createWhenCollectorRegistryIsNullThrowsException() { - assertThatIllegalArgumentException() - .isThrownBy(() -> new PrometheusPushGatewayManager(this.pushGateway, null, - this.scheduler, this.pushRate, "job", this.groupingKey, null)) - .withMessage("Registry must not be null"); - } - - @Test - void createWhenSchedulerIsNullThrowsException() { - assertThatIllegalArgumentException().isThrownBy( - () -> new PrometheusPushGatewayManager(this.pushGateway, this.registry, - null, this.pushRate, "job", this.groupingKey, null)) - .withMessage("Scheduler must not be null"); - } - - @Test - void createWhenPushRateIsNullThrowsException() { - assertThatIllegalArgumentException().isThrownBy( - () -> new PrometheusPushGatewayManager(this.pushGateway, this.registry, - this.scheduler, null, "job", this.groupingKey, null)) - .withMessage("PushRate must not be null"); - } - - @Test - void createWhenJobIsEmptyThrowsException() { - assertThatIllegalArgumentException().isThrownBy( - () -> new PrometheusPushGatewayManager(this.pushGateway, this.registry, - this.scheduler, this.pushRate, "", this.groupingKey, null)) - .withMessage("Job must not be empty"); - } - - @Test - void createShouldSchedulePushAsFixedRate() throws Exception { - new PrometheusPushGatewayManager(this.pushGateway, this.registry, this.scheduler, - this.pushRate, "job", this.groupingKey, null); - verify(this.scheduler).scheduleAtFixedRate(this.task.capture(), - eq(this.pushRate.toMillis())); - this.task.getValue().run(); - verify(this.pushGateway).pushAdd(this.registry, "job", this.groupingKey); - } - - @Test - void shutdownWhenOwnsSchedulerDoesShutdownScheduler() { - PushGatewayTaskScheduler ownedScheduler = mockScheduler( - PushGatewayTaskScheduler.class); - PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager( - this.pushGateway, this.registry, ownedScheduler, this.pushRate, "job", - this.groupingKey, null); - manager.shutdown(); - verify(ownedScheduler).shutdown(); - } - - @Test - void shutdownWhenDoesNotOwnSchedulerDoesNotShutdownScheduler() { - ThreadPoolTaskScheduler otherScheduler = mockScheduler( - ThreadPoolTaskScheduler.class); - PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager( - this.pushGateway, this.registry, otherScheduler, this.pushRate, "job", - this.groupingKey, null); - manager.shutdown(); - verify(otherScheduler, never()).shutdown(); - } - - @Test - void shutdownWhenShutdownOperationIsPushPerformsPushOnShutdown() - throws Exception { - PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager( - this.pushGateway, this.registry, this.scheduler, this.pushRate, "job", - this.groupingKey, ShutdownOperation.PUSH); - manager.shutdown(); - verify(this.future).cancel(false); - verify(this.pushGateway).pushAdd(this.registry, "job", this.groupingKey); - } - - @Test - void shutdownWhenShutdownOperationIsDeletePerformsDeleteOnShutdown() - throws Exception { - PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager( - this.pushGateway, this.registry, this.scheduler, this.pushRate, "job", - this.groupingKey, ShutdownOperation.DELETE); - manager.shutdown(); - verify(this.future).cancel(false); - verify(this.pushGateway).delete("job", this.groupingKey); - } - - @Test - void shutdownWhenShutdownOperationIsNoneDoesNothing() { - PrometheusPushGatewayManager manager = new PrometheusPushGatewayManager( - this.pushGateway, this.registry, this.scheduler, this.pushRate, "job", - this.groupingKey, PrometheusPushGatewayManager.ShutdownOperation.NONE); - manager.shutdown(); - verify(this.future).cancel(false); - verifyZeroInteractions(this.pushGateway); - } - - @Test - void pushWhenUnknownHostExceptionIsThrownDoesShutdown() throws Exception { - new PrometheusPushGatewayManager(this.pushGateway, this.registry, this.scheduler, - this.pushRate, "job", this.groupingKey, null); - verify(this.scheduler).scheduleAtFixedRate(this.task.capture(), - eq(this.pushRate.toMillis())); - willThrow(new UnknownHostException("foo")).given(this.pushGateway) - .pushAdd(this.registry, "job", this.groupingKey); - this.task.getValue().run(); - verify(this.future).cancel(false); - } - - @Test - void pushDoesNotThrowException() throws Exception { - new PrometheusPushGatewayManager(this.pushGateway, this.registry, this.scheduler, - this.pushRate, "job", this.groupingKey, null); - verify(this.scheduler).scheduleAtFixedRate(this.task.capture(), - eq(this.pushRate.toMillis())); - willThrow(RuntimeException.class).given(this.pushGateway).pushAdd(this.registry, - "job", this.groupingKey); - this.task.getValue().run(); - } - - @SuppressWarnings({ "unchecked", "rawtypes" }) - private T mockScheduler(Class type) { - T scheduler = mock(type); - given(scheduler.scheduleAtFixedRate(isA(Runnable.class), isA(Long.class))) - .willReturn((ScheduledFuture) this.future); - return scheduler; - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/integration/SpringIntegrationMetricsTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/integration/SpringIntegrationMetricsTest.java deleted file mode 100644 index a80cb19ae4..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/integration/SpringIntegrationMetricsTest.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.integration; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.MockClock; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.integration.annotation.Gateway; -import org.springframework.integration.annotation.IntegrationComponentScan; -import org.springframework.integration.annotation.MessagingGateway; -import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.support.Transformers; -import org.springframework.integration.ws.SimpleWebServiceOutboundGateway; -import org.springframework.integration.ws.WebServiceHeaders; -import org.springframework.test.context.junit4.SpringRunner; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest -public class SpringIntegrationMetricsTest { - - @Autowired - private TestSpringIntegrationApplication.TempConverter converter; - - @Autowired - private MeterRegistry registry; - - @Test - public void springIntegrationMetrics() { - converter.fahrenheitToCelcius(68.0f); - - assertThat(registry.get("spring.integration.channel.sends") - .tags("channel", "convert.input").functionCounter().count()).isEqualTo(1.0); - registry.get("spring.integration.handler.duration.min").meter(); - registry.get("spring.integration.sourceNames").meter(); - } - - @SpringBootApplication - @IntegrationComponentScan - public static class TestSpringIntegrationApplication { - @Bean - MockClock clock() { - return new MockClock(); - } - - @Bean - public IntegrationFlow convert() { - return f -> f - .transform(payload -> - "" - + "" + payload + "" - + "", e -> e.id("toXml")) - .enrichHeaders(h -> h - .header(WebServiceHeaders.SOAP_ACTION, - "https://www.w3schools.com/xml/FahrenheitToCelsius")) - .handle(new SimpleWebServiceOutboundGateway( - "https://www.w3schools.com/xml/tempconvert.asmx"), e -> e.id("w3schools")) - .transform(Transformers.xpath("/*[local-name()=\"FahrenheitToCelsiusResponse\"]" - + "/*[local-name()=\"FahrenheitToCelsiusResult\"]"), e -> e.id("toResponse")); - } - - @MessagingGateway - public interface TempConverter { - @Gateway(requestChannel = "convert.input") - float fahrenheitToCelcius(float fahren); - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/jdbc/DataSourcePoolMetricsHikariTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/jdbc/DataSourcePoolMetricsHikariTest.java deleted file mode 100644 index ad124c6daa..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/jdbc/DataSourcePoolMetricsHikariTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.jdbc; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.sql.DataSource; -import java.util.Collection; - -import static java.util.Collections.emptyList; - -/** - * @author Arthur Gavlyukovskiy - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(properties = { - "spring.datasource.generate-unique-name=true", - "management.security.enabled=false", - "spring.datasource.type=com.zaxxer.hikari.HikariDataSource" -}) -public class DataSourcePoolMetricsHikariTest { - - @Autowired - private MeterRegistry registry; - - @Test - public void dataSourceIsInstrumented() { - registry.get("data.source.connections.active").meter(); - } - - @SpringBootApplication(scanBasePackages = "isolated") - @Import(DataSourceConfig.class) - static class MetricsApp { - @Bean - MeterRegistry registry() { - return new SimpleMeterRegistry(); - } - } - - @Configuration - static class DataSourceConfig { - public DataSourceConfig(DataSource dataSource, - Collection metadataProviders, - MeterRegistry registry) { - new DataSourcePoolMetrics( - dataSource, - metadataProviders, - "data.source", - emptyList()).bindTo(registry); - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/jdbc/DataSourcePoolMetricsTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/jdbc/DataSourcePoolMetricsTest.java deleted file mode 100644 index 7aaf53d20e..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/jdbc/DataSourcePoolMetricsTest.java +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.jdbc; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.metadata.DataSourcePoolMetadataProvider; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.sql.DataSource; -import java.sql.SQLException; -import java.util.Collection; - -import static java.util.Collections.emptyList; - -/** - * @author Jon Schneider - */ -@RunWith(SpringRunner.class) -@SpringBootTest -@TestPropertySource(properties = { - "spring.datasource.generate-unique-name=true", - "management.security.enabled=false", - "spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource" -}) -public class DataSourcePoolMetricsTest { - - @Autowired - private DataSource dataSource; - - @Autowired - private MeterRegistry registry; - - @Test - public void dataSourceIsInstrumented() throws SQLException { - dataSource.getConnection().getMetaData(); - registry.find("data.source.connections.max").meter(); - } - - @SpringBootApplication(scanBasePackages = "isolated") - @Import(DataSourceConfig.class) - static class MetricsApp { - @Bean - MeterRegistry registry() { - return new SimpleMeterRegistry(); - } - } - - @Configuration - static class DataSourceConfig { - public DataSourceConfig(DataSource dataSource, - Collection metadataProviders, - MeterRegistry registry) { - new DataSourcePoolMetrics( - dataSource, - metadataProviders, - "data.source", - emptyList()).bindTo(registry); - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/scheduling/ExecutorServiceMetricsTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/scheduling/ExecutorServiceMetricsTest.java deleted file mode 100644 index a392335e11..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/scheduling/ExecutorServiceMetricsTest.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.scheduling; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.binder.jvm.ExecutorServiceMetrics; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Test; -import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; - -/** - * @author Jon Schneider - * @author Clint Checketts - */ -public class ExecutorServiceMetricsTest { - private MeterRegistry registry = new SimpleMeterRegistry(); - - @Test - public void threadPoolTaskExecutor() { - ThreadPoolTaskExecutor exec = new ThreadPoolTaskExecutor(); - exec.initialize(); - - ExecutorServiceMetrics.monitor(registry, exec.getThreadPoolExecutor(), "exec"); - assertThreadPoolExecutorMetrics("exec"); - } - - @Test - public void taskScheduler() { - ThreadPoolTaskScheduler sched = new ThreadPoolTaskScheduler(); - sched.initialize(); - - ExecutorServiceMetrics.monitor(registry, sched.getScheduledExecutor(), "sched"); - assertThreadPoolExecutorMetrics("sched"); - } - - private void assertThreadPoolExecutorMetrics(String name) { - registry.get("executor.completed").tag("name", name).meter(); - registry.get("executor.queued").tag("name", name).gauge(); - registry.get("executor.pool.size").tag("name", name).gauge(); - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/scheduling/ScheduledMethodMetricsTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/scheduling/ScheduledMethodMetricsTest.java deleted file mode 100644 index 7f1c6c3f08..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/scheduling/ScheduledMethodMetricsTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.scheduling; - -import io.micrometer.core.annotation.Timed; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.scheduling.annotation.EnableScheduling; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.concurrent.CountDownLatch; - -import static org.assertj.core.api.Assertions.assertThat; - -@RunWith(SpringRunner.class) -@SpringBootTest -@Ignore("Race condition still...") -public class ScheduledMethodMetricsTest { - - static CountDownLatch longTaskStarted = new CountDownLatch(1); - static CountDownLatch longTaskShouldComplete = new CountDownLatch(1); - - static CountDownLatch shortBeepsExecuted = new CountDownLatch(1); - - @Autowired - private MeterRegistry registry; - - @Autowired - private ThreadPoolTaskScheduler scheduler; - - @Test - public void shortTasksAreInstrumented() throws InterruptedException { - shortBeepsExecuted.await(); - while (scheduler.getActiveCount() > 0) { - } - - assertThat(registry.get("beeper").timer().count()).isEqualTo(1L); - registry.get("beeper").tags("percentile", "50").gauge(); - registry.get("beeper").tags("percentile", "95").gauge(); - } - - @Test - public void longTasksAreInstrumented() throws InterruptedException { - longTaskStarted.await(); - - assertThat(registry.get("long.beep").longTaskTimer().activeTasks()).isEqualTo(1); - - // make sure longBeep continues running until we have a chance to observe it in the active state - longTaskShouldComplete.countDown(); - while (scheduler.getActiveCount() > 0) { - } - - Thread.sleep(10); - - assertThat(registry.get("long.beep").longTaskTimer().activeTasks()).isEqualTo(0); - } - - @SpringBootApplication - @EnableScheduling - static class MetricsApp { - @Bean - MeterRegistry registry() { - return new SimpleMeterRegistry(); - } - - @Bean - ThreadPoolTaskScheduler scheduler() { - ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); - // this way, executing longBeep doesn't block the short tasks from running - scheduler.setPoolSize(6); - return scheduler; - } - - @Timed(value = "long.beep", longTask = true) - @Scheduled(fixedDelay = 100_000) - void longBeep() throws InterruptedException { - longTaskStarted.countDown(); - longTaskShouldComplete.await(); - System.out.println("beep"); - } - - @Timed(value = "beeper", percentiles = {0.50, 0.95}) - @Scheduled(fixedDelay = 100_000) - void shortBeep() { - shortBeepsExecuted.countDown(); - System.out.println("beep"); - } - - @Timed // not instrumented because @Timed lacks a metric name - @Scheduled(fixedDelay = 100_000) - void noMetricName() { - System.out.println("beep"); - } - - @Scheduled(fixedDelay = 100_000) - // not instrumented because it isn't @Timed - void notTimed() { - System.out.println("beep"); - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/security/SpringSecurityTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/security/SpringSecurityTest.java deleted file mode 100644 index 4f739a0239..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/security/SpringSecurityTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.security; - -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Import; -import org.springframework.security.test.context.support.WithMockUser; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(SpringRunner.class) -@SpringBootTest -@AutoConfigureMockMvc -@TestPropertySource(properties = { - // changed to spring.security.* in Boot 2 - "security.user.password=foo" -}) -public class SpringSecurityTest { - - @Autowired - private MockMvc mvc; - - @Autowired - private MeterRegistry registry; - - @Test - @WithMockUser - public void securityAllowsAccess() throws Exception { - mvc.perform(get("/api/secured")).andExpect(status().isOk()); - - registry.get("http.server.requests") - .tags("status", "200") - .timer(); - } - - @Test - public void securityBlocksAccess() throws Exception { - mvc.perform(get("/api/secured")).andExpect(status().isUnauthorized()); - - registry.get("http.server.requests") - .tags("status", "401") - .timer(); - } - - @SpringBootApplication(scanBasePackages = "ignore") - @Import(Controller.class) - static class SecurityApp { - @Bean - public MeterRegistry registry() { - return new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock()); - } - } - - @RestController - static class Controller { - @GetMapping("/api/secured") - public String secured() { - return "got in"; - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/DefaultRestTemplateExchangeTagsProviderTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/DefaultRestTemplateExchangeTagsProviderTest.java deleted file mode 100644 index 0171fa4678..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/DefaultRestTemplateExchangeTagsProviderTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.client; - -import io.micrometer.core.instrument.Tag; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.http.HttpMethod; -import org.springframework.http.HttpStatus; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.mock.http.client.MockClientHttpRequest; -import org.springframework.mock.http.client.MockClientHttpResponse; - -import java.io.IOException; -import java.net.URI; -import java.net.URISyntaxException; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - -@RunWith(MockitoJUnitRunner.class) -public class DefaultRestTemplateExchangeTagsProviderTest { - - private DefaultRestTemplateExchangeTagsProvider tagsProvider = new DefaultRestTemplateExchangeTagsProvider(); - - private MockClientHttpRequest httpRequest = new MockClientHttpRequest(); - private ClientHttpResponse httpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.OK); - - @Before - public void before() throws URISyntaxException { - httpRequest.setMethod(HttpMethod.GET); - httpRequest.setURI(new URI("http://localhost/test/123")); - } - - @Test - public void uriTagSetFromUriTemplate() { - Iterable tags = tagsProvider.getTags("/test/{id}", httpRequest, httpResponse); - - assertThat(tags).contains(Tag.of("uri", "/test/{id}")); - } - - @Test - public void uriTagSetFromRequestWhenNoUriTemplate() { - Iterable tags = tagsProvider.getTags(null, httpRequest, httpResponse); - - assertThat(tags).contains(Tag.of("uri", "/test/123")); - } - - @Test - public void uriTagSetFromRequestWhenUriTemplateIsBlank() { - Iterable tags = tagsProvider.getTags(" ", httpRequest, httpResponse); - - assertThat(tags).contains(Tag.of("uri", "/test/123")); - } - - @Test - public void outcomeTagInformational() { - httpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.CONTINUE); - Iterable tags = tagsProvider.getTags(" ", httpRequest, httpResponse); - - assertThat(tags).contains(Tag.of("outcome", "INFORMATIONAL")); - } - - @Test - public void outcomeTagSuccess() { - httpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.OK); - Iterable tags = tagsProvider.getTags(" ", httpRequest, httpResponse); - - assertThat(tags).contains(Tag.of("outcome", "SUCCESS")); - } - - @Test - public void outcomeTagRedirection() { - httpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.PERMANENT_REDIRECT); - Iterable tags = tagsProvider.getTags(" ", httpRequest, httpResponse); - - assertThat(tags).contains(Tag.of("outcome", "REDIRECTION")); - } - - @Test - public void outcomeTagClientError() { - httpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.BAD_REQUEST); - Iterable tags = tagsProvider.getTags(" ", httpRequest, httpResponse); - - assertThat(tags).contains(Tag.of("outcome", "CLIENT_ERROR")); - } - - @Test - public void outcomeTagServerError() { - httpResponse = new MockClientHttpResponse(new byte[]{}, HttpStatus.INTERNAL_SERVER_ERROR); - Iterable tags = tagsProvider.getTags(" ", httpRequest, httpResponse); - - assertThat(tags).contains(Tag.of("outcome", "SERVER_ERROR")); - } - - @Test - public void outcomeTagUnknownStatusCode() throws IOException { - ClientHttpResponse clientHttpResponse = Mockito.mock(ClientHttpResponse.class); - when(clientHttpResponse.getStatusCode()).thenThrow(new IllegalArgumentException()); - - Iterable tags = tagsProvider.getTags(" ", httpRequest, clientHttpResponse); - - assertThat(tags).contains(Tag.of("outcome", "UNKNOWN")); - } - - @Test - public void outcomeTagIOException() throws IOException { - ClientHttpResponse clientHttpResponse = Mockito.mock(ClientHttpResponse.class); - when(clientHttpResponse.getStatusCode()).thenThrow(new IOException()); - - Iterable tags = tagsProvider.getTags(" ", httpRequest, clientHttpResponse); - - assertThat(tags).contains(Tag.of("outcome", "UNKNOWN")); - } - - @Test - public void outcomeTagNullResponse() { - Iterable tags = tagsProvider.getTags(" ", httpRequest, null); - - assertThat(tags).contains(Tag.of("outcome", "UNKNOWN")); - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/MetricsRestTemplateCustomizerTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/MetricsRestTemplateCustomizerTest.java deleted file mode 100644 index ee8499afb5..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/MetricsRestTemplateCustomizerTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.client; - -import io.micrometer.core.Issue; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.Tag; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import org.junit.Before; -import org.junit.Test; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.test.web.client.MockRestServiceServer; -import org.springframework.test.web.client.match.MockRestRequestMatchers; -import org.springframework.test.web.client.response.MockRestResponseCreators; -import org.springframework.web.client.RestTemplate; - -import java.net.URI; -import java.net.URISyntaxException; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link MetricsRestTemplateCustomizer}. - * - * @author Jon Schneider - */ -public class MetricsRestTemplateCustomizerTest { - - private MeterRegistry registry = new SimpleMeterRegistry(SimpleConfig.DEFAULT, new MockClock()); - private RestTemplate restTemplate = new RestTemplate(); - private MockRestServiceServer mockServer = MockRestServiceServer.createServer(restTemplate); - - @Before - public void before() { - MetricsRestTemplateCustomizer customizer = new MetricsRestTemplateCustomizer( - registry, new DefaultRestTemplateExchangeTagsProvider(), "http.client.requests"); - customizer.customize(restTemplate); - } - - @Test - public void interceptRestTemplate() { - mockServer.expect(MockRestRequestMatchers.requestTo("/test/123")) - .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) - .andRespond(MockRestResponseCreators.withSuccess("OK", - MediaType.APPLICATION_JSON)); - - String result = restTemplate.getForObject("/test/{id}", String.class, 123); - - assertThat(registry.get("http.client.requests").meters()) - .anySatisfy(m -> assertThat(m.getId().getTags().stream().map(Tag::getKey)).doesNotContain("bucket")); - - assertThat(registry.get("http.client.requests") - .tags("method", "GET", "uri", "/test/{id}", "status", "200") - .timer().count()).isEqualTo(1L); - - assertThat(result).isEqualTo("OK"); - - mockServer.verify(); - } - - @Issue("#283") - @Test - public void normalizeUriToContainLeadingSlash() { - mockServer.expect(MockRestRequestMatchers.requestTo("test/123")) - .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) - .andRespond(MockRestResponseCreators.withSuccess("OK", - MediaType.APPLICATION_JSON)); - - String result = restTemplate.getForObject("test/{id}", String.class, 123); - - registry.get("http.client.requests").tags("uri", "/test/{id}").timer(); - assertThat(result).isEqualTo("OK"); - - mockServer.verify(); - } - - @Test - public void interceptRestTemplateWithUri() throws URISyntaxException { - mockServer.expect(MockRestRequestMatchers.requestTo("http://localhost/test/123")) - .andExpect(MockRestRequestMatchers.method(HttpMethod.GET)) - .andRespond(MockRestResponseCreators.withSuccess("OK", - MediaType.APPLICATION_JSON)); - - String result = restTemplate.getForObject(new URI("http://localhost/test/123"), String.class); - - assertThat(result).isEqualTo("OK"); - - registry.get("http.client.requests").tags("uri", "/test/123").timer(); - - mockServer.verify(); - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/RestTemplateExchangeTagsTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/RestTemplateExchangeTagsTest.java deleted file mode 100644 index 4473407d4c..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/client/RestTemplateExchangeTagsTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.client; - -import io.micrometer.core.instrument.Tag; -import org.junit.Test; -import org.springframework.http.HttpStatus; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.mock.http.client.MockClientHttpResponse; - -import java.io.IOException; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link RestTemplateExchangeTags}. - * - * @author Nishant Raut - * @author Brian Clozel - */ -public class RestTemplateExchangeTagsTest { - - @Test - public void outcomeTagIsUnknownWhenResponseIsNull() { - Tag tag = RestTemplateExchangeTags.outcome(null); - assertThat(tag.getValue()).isEqualTo("UNKNOWN"); - } - - @Test - public void outcomeTagIsInformationalWhenResponseIs1xx() { - ClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.CONTINUE); - Tag tag = RestTemplateExchangeTags.outcome(response); - assertThat(tag.getValue()).isEqualTo("INFORMATIONAL"); - } - - @Test - public void outcomeTagIsSuccessWhenResponseIs2xx() { - ClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.OK); - Tag tag = RestTemplateExchangeTags.outcome(response); - assertThat(tag.getValue()).isEqualTo("SUCCESS"); - } - - @Test - public void outcomeTagIsRedirectionWhenResponseIs3xx() { - ClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.MOVED_PERMANENTLY); - Tag tag = RestTemplateExchangeTags.outcome(response); - assertThat(tag.getValue()).isEqualTo("REDIRECTION"); - } - - @Test - public void outcomeTagIsClientErrorWhenResponseIs4xx() { - ClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.BAD_REQUEST); - Tag tag = RestTemplateExchangeTags.outcome(response); - assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR"); - } - - @Test - public void outcomeTagIsServerErrorWhenResponseIs5xx() { - ClientHttpResponse response = new MockClientHttpResponse("foo".getBytes(), HttpStatus.BAD_GATEWAY); - Tag tag = RestTemplateExchangeTags.outcome(response); - assertThat(tag.getValue()).isEqualTo("SERVER_ERROR"); - } - - @Test - public void outcomeTagIsUnknownWhenResponseThrowsIOException() throws Exception { - ClientHttpResponse response = mock(ClientHttpResponse.class); - given(response.getRawStatusCode()).willThrow(IOException.class); - Tag tag = RestTemplateExchangeTags.outcome(response); - assertThat(tag.getValue()).isEqualTo("UNKNOWN"); - } - - @Test - public void outcomeTagIsUnknownForCustomResponseStatus() throws Exception { - ClientHttpResponse response = mock(ClientHttpResponse.class); - given(response.getRawStatusCode()).willThrow(IllegalArgumentException.class); - Tag tag = RestTemplateExchangeTags.outcome(response); - assertThat(tag.getValue()).isEqualTo("UNKNOWN"); - } - - @Test - public void outcomeTagIsClientErrorWhenResponseIsNonStandardInClientSeries() throws IOException { - ClientHttpResponse response = mock(ClientHttpResponse.class); - given(response.getRawStatusCode()).willReturn(490); - Tag tag = RestTemplateExchangeTags.outcome(response); - assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR"); - } - - @Test - public void outcomeTagIsUnknownWhenResponseStatusIsInUnknownSeries() throws IOException { - ClientHttpResponse response = mock(ClientHttpResponse.class); - given(response.getRawStatusCode()).willReturn(701); - Tag tag = RestTemplateExchangeTags.outcome(response); - assertThat(tag.getValue()).isEqualTo("UNKNOWN"); - } - -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/jersey2/server/JerseyServerMetricsTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/jersey2/server/JerseyServerMetricsTest.java deleted file mode 100644 index d849a76f88..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/jersey2/server/JerseyServerMetricsTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.jersey2.server; - -import io.github.resilience4j.retry.Retry; -import io.github.resilience4j.retry.RetryConfig; -import io.micrometer.core.Issue; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.search.MeterNotFoundException; -import org.glassfish.jersey.server.ResourceConfig; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import java.time.Duration; - -@RunWith(SpringRunner.class) -@SpringBootTest(classes = JerseyServerMetricsTest.JerseyApp.class, - webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) -@TestPropertySource(properties = { - "spring.jersey.type=filter", - "spring.jersey.filter.order=-2147483648" -}) -public class JerseyServerMetricsTest { - @Autowired - private TestRestTemplate client; - - @Autowired - private MeterRegistry registry; - - @Issue("#486") - @Test - public void jerseyWeb() { - client.getForObject("/ping/1", String.class); - - RetryConfig retryConfig = RetryConfig.custom() - .maxAttempts(3) - .waitDuration(Duration.ofMillis(250)) - .retryExceptions(MeterNotFoundException.class) - .build(); - - Retry.of("searchForTimer", retryConfig).executeRunnable(() -> - registry.get("http.server.requests") - .tag("uri", "/ping/{id}") - .timer() - ); - } - - @SpringBootApplication(scanBasePackages = "ignore") - @Import({JerseyConfig.class, PingResource.class}) - public static class JerseyApp { - } - - public static class JerseyConfig extends ResourceConfig { - public JerseyConfig() { - this.register(PingResource.class); - } - } - - @Path("/ping") - public static class PingResource { - @GET - @Path("/{id}") - public String ping(@PathParam("id") String id) { - return id; - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterAutoTimedTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterAutoTimedTest.java deleted file mode 100644 index 4232eeba7a..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterAutoTimedTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.servlet; - -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.spring.autoconfigure.web.servlet.WebMvcMetricsAutoConfiguration; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * @author Jon Schneider - */ -@RunWith(SpringRunner.class) -@AutoConfigureMockMvc -@WebAppConfiguration -@TestPropertySource(properties = "security.ignored=/**") -public class WebMvcMetricsFilterAutoTimedTest { - - @Autowired - private MeterRegistry registry; - - @Autowired - private MockMvc mvc; - - @Test - public void metricsCanBeAutoTimed() throws Exception { - this.mvc.perform(get("/api/10")).andExpect(status().isOk()); - - assertThat(this.registry.get("http.server.requests").tags("status", "200").timer().count()).isEqualTo(1); - } - - @Configuration - @EnableWebMvc - @Import(Controller.class) - @ImportAutoConfiguration(WebMvcMetricsAutoConfiguration.class) - static class TestConfiguration { - @Bean - MockClock clock() { - return new MockClock(); - } - - @Bean - MeterRegistry meterRegistry(Clock clock) { - return new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock); - } - } - - @RestController - @RequestMapping("/api") - static class Controller { - @GetMapping("/{id}") - public String successful(@PathVariable Long id) { - return id.toString(); - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterCustomExceptionHandlerTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterCustomExceptionHandlerTest.java deleted file mode 100644 index 8354955682..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterCustomExceptionHandlerTest.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * Copyright 2019 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.servlet; - -import io.micrometer.core.annotation.Timed; -import io.micrometer.core.instrument.Clock; -import io.micrometer.core.instrument.MeterRegistry; -import io.micrometer.core.instrument.MockClock; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.spring.autoconfigure.web.servlet.WebMvcMetricsAutoConfiguration; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - - -/** - * Tests for {@link WebMvcMetricsFilter} in the presence of a custom exception handler. - * - * @author Jon Schneider - */ -@RunWith(SpringRunner.class) -@WebAppConfiguration -@AutoConfigureMockMvc -@TestPropertySource(properties = "security.ignored=/**") -public class WebMvcMetricsFilterCustomExceptionHandlerTest { - - @Autowired - private SimpleMeterRegistry registry; - - @Autowired - private MockMvc mvc; - - @Test - public void handledExceptionIsRecordedInMetricTag() throws Exception { - mvc.perform(get("/api/handledError")).andExpect(status().is5xxServerError()); - - assertThat(this.registry.get("http.server.requests") - .tags("exception", "Exception1", "status", "500").timer().count()).isEqualTo(1L); - } - - @Test - public void rethrownExceptionIsRecordedInMetricTag() { - assertThatCode(() -> mvc.perform(get("/api/rethrownError")) - .andExpect(status().is5xxServerError())); - - assertThat(this.registry.get("http.server.requests") - .tags("exception", "Exception2", "status", "500").timer().count()).isEqualTo(1L); - } - - @Configuration - @EnableWebMvc - @ImportAutoConfiguration(WebMvcMetricsAutoConfiguration.class) - static class TestConfiguration { - @Bean - MockClock clock() { - return new MockClock(); - } - - @Bean - MeterRegistry meterRegistry(Clock clock) { - return new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock); - } - - @RestController - @RequestMapping("/api") - @Timed - static class Controller1 { - @Bean - public CustomExceptionHandler controllerAdvice() { - return new CustomExceptionHandler(); - } - - @GetMapping("/handledError") - public String handledError() { - throw new Exception1(); - } - - @GetMapping("/rethrownError") - public String rethrownError() { - throw new Exception2(); - } - } - } - - @SuppressWarnings("serial") - static class Exception1 extends RuntimeException { - } - - @SuppressWarnings("serial") - static class Exception2 extends RuntimeException { - } - - @ControllerAdvice - static class CustomExceptionHandler { - - @ExceptionHandler - ResponseEntity handleError(Exception1 ex) { - return new ResponseEntity<>("this is a custom exception body", - HttpStatus.INTERNAL_SERVER_ERROR); - } - - @ExceptionHandler - ResponseEntity rethrowError(Exception2 ex) { - throw ex; - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterTest.java deleted file mode 100644 index c718c19df1..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcMetricsFilterTest.java +++ /dev/null @@ -1,436 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.servlet; - -import io.micrometer.core.annotation.Timed; -import io.micrometer.core.instrument.*; -import io.micrometer.core.instrument.composite.CompositeMeterRegistry; -import io.micrometer.core.instrument.config.MeterFilter; -import io.micrometer.core.instrument.config.MeterFilterReply; -import io.micrometer.core.instrument.simple.SimpleConfig; -import io.micrometer.core.instrument.simple.SimpleMeterRegistry; -import io.micrometer.core.lang.NonNull; -import io.micrometer.core.lang.NonNullApi; -import io.micrometer.prometheus.PrometheusConfig; -import io.micrometer.prometheus.PrometheusMeterRegistry; -import io.micrometer.spring.autoconfigure.web.servlet.WebMvcMetricsAutoConfiguration; -import io.prometheus.client.CollectorRegistry; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.autoconfigure.ImportAutoConfiguration; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Import; -import org.springframework.context.annotation.Primary; -import org.springframework.http.HttpStatus; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit4.SpringRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.MvcResult; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.filter.OncePerRequestFilter; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; -import java.util.Collection; -import java.util.concurrent.BrokenBarrierException; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CyclicBarrier; - -import static io.micrometer.spring.web.servlet.WebMvcMetricsFilterTest.RedirectAndNotFoundFilter.TEST_MISBEHAVE_HEADER; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatCode; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.asyncDispatch; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.request; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -/** - * @author Jon Schneider - * @author Nikolay Rybak - */ -@RunWith(SpringRunner.class) -@WebAppConfiguration -@AutoConfigureMockMvc -@TestPropertySource(properties = "security.ignored=/**") -public class WebMvcMetricsFilterTest { - @Autowired - private SimpleMeterRegistry registry; - - @Autowired - private PrometheusMeterRegistry prometheusRegistry; - - @Autowired - private MockMvc mvc; - - @Autowired - @Qualifier("callableBarrier") - private CyclicBarrier callableBarrier; - - @Autowired - @Qualifier("completableFutureBarrier") - private CyclicBarrier completableFutureBarrier; - - @Test - public void timedMethod() throws Exception { - mvc.perform(get("/api/c1/10")).andExpect(status().isOk()); - - assertThat(this.registry.get("http.server.requests") - .tags("status", "200", "uri", "/api/c1/{id}", "public", "true") - .timer().count()).isEqualTo(1L); - } - - @Test - public void subclassedTimedMethod() throws Exception { - mvc.perform(get("/api/c1/metaTimed/10")).andExpect(status().isOk()); - - assertThat(this.registry.get("http.server.requests") - .tags("status", "200", "uri", "/api/c1/metaTimed/{id}") - .timer().count()).isEqualTo(1L); - } - - @Test - public void untimedMethod() throws Exception { - mvc.perform(get("/api/c1/untimed/10")).andExpect(status().isOk()); - - assertThat(this.registry.find("http.server.requests") - .tags("uri", "/api/c1/untimed/10").timer()) - .isNull(); - } - - @Test - public void timedControllerClass() throws Exception { - mvc.perform(get("/api/c2/10")).andExpect(status().isOk()); - - assertThat(this.registry.get("http.server.requests").tags("status", "200") - .timer().count()).isEqualTo(1L); - } - - @Test - public void badClientRequest() throws Exception { - mvc.perform(get("/api/c1/oops")).andExpect(status().is4xxClientError()); - - assertThat(this.registry.get("http.server.requests").tags("status", "400") - .timer().count()).isEqualTo(1L); - } - - @Test - public void redirectRequest() throws Exception { - mvc.perform(get("/api/redirect") - .header(TEST_MISBEHAVE_HEADER, "302")).andExpect(status().is3xxRedirection()); - - this.registry.get("http.server.requests") - .tags("uri", "REDIRECTION", "status", "302").timer(); - } - - @Test - public void notFoundRequest() throws Exception { - mvc.perform(get("/api/not/found") - .header(TEST_MISBEHAVE_HEADER, "404")) - .andExpect(status().is4xxClientError()); - - this.registry.get("http.server.requests") - .tags("uri", "NOT_FOUND", "status", "404").timer(); - } - - @Test - public void unhandledError() { - assertThatCode(() -> mvc.perform(get("/api/c1/unhandledError/10")) - .andExpect(status().isOk())) - .hasRootCauseInstanceOf(RuntimeException.class); - - assertThat(this.registry.get("http.server.requests") - .tags("exception", "RuntimeException") - .timer().count()).isEqualTo(1L); - } - - @Test - public void streamingError() throws Exception { - MvcResult result = this.mvc.perform(get("/api/c1/streamingError")) - .andExpect(request().asyncStarted()).andReturn(); - assertThatCode( - () -> this.mvc.perform(asyncDispatch(result)).andExpect(status().isOk())); - assertThat(this.registry.get("http.server.requests") - .tags("exception", "IOException").timer().count()).isEqualTo(1L); - } - - @Test - public void endpointThrowsError() throws Exception { - mvc.perform(get("/api/c1/error/10")).andExpect(status().is4xxClientError()); - - assertThat(this.registry.get("http.server.requests").tags("status", "422") - .timer().count()).isEqualTo(1L); - } - - @Test - public void endpointThrowsAnonymousError() throws Exception { - try { - mvc.perform(get("/api/c1/anonymousError/10")); - } catch (Throwable ignore) { - } - - assertThat(this.registry.get("http.server.requests").tag("uri", "/api/c1/anonymousError/{id}").timer().getId() - .getTag("exception")) - .endsWith("$1"); - } - - @Test - public void regexBasedRequestMapping() throws Exception { - mvc.perform(get("/api/c1/regex/.abc")).andExpect(status().isOk()); - - assertThat(this.registry.get("http.server.requests") - .tags("uri", "/api/c1/regex/{id:\\.[a-z]+}") - .timer().count()).isEqualTo(1L); - } - - @Test - public void recordQuantiles() throws Exception { - mvc.perform(get("/api/c1/percentiles/10")).andExpect(status().isOk()); - - assertThat(prometheusRegistry.scrape()).contains("quantile=\"0.5\""); - assertThat(prometheusRegistry.scrape()).contains("quantile=\"0.95\""); - } - - @Test - public void recordHistogram() throws Exception { - mvc.perform(get("/api/c1/histogram/10")).andExpect(status().isOk()); - - assertThat(prometheusRegistry.scrape()).contains("le=\"0.001\""); - assertThat(prometheusRegistry.scrape()).contains("le=\"30.0\""); - } - - @Target({ElementType.METHOD}) - @Retention(RetentionPolicy.RUNTIME) - @Timed(percentiles = 0.95) - public @interface Timed95 { - } - - @Configuration - @EnableWebMvc - @Import({Controller1.class, Controller2.class}) - @ImportAutoConfiguration(WebMvcMetricsAutoConfiguration.class) - static class MetricsFilterApp { - @Bean - Clock micrometerClock() { - return new MockClock(); - } - - @Primary - @Bean - MeterRegistry meterRegistry(Collection registries, Clock clock) { - CompositeMeterRegistry composite = new CompositeMeterRegistry(clock); - registries.forEach(composite::add); - return composite; - } - - @Bean - SimpleMeterRegistry simple(Clock clock) { - return new SimpleMeterRegistry(SimpleConfig.DEFAULT, clock); - } - - @Bean - PrometheusMeterRegistry prometheus(Clock clock) { - PrometheusMeterRegistry r = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT, new CollectorRegistry(), clock); - r.config().meterFilter(new MeterFilter() { - @Override - @NonNull - public MeterFilterReply accept(@NonNull Meter.Id id) { - for (Tag tag : id.getTags()) { - if (tag.getKey().equals("uri") && (tag.getValue().contains("histogram") || tag.getValue().contains("percentiles"))) { - return MeterFilterReply.ACCEPT; - } - } - return MeterFilterReply.DENY; - } - }); - return r; - } - - @Bean - RedirectAndNotFoundFilter redirectAndNotFoundFilter() { - return new RedirectAndNotFoundFilter(); - } - - @Bean(name = "callableBarrier") - CyclicBarrier callableBarrier() { - return new CyclicBarrier(2); - } - - @Bean(name = "completableFutureBarrier") - CyclicBarrier completableFutureBarrier() { - return new CyclicBarrier(2); - } - } - - @RestController - @RequestMapping("/api/c1") - static class Controller1 { - @Autowired - @Qualifier("callableBarrier") - private CyclicBarrier callableBarrier; - - @Autowired - @Qualifier("completableFutureBarrier") - private CyclicBarrier completableFutureBarrier; - - @Timed(extraTags = {"public", "true"}) - @GetMapping("/{id}") - public String successfulWithExtraTags(@PathVariable Long id) { - return id.toString(); - } - - @Timed - @Timed(value = "my.long.request", extraTags = {"region", "test"}, longTask = true) - @GetMapping("/callable/{id}") - public Callable asyncCallable(@PathVariable Long id) throws Exception { - callableBarrier.await(); - return () -> { - try { - callableBarrier.await(); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - return id.toString(); - }; - } - - @Timed - @GetMapping("/completableFuture/{id}") - CompletableFuture asyncCompletableFuture(@PathVariable Long id) throws Exception { - completableFutureBarrier.await(); - return CompletableFuture.supplyAsync(() -> { - try { - completableFutureBarrier.await(); - } catch (InterruptedException | BrokenBarrierException e) { - throw new RuntimeException(e); - } - return id.toString(); - }); - } - - @Timed - @Timed(value = "my.long.request.exception", longTask = true) - @GetMapping("/completableFutureException") - CompletableFuture asyncCompletableFutureException() { - return CompletableFuture.supplyAsync(() -> { - throw new RuntimeException("boom"); - }); - } - - @GetMapping("/untimed/{id}") - public String successfulButUntimed(@PathVariable Long id) { - return id.toString(); - } - - @Timed - @GetMapping("/error/{id}") - public String alwaysThrowsException(@PathVariable Long id) { - throw new IllegalStateException("Boom on " + id + "!"); - } - - @Timed - @GetMapping("/anonymousError/{id}") - public String alwaysThrowsAnonymousException(@PathVariable Long id) throws Exception { - throw new Exception("this exception won't have a simple class name") { - }; - } - - @Timed - @GetMapping("/unhandledError/{id}") - public String alwaysThrowsUnhandledException(@PathVariable Long id) { - throw new RuntimeException("Boom on " + id + "!"); - } - - @GetMapping("/streamingError") - public ResponseBodyEmitter streamingError() { - ResponseBodyEmitter emitter = new ResponseBodyEmitter(); - emitter.completeWithError( - new IOException("error while writing to the response")); - return emitter; - } - - @Timed - @GetMapping("/regex/{id:\\.[a-z]+}") - public String successfulRegex(@PathVariable String id) { - return id; - } - - @Timed(percentiles = {0.50, 0.95}) - @GetMapping("/percentiles/{id}") - public String percentiles(@PathVariable String id) { - return id; - } - - @Timed(histogram = true) - @GetMapping("/histogram/{id}") - public String histogram(@PathVariable String id) { - return id; - } - - @Timed95 - @GetMapping("/metaTimed/{id}") - public String meta(@PathVariable String id) { - return id; - } - - @ExceptionHandler(IllegalStateException.class) - @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) - ModelAndView defaultErrorHandler(HttpServletRequest request, Exception e) { - return new ModelAndView("myerror"); - } - } - - @RestController - @Timed - @RequestMapping("/api/c2") - static class Controller2 { - @GetMapping("/{id}") - public String successful(@PathVariable Long id) { - return id.toString(); - } - } - - @NonNullApi - static class RedirectAndNotFoundFilter extends OncePerRequestFilter { - - static final String TEST_MISBEHAVE_HEADER = "x-test-misbehave-status"; - - @Override - protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { - String misbehave = request.getHeader(TEST_MISBEHAVE_HEADER); - if (misbehave != null) { - response.setStatus(Integer.parseInt(misbehave)); - } else { - filterChain.doFilter(request, response); - } - } - } -} diff --git a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcTagsTest.java b/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcTagsTest.java deleted file mode 100644 index 2b1a47dcb6..0000000000 --- a/micrometer-spring-legacy/src/test/java/io/micrometer/spring/web/servlet/WebMvcTagsTest.java +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Copyright 2017 Pivotal Software, Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - *

- * https://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package io.micrometer.spring.web.servlet; - -import io.micrometer.core.instrument.Tag; -import org.junit.Test; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.web.servlet.HandlerMapping; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Tests for {@link WebMvcTags}. - * - * @author Andy Wilkinson - * @author Brian Clozel - * @author Michael McFadyen - */ -public class WebMvcTagsTest { - private final MockHttpServletRequest request = new MockHttpServletRequest(); - - private final MockHttpServletResponse response = new MockHttpServletResponse(); - - @Test - public void uriTagValueIsBestMatchingPatternWhenAvailable() { - this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, - "/spring"); - this.response.setStatus(301); - Tag tag = WebMvcTags.uri(this.request, this.response); - assertThat(tag.getValue()).isEqualTo("/spring"); - } - - @Test - public void uriTagValueIsRootWhenRequestHasNoPatternOrPathInfo() { - assertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("root"); - } - - @Test - public void uriTagValueIsRootWhenRequestHasNoPatternAndSlashPathInfo() { - this.request.setPathInfo("/"); - assertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("root"); - } - - @Test - public void uriTagValueIsUnknownWhenRequestHasNoPatternAndNonRootPathInfo() { - this.request.setPathInfo("/example"); - assertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("UNKNOWN"); - } - - @Test - public void uriTagValueIsRedirectionWhenResponseStatusIs3xx() { - this.response.setStatus(301); - Tag tag = WebMvcTags.uri(this.request, this.response); - assertThat(tag.getValue()).isEqualTo("REDIRECTION"); - } - - @Test - public void uriTagValueIsNotFoundWhenResponseStatusIs404() { - this.response.setStatus(404); - Tag tag = WebMvcTags.uri(this.request, this.response); - assertThat(tag.getValue()).isEqualTo("NOT_FOUND"); - } - - @Test - public void uriTagToleratesCustomResponseStatus() { - this.response.setStatus(601); - Tag tag = WebMvcTags.uri(this.request, this.response); - assertThat(tag.getValue()).isEqualTo("root"); - } - - @Test - public void uriTagIsUnknownWhenRequestIsNull() { - Tag tag = WebMvcTags.uri(null, null); - assertThat(tag.getValue()).isEqualTo("UNKNOWN"); - } - - @Test - public void outcomeTagIsUnknownWhenResponseIsNull() { - Tag tag = WebMvcTags.outcome(null); - assertThat(tag.getValue()).isEqualTo("UNKNOWN"); - } - - @Test - public void outcomeTagIsInformationalWhenResponseIs1xx() { - this.response.setStatus(100); - Tag tag = WebMvcTags.outcome(this.response); - assertThat(tag.getValue()).isEqualTo("INFORMATIONAL"); - } - - @Test - public void outcomeTagIsSuccessWhenResponseIs2xx() { - this.response.setStatus(200); - Tag tag = WebMvcTags.outcome(this.response); - assertThat(tag.getValue()).isEqualTo("SUCCESS"); - } - - @Test - public void outcomeTagIsRedirectionWhenResponseIs3xx() { - this.response.setStatus(301); - Tag tag = WebMvcTags.outcome(this.response); - assertThat(tag.getValue()).isEqualTo("REDIRECTION"); - } - - @Test - public void outcomeTagIsClientErrorWhenResponseIs4xx() { - this.response.setStatus(400); - Tag tag = WebMvcTags.outcome(this.response); - assertThat(tag.getValue()).isEqualTo("CLIENT_ERROR"); - } - - @Test - public void outcomeTagIsServerErrorWhenResponseIs5xx() { - this.response.setStatus(500); - Tag tag = WebMvcTags.outcome(this.response); - assertThat(tag.getValue()).isEqualTo("SERVER_ERROR"); - } - -} diff --git a/micrometer-spring-legacy/src/test/resources/logback.xml b/micrometer-spring-legacy/src/test/resources/logback.xml deleted file mode 100644 index 81414f4b90..0000000000 --- a/micrometer-spring-legacy/src/test/resources/logback.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - \ No newline at end of file diff --git a/samples/micrometer-samples-boot1/src/main/resources/application.yml b/samples/micrometer-samples-boot1/src/main/resources/application.yml deleted file mode 100644 index c2dd320881..0000000000 --- a/samples/micrometer-samples-boot1/src/main/resources/application.yml +++ /dev/null @@ -1,46 +0,0 @@ -# -# Copyright 2017 Pivotal Software, Inc. -#

-# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -#

-# https://www.apache.org/licenses/LICENSE-2.0 -#

-# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -server.port: 8080 -management.security.enabled: false - -# see https://stackoverflow.com/questions/44474160/spring-integration-display-warning-that-header-is-ignored-for-population-because -logging.level.org.springframework.integration.support.MessageBuilder: WARN -logging.level.org.springframework.boot: INFO - -management.metrics.export: - appoptics.enabled: false - atlas.enabled: false - azuremonitor.enabled: false - datadog.enabled: false - dynatrace.enabled: false - elastic.enabled: false - ganglia.enabled: false - graphite.enabled: false - humio.enabled: false - influx.enabled: false - jmx.enabled: false - kairos.enabled: false - logging.enabled: false - newrelic.enabled: false - prometheus.enabled: false - signalfx.enabled: false - stackdriver.enabled: false - statsd.enabled: false - wavefront.enabled: false -security.ignored: /** - -endpoints.shutdown.enabled: true \ No newline at end of file diff --git a/samples/micrometer-samples-boot1/build.gradle b/samples/micrometer-samples-boot2/build.gradle similarity index 80% rename from samples/micrometer-samples-boot1/build.gradle rename to samples/micrometer-samples-boot2/build.gradle index 40a82a72b0..ed451b93f3 100644 --- a/samples/micrometer-samples-boot1/build.gradle +++ b/samples/micrometer-samples-boot2/build.gradle @@ -4,7 +4,7 @@ plugins { dependencyManagement { imports { - mavenBom 'org.springframework.boot:spring-boot-dependencies:1.5.17.RELEASE' + mavenBom 'org.springframework.boot:spring-boot-dependencies:2.2.0.RELEASE' } dependencies { // not necessary in real Boot 1.5.x apps because reactor is shaded inside the @@ -14,15 +14,16 @@ dependencyManagement { } dependencies { - compile project(':micrometer-spring-legacy') - ['atlas', 'azure-monitor', 'prometheus', 'datadog', 'elastic', 'ganglia', 'graphite', 'jmx', 'influx', 'statsd', 'new-relic', 'cloudwatch', 'cloudwatch2', 'signalfx', 'wavefront', 'elastic', 'dynatrace', 'humio', 'appoptics', 'stackdriver'].each { sys -> compile project(":micrometer-registry-$sys") } compile 'org.springframework.boot:spring-boot-starter-web' - compile 'org.springframework.boot:spring-boot-actuator' - compile 'org.springframework.integration:spring-integration-java-dsl' + compile 'org.springframework.boot:spring-boot-starter-actuator' compile 'org.springframework.integration:spring-integration-ws' compile 'org.springframework.integration:spring-integration-xml' + + // For running on Java 9+ + runtime 'javax.xml.soap:javax.xml.soap-api:1.4.0' + runtime 'com.sun.xml.messaging.saaj:saaj-impl:1.5.1' } diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/AppOpticsSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/AppOpticsSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/AppOpticsSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/AppOpticsSample.java index dc714ea8fe..59ad3d440c 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/AppOpticsSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/AppOpticsSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/AtlasSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/AtlasSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/AtlasSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/AtlasSample.java index 63a39154ea..9e51868a11 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/AtlasSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/AtlasSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/AzureMonitorSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/AzureMonitorSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/AzureMonitorSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/AzureMonitorSample.java index 45ceeed2d9..199b177dac 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/AzureMonitorSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/AzureMonitorSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/DatadogSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/DatadogSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/DatadogSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/DatadogSample.java index db1d9f9bf4..049e8494b9 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/DatadogSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/DatadogSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/DynatraceSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/DynatraceSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/DynatraceSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/DynatraceSample.java index 98c6ccdb62..648dd9f1ce 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/DynatraceSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/DynatraceSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/ElasticSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/ElasticSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/ElasticSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/ElasticSample.java index bfcdf04a08..9083784929 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/ElasticSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/ElasticSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/GangliaSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/GangliaSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/GangliaSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/GangliaSample.java index 4523a7b72d..b481ddb9f2 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/GangliaSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/GangliaSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/HumioSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/HumioSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/HumioSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/HumioSample.java index f07bac68dc..4c56386cc3 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/HumioSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/HumioSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/InfluxSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/InfluxSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/InfluxSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/InfluxSample.java index 6f3200173e..08ff1d416e 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/InfluxSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/InfluxSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/JmxSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/JmxSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/JmxSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/JmxSample.java index 4c180872ac..5ed18fab20 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/JmxSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/JmxSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/KairosSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/KairosSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/KairosSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/KairosSample.java index e98149acf6..738467ca80 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/KairosSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/KairosSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/LoggingRegistrySample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/LoggingRegistrySample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/LoggingRegistrySample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/LoggingRegistrySample.java index a8f5328416..1eb8eb75f4 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/LoggingRegistrySample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/LoggingRegistrySample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/NewRelicSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/NewRelicSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/NewRelicSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/NewRelicSample.java index 47786ab11a..138557aace 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/NewRelicSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/NewRelicSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/PrometheusPushgatewaySample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/PrometheusPushgatewaySample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/PrometheusPushgatewaySample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/PrometheusPushgatewaySample.java index c48a1b5a25..c9842ddbf2 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/PrometheusPushgatewaySample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/PrometheusPushgatewaySample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/PrometheusSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/PrometheusSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/PrometheusSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/PrometheusSample.java index 7dfd0f5e0d..942e8cb161 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/PrometheusSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/PrometheusSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/SignalFxSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/SignalFxSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/SignalFxSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/SignalFxSample.java index e9215bea81..5d6baa15b7 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/SignalFxSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/SignalFxSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/SimpleSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/SimpleSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/SimpleSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/SimpleSample.java index 84195245f8..7061c9f3b9 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/SimpleSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/SimpleSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StackdriverSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StackdriverSample.java similarity index 92% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StackdriverSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StackdriverSample.java index 7387dfcdd2..927124b8a3 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StackdriverSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StackdriverSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StatsdDatadogSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StatsdDatadogSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StatsdDatadogSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StatsdDatadogSample.java index 57b382bdea..d8c0c26695 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StatsdDatadogSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StatsdDatadogSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StatsdEtsySample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StatsdEtsySample.java similarity index 92% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StatsdEtsySample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StatsdEtsySample.java index 72c259591d..c006065bd4 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StatsdEtsySample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StatsdEtsySample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; @@ -29,4 +29,4 @@ public class StatsdEtsySample { public static void main(String[] args) { new SpringApplicationBuilder(StatsdEtsySample.class).profiles("statsd-etsy").run(args); } -} \ No newline at end of file +} diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StatsdTelegrafSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StatsdTelegrafSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StatsdTelegrafSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StatsdTelegrafSample.java index ed00dbdb05..7d003cf7d2 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/StatsdTelegrafSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/StatsdTelegrafSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/WavefrontSample.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/WavefrontSample.java similarity index 91% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/WavefrontSample.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/WavefrontSample.java index d188006232..001ce75008 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/WavefrontSample.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/WavefrontSample.java @@ -13,9 +13,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples; +package io.micrometer.boot2.samples; -import io.micrometer.boot1.samples.components.PersonController; +import io.micrometer.boot2.samples.components.PersonController; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.scheduling.annotation.EnableScheduling; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/components/PersonController.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/components/PersonController.java similarity index 98% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/components/PersonController.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/components/PersonController.java index b82caadc69..39117e151a 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/components/PersonController.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/components/PersonController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples.components; +package io.micrometer.boot2.samples.components; import io.micrometer.core.annotation.Timed; import io.micrometer.core.instrument.MeterRegistry; diff --git a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/integration/SpringIntegrationApplication.java b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/integration/SpringIntegrationApplication.java similarity index 92% rename from samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/integration/SpringIntegrationApplication.java rename to samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/integration/SpringIntegrationApplication.java index 1c8e17827a..dd960090aa 100644 --- a/samples/micrometer-samples-boot1/src/main/java/io/micrometer/boot1/samples/integration/SpringIntegrationApplication.java +++ b/samples/micrometer-samples-boot2/src/main/java/io/micrometer/boot2/samples/integration/SpringIntegrationApplication.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package io.micrometer.boot1.samples.integration; +package io.micrometer.boot2.samples.integration; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @@ -24,9 +24,9 @@ import org.springframework.integration.annotation.IntegrationComponentScan; import org.springframework.integration.annotation.MessagingGateway; import org.springframework.integration.dsl.IntegrationFlow; -import org.springframework.integration.dsl.support.Transformers; import org.springframework.integration.ws.SimpleWebServiceOutboundGateway; import org.springframework.integration.ws.WebServiceHeaders; +import org.springframework.integration.xml.transformer.XPathTransformer; @Configuration @SpringBootApplication @@ -57,7 +57,7 @@ public IntegrationFlow convert() { "https://www.w3schools.com/xml/FahrenheitToCelsius")) .handle(new SimpleWebServiceOutboundGateway( "https://www.w3schools.com/xml/tempconvert.asmx"), e -> e.id("w3schools")) - .transform(Transformers.xpath("/*[local-name()=\"FahrenheitToCelsiusResponse\"]" + .transform(new XPathTransformer("/*[local-name()=\"FahrenheitToCelsiusResponse\"]" + "/*[local-name()=\"FahrenheitToCelsiusResult\"]"), e -> e.id("toResponse")); } diff --git a/samples/micrometer-samples-boot1/src/main/resources/.gitignore b/samples/micrometer-samples-boot2/src/main/resources/.gitignore similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/.gitignore rename to samples/micrometer-samples-boot2/src/main/resources/.gitignore diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-appoptics.yml b/samples/micrometer-samples-boot2/src/main/resources/application-appoptics.yml similarity index 97% rename from samples/micrometer-samples-boot1/src/main/resources/application-appoptics.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-appoptics.yml index cd345a457d..f5ee6fb5f7 100644 --- a/samples/micrometer-samples-boot1/src/main/resources/application-appoptics.yml +++ b/samples/micrometer-samples-boot2/src/main/resources/application-appoptics.yml @@ -18,4 +18,4 @@ management.metrics.export: appoptics: enabled: true step: 10s - token: fake \ No newline at end of file + api-token: fake diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-atlas.yml b/samples/micrometer-samples-boot2/src/main/resources/application-atlas.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-atlas.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-atlas.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-azuremonitor.yml b/samples/micrometer-samples-boot2/src/main/resources/application-azuremonitor.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-azuremonitor.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-azuremonitor.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-datadog.yml b/samples/micrometer-samples-boot2/src/main/resources/application-datadog.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-datadog.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-datadog.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-dynatrace.yml b/samples/micrometer-samples-boot2/src/main/resources/application-dynatrace.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-dynatrace.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-dynatrace.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-elastic.yml b/samples/micrometer-samples-boot2/src/main/resources/application-elastic.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-elastic.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-elastic.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-ganglia.yml b/samples/micrometer-samples-boot2/src/main/resources/application-ganglia.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-ganglia.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-ganglia.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-humio.yml b/samples/micrometer-samples-boot2/src/main/resources/application-humio.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-humio.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-humio.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-influx.yml b/samples/micrometer-samples-boot2/src/main/resources/application-influx.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-influx.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-influx.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-jmx.yml b/samples/micrometer-samples-boot2/src/main/resources/application-jmx.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-jmx.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-jmx.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-kairos.yml b/samples/micrometer-samples-boot2/src/main/resources/application-kairos.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-kairos.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-kairos.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-logging.yml b/samples/micrometer-samples-boot2/src/main/resources/application-logging.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-logging.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-logging.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-prometheus-pushgateway.yml b/samples/micrometer-samples-boot2/src/main/resources/application-prometheus-pushgateway.yml similarity index 70% rename from samples/micrometer-samples-boot1/src/main/resources/application-prometheus-pushgateway.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-prometheus-pushgateway.yml index 48a4ea82cc..af12744e95 100644 --- a/samples/micrometer-samples-boot1/src/main/resources/application-prometheus-pushgateway.yml +++ b/samples/micrometer-samples-boot2/src/main/resources/application-prometheus-pushgateway.yml @@ -15,17 +15,16 @@ # -management.security.enabled: false - -management.metrics.export: - prometheus: - enabled: true - pushgateway: +management: + metrics.export: + prometheus: enabled: true - push-rate: 10s - grouping-keys: - instance: local + pushgateway: + enabled: true + push-rate: 10s + grouping-keys: + instance: local -endpoints.prometheus.enabled: false + endpoint.prometheus.enabled: false -spring.application.name: pushgateway-sample \ No newline at end of file +spring.application.name: pushgateway-sample diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-prometheus.yml b/samples/micrometer-samples-boot2/src/main/resources/application-prometheus.yml similarity index 95% rename from samples/micrometer-samples-boot1/src/main/resources/application-prometheus.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-prometheus.yml index d65cbae4b7..c15e8f0659 100644 --- a/samples/micrometer-samples-boot1/src/main/resources/application-prometheus.yml +++ b/samples/micrometer-samples-boot2/src/main/resources/application-prometheus.yml @@ -14,6 +14,5 @@ # limitations under the License. # -management.security.enabled: false management.metrics.export.prometheus.enabled: true -management.metrics.distribution.percentiles-histogram.http: true \ No newline at end of file +management.metrics.distribution.percentiles-histogram.http: true diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-signalfx.yml b/samples/micrometer-samples-boot2/src/main/resources/application-signalfx.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-signalfx.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-signalfx.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-stackdriver.yml b/samples/micrometer-samples-boot2/src/main/resources/application-stackdriver.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-stackdriver.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-stackdriver.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-statsd-datadog.yml b/samples/micrometer-samples-boot2/src/main/resources/application-statsd-datadog.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-statsd-datadog.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-statsd-datadog.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-statsd-etsy.yml b/samples/micrometer-samples-boot2/src/main/resources/application-statsd-etsy.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-statsd-etsy.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-statsd-etsy.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-statsd-telegraf.yml b/samples/micrometer-samples-boot2/src/main/resources/application-statsd-telegraf.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-statsd-telegraf.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-statsd-telegraf.yml diff --git a/samples/micrometer-samples-boot1/src/main/resources/application-wavefront.yml b/samples/micrometer-samples-boot2/src/main/resources/application-wavefront.yml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/application-wavefront.yml rename to samples/micrometer-samples-boot2/src/main/resources/application-wavefront.yml diff --git a/micrometer-spring-legacy/src/test/resources/application.yml b/samples/micrometer-samples-boot2/src/main/resources/application.yml similarity index 90% rename from micrometer-spring-legacy/src/test/resources/application.yml rename to samples/micrometer-samples-boot2/src/main/resources/application.yml index 5879d4f409..87985a0824 100644 --- a/micrometer-spring-legacy/src/test/resources/application.yml +++ b/samples/micrometer-samples-boot2/src/main/resources/application.yml @@ -14,18 +14,19 @@ # limitations under the License. # +server.port: 8080 + # see https://stackoverflow.com/questions/44474160/spring-integration-display-warning-that-header-is-ignored-for-population-because logging.level.org.springframework.integration.support.MessageBuilder: WARN logging.level.org.springframework.boot: INFO -management.metrics: - use-global-registry: false - export: +management: + metrics.export: appoptics.enabled: false atlas.enabled: false azuremonitor.enabled: false - dynatrace.enabled: false datadog.enabled: false + dynatrace.enabled: false elastic.enabled: false ganglia.enabled: false graphite.enabled: false @@ -40,3 +41,10 @@ management.metrics: stackdriver.enabled: false statsd.enabled: false wavefront.enabled: false + + endpoint.shutdown.enabled: true + + endpoints: + web: + exposure: + include: '*' diff --git a/samples/micrometer-samples-boot1/src/main/resources/logback.xml b/samples/micrometer-samples-boot2/src/main/resources/logback.xml similarity index 100% rename from samples/micrometer-samples-boot1/src/main/resources/logback.xml rename to samples/micrometer-samples-boot2/src/main/resources/logback.xml diff --git a/scripts/sync-to-maven-central.sh b/scripts/sync-to-maven-central.sh index 957240067d..2b626a3ada 100755 --- a/scripts/sync-to-maven-central.sh +++ b/scripts/sync-to-maven-central.sh @@ -25,7 +25,6 @@ MODULES=( micrometer-registry-signalfx micrometer-registry-statsd micrometer-registry-wavefront - micrometer-spring-legacy micrometer-jersey2 micrometer-registry-stackdriver micrometer-registry-elastic @@ -50,4 +49,4 @@ do -X \ POST "https://api.bintray.com/maven_central_sync/spring/jars/${module}/versions/${VERSION}" > /dev/null || { echo "Failed to sync" >&2; exit 1; } echo " complete" -done \ No newline at end of file +done diff --git a/settings.gradle b/settings.gradle index 4b73d252fd..6b2017244b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,10 +1,9 @@ rootProject.name = 'micrometer' include 'micrometer-core' -include 'micrometer-spring-legacy' include 'micrometer-jersey2' -['core', 'boot1'].each { sample -> +['core', 'boot2'].each { sample -> include "micrometer-samples-$sample" project(":micrometer-samples-$sample").projectDir = new File(rootProject.projectDir, "samples/micrometer-samples-$sample") }