excludeFilters in ComponentScan stops the http_server_request actuator metrics

36 Views Asked by At

We have a spring based simple library where we added some new implementation in a new dedicated package. Sharing the main configuration from class that package

@Configuration
public class ChangesConfig {

    public static final String CONFIG_CHANGE_PREFIX = "CONFIG_CHANGE_";
    public static final String CONFIG_CHANGE_STANDARD_OUTPUT = "CONFIG_CHANGE_STANDARD_OUTPUT";

    @Bean
    GcpProjectIdProvider gcpProjectIdProvider() {
        return new DefaultGcpProjectIdProvider();
    }

    @Bean
    public Builder BuilderConfig(GcpProjectIdProvider gcpProjectIdProvider) {
        return new CachingBuilder(new DefaultBuilder(gcpProjectIdProvider));
    }
    @Bean
    public ChangeProvider ChangeProvider(ConfigurableEnvironment configurableEnvironment, Builder BuilderConfig) {
        Properties props = new Properties();
        MutablePropertySources mutablePropertySources = configurableEnvironment.getPropertySources();
        List<String> properties = StreamSupport.stream(mutablePropertySources.spliterator(), false)
                .filter(EnumerablePropertySource.class::isInstance)
                .map(ps -> ((EnumerablePropertySource<?>) ps).getPropertyNames())
                .flatMap(Arrays::stream)
                .filter(propName -> propName.startsWith(CONFIG_CHANGE_PREFIX))
                .collect(Collectors.toList());
        if(properties.isEmpty())
            return new NoOpChangeProvider();
        properties.forEach(propName -> props.setProperty(propName.substring(CONFIG_CHANGE_PREFIX.length()).toLowerCase(), configurableEnvironment.getProperty(propName)));
        if(properties.size() == 1 && properties.contains(CONFIG_CHANGE_STANDARD_OUTPUT)) {
            return new StandardOutputChangeProvider();
        }
        return new ChangeProviderImpl(props, BuilderConfig);
    }

    @Bean
    public ConfigRecorder ConfigRecorder(ChangeProvider ChangeProvider) {
        return new ConfigRecorderImpl(ChangeProvider);
    }

}

Built the new version of this library.

To its upstream services where this library was used, bumped the version and tests started failing due to that implementation in new package.

@Slf4j
@SpringBootApplication(exclude = {R2dbcAutoConfiguration.class}, scanBasePackages = "com.abc")
public class Application {

    public static void main(String[] args) {
        ReactorDebugAgent.init();
        SpringApplication.run(Application.class, args);
    }
}

So We decided to exclude the specific package from ComponentScan and all tests went fine and build worked fine.

@Slf4j
@SpringBootApplication(exclude = {R2dbcAutoConfiguration.class})
@ComponentScan(basePackages = "com.abc", excludeFilters= {@ComponentScan.Filter(type= FilterType.REGEX, pattern={"com.abc.bcd.def..*"})})
public class Application {

    public static void main(String[] args) {
        ReactorDebugAgent.init();
        SpringApplication.run(Application.class, args);
    }
}

However we noticed only http_server_request actuator metrics are missing. If i remove the excludeFilters in above configuration then http_server_request actuator metrics are sent fine.

What could be the reason ?

We tried various changes with @ComponentScan but nothing seems to work.

0

There are 0 best solutions below