Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;
Expand All @@ -46,6 +47,7 @@
@ConditionalOnBean(Clock.class)
@EnableConfigurationProperties(SimpleProperties.class)
@ConditionalOnMissingBean(MeterRegistry.class)
@ConditionalOnProperty(prefix = "management.metrics.export.simple", name = "enabled", havingValue = "true", matchIfMissing = true)
public class SimpleMetricsExportAutoConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
public class SimpleProperties {

/**
* Enable publishing to the backend.
* Enable in-memory metrics that aren't published anywhere (allows you to see
* what metrics are collected in the metrics actuator endpoint).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a bit misleading and we should rephrase that.

*/
private boolean enabled;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default value here should be true. And we shouldn't have a property at all since it's not used anywhere in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I guess adding it to additional-spring-configuration-metadata.json accomplishes the same.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ public String get(String k) {
return null;
}

@Override
public boolean enabled() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this property at all in SimpleConfig was a mistake. When this is merged, I'll remove it.

return get(SimpleProperties::getEnabled, SimpleConfig.super::enabled);
}

@Override
public Duration step() {
return get(SimpleProperties::getStep, SimpleConfig.super::step);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,15 @@ public void autoConfiguresConfigAndMeterRegistry() {
.hasSingleBean(Clock.class).hasSingleBean(SimpleConfig.class));
}

@Test
public void backsOffWhenSpecificallyDisabled() {
this.contextRunner.withUserConfiguration(BaseConfiguration.class)
.withPropertyValues("management.metrics.export.simple.enabled=false")
.run((context) -> assertThat(context)
.doesNotHaveBean(SimpleMeterRegistry.class)
.doesNotHaveBean(SimpleConfig.class));
}

@Test
public void allowsConfigToBeCustomized() {
this.contextRunner.withUserConfiguration(CustomConfigConfiguration.class)
Expand Down