Monitor Kafka Streams application state out of the box
Feature request
I would like to monitor my Kafka Streams application state without without extra programming effort.
Rationale Monitoring Kafka Streams application state is one of the basis metrics for operating Kafka Streams applications. When application is going to Re-Balancing state too often or stuck in Error state this is what really matters in Kafka Streams observability.
Additional context
Kafka Streams is by default reporting application state on top level client metrics. Library is reporting enum values:
Because of reported value is not numeric, Micrometer is filtering this metric out in KafkaMetrics meter binder.
Proposed solution As every Kafka Stream state has also standard numeric representation we can translate enum -> double and report Kafka Streams application state out of the box. We can extend present KafkaMetrics meter binder implementation by adding there if statement for state metric and register gauge:
return stateMetric -> {
KafkaStreams.State state = (KafkaStreams.State) stateMetric.metricValue();
return switch (state) {
case CREATED -> 0;
case RUNNING -> 2;
case REBALANCING -> 1;
case PENDING_SHUTDOWN -> 3;
case NOT_RUNNING -> 4;
case ERROR -> 5;
default -> -1;
};
};
Additional resources
When you find this feature useful I would like to provide an implementation implementation.