I have a spring boot application (version 2.3.4) and I'm using @KafkaListener to consume records. I also use actuator and micrometer (version 1.5.5) for the metrics.
The problem is that I can't see the Kafka metrics in /actuator/prometheus. I'm using the following dependencies:
'org.springframework.boot' version '2.3.4.RELEASE'
implementation group: 'org.springframework.kafka', name: 'spring-kafka', version: '2.5.10.RELEASE'
implementation group: 'org.apache.kafka', name: 'kafka-clients', version: '2.5.1'
And added these properties to application.yaml:
management:
server:
port: 9091
endpoints:
web:
exposure:
include: "*"
endpoint:
health:
probes:
enabled: true
spring:
jmx:
enabled: true
Trying to under if I should add anything else to make the kafka metrics visible in /actuator/prometheus
Note that the metrics are visible when I use default KafkaTemplate, but when trying to create a custom KafkaTemplate, the metrics disappear:
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
public ProducerFactory<String, String> customProducerFactory() {
Map<String, Object> configProps = new HashMap<>();
configProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "127.0.0.1:9092");
configProps.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, Serdes.String().serializer().getClass().getName());
configProps.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, Serdes.String().serializer().getClass().getName());
return new DefaultKafkaProducerFactory<>(configProps);
}
@Bean
public KafkaTemplate<String, String> customProducer() {
return new KafkaTemplate<>(customProducerFactory());
}
@KafkaListener(id = "test", topics = "test_topic")
public void listen(String in) {
System.out.println(in);
}
@Bean
public NewTopic topic() {
return TopicBuilder.name("test_topic").partitions(1).replicas(1).build();
}
@Bean
public ApplicationRunner runner(KafkaTemplate<String, String> template) {
return args -> {
template.send("test_topic", "foo");
};
}
}