Remove metric export auto-configuration

This commit removes the auto-configuration that export metrics
automatically to Redis. This feature has been superseded by the stats
feature and can be restored at any time in a custom service.

Closes gh-373
This commit is contained in:
Stephane Nicoll 2017-02-25 09:46:44 +01:00
parent 06f314dc8c
commit 13766008b4
6 changed files with 0 additions and 283 deletions

View File

@ -21,11 +21,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>

View File

@ -18,22 +18,9 @@ package io.spring.initializr.actuate.autoconfigure;
import io.spring.initializr.actuate.metric.ProjectGenerationMetricsListener;
import org.springframework.boot.actuate.autoconfigure.ExportMetricWriter;
import org.springframework.boot.actuate.autoconfigure.MetricExportAutoConfiguration;
import org.springframework.boot.actuate.metrics.CounterService;
import org.springframework.boot.actuate.metrics.repository.redis.RedisMetricRepository;
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration;
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.data.redis.connection.RedisConnectionFactory;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.util.ObjectUtils;
/**
* {@link org.springframework.boot.autoconfigure.EnableAutoConfiguration
@ -42,7 +29,6 @@ import org.springframework.util.ObjectUtils;
* @author Dave Syer
*/
@Configuration
@AutoConfigureAfter({ RedisAutoConfiguration.class, MetricExportAutoConfiguration.class })
public class InitializrMetricsConfiguration {
@Bean
@ -51,22 +37,4 @@ public class InitializrMetricsConfiguration {
return new ProjectGenerationMetricsListener(counterService);
}
@ConditionalOnBean(RedisConnectionFactory.class)
@ConditionalOnProperty(value = "spring.metrics.export.enabled")
@EnableScheduling
@EnableConfigurationProperties(MetricsProperties.class)
@Configuration
protected static class MetricsExportConfiguration {
@Bean
@ExportMetricWriter
public MetricWriter writer(RedisConnectionFactory connectionFactory,
MetricsProperties metrics, ApplicationContext context) {
return new RedisMetricRepository(connectionFactory,
metrics.getPrefix() + metrics.getId(context.getId()) + "."
+ ObjectUtils.getIdentityHexString(context) + ".",
metrics.getKey());
}
}
}

View File

@ -1,97 +0,0 @@
/*
* Copyright 2012-2017 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
*
* http://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.spring.initializr.actuate.autoconfigure;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;
/**
* Metrics-related configuration.
*
* @author Dave Syer
*/
@ConfigurationProperties("initializr.metrics")
public class MetricsProperties {
/**
* Prefix for redis keys holding metrics in data store.
*/
private String prefix = "spring.metrics.collector.";
/**
* Redis key holding index to metrics keys in data store.
*/
private String key = "keys.spring.metrics.collector";
/**
* Identifier for application in metrics keys. Keys will be exported in the form
* "[id].[hex].[name]" (where "[id]" is this value, "[hex]" is unique per application
* context, and "[name]" is the "natural" name for the metric.
*/
@Value("${spring.application.name:${vcap.application.name:application}}")
private String id;
/**
* The rate (in milliseconds) at which metrics are exported to Redis. If the value is
* <=0 then the export is disabled.
*/
@Value("${spring.metrics.export.default.delayMillis:5000}")
private long rateMillis = 5000L;
public String getPrefix() {
if (prefix.endsWith(".")) {
return prefix;
}
return prefix + ".";
}
public String getId(String defaultValue) {
if (StringUtils.hasText(id)) {
return id;
}
return defaultValue;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public long getRateMillis() {
return rateMillis;
}
public void setRateMillis(long rateMillis) {
this.rateMillis = rateMillis;
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
}

View File

@ -1,95 +0,0 @@
/*
* Copyright 2012-2017 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
*
* http://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.spring.initializr.actuate.metric;
import io.spring.initializr.actuate.metric.MetricsExportTests.Config;
import io.spring.initializr.actuate.test.RedisRunning;
import io.spring.initializr.generator.ProjectGeneratedEvent;
import io.spring.initializr.generator.ProjectRequest;
import io.spring.initializr.metadata.InitializrMetadata;
import io.spring.initializr.metadata.InitializrMetadataBuilder;
import io.spring.initializr.metadata.InitializrMetadataProvider;
import io.spring.initializr.metadata.InitializrProperties;
import io.spring.initializr.metadata.SimpleInitializrMetadataProvider;
import org.junit.Before;
import org.junit.Rule;
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.actuate.metrics.repository.redis.RedisMetricRepository;
import org.springframework.boot.actuate.metrics.writer.MetricWriter;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertTrue;
/**
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Config.class, properties = {
"spring.metrics.export.delayMillis:500", "spring.metrics.export.enabled:true",
"initializr.metrics.prefix:test.prefix", "initializr.metrics.key:key.test" })
public class MetricsExportTests {
@Rule
public RedisRunning running = new RedisRunning();
@Autowired
private ProjectGenerationMetricsListener listener;
@Autowired
@Qualifier("writer")
private MetricWriter writer;
private RedisMetricRepository repository;
@Before
public void init() throws Exception {
repository = (RedisMetricRepository) writer;
repository.findAll().forEach(it -> repository.reset(it.getName()));
assertTrue("Metrics not empty", repository.count() == 0);
}
@Test
public void exportAndCheckMetricsExist() throws Exception {
listener.onGeneratedProject(new ProjectGeneratedEvent(new ProjectRequest()));
Thread.sleep(1000L);
assertTrue("No metrics exported", repository.count() > 0);
}
@Configuration
@EnableAutoConfiguration
@EnableConfigurationProperties(InitializrProperties.class)
protected static class Config {
@Bean
public InitializrMetadataProvider initializrMetadataProvider(
InitializrProperties properties) {
InitializrMetadata metadata = InitializrMetadataBuilder
.fromInitializrProperties(properties).build();
return new SimpleInitializrMetadataProvider(metadata);
}
}
}

View File

@ -1,50 +0,0 @@
/*
* Copyright 2012-2017 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
*
* http://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.spring.initializr.actuate.test;
import org.junit.Assume;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
/**
* A {@link org.junit.rules.TestRule} that validates Redis is available.
*
* @author Dave Syer
*/
public class RedisRunning extends TestWatcher {
private JedisConnectionFactory connectionFactory;
@Override
public Statement apply(Statement base, Description description) {
if (connectionFactory == null) {
connectionFactory = new JedisConnectionFactory();
connectionFactory.afterPropertiesSet();
}
try {
connectionFactory.getConnection();
}
catch (Exception ex) {
Assume.assumeNoException("Cannot connect to Redis (so skipping tests)", ex);
}
return super.apply(base, description);
}
}

View File

@ -1,4 +0,0 @@
spring:
metrics:
export:
enabled: true