GithubHelp home page GithubHelp logo

deviceinsight / kafka-health-check Goto Github PK

View Code? Open in Web Editor NEW
33.0 20.0 15.0 105 KB

Health Check for Apache Kafka

License: Apache License 2.0

Java 100.00%
kafka spring health-check spring-boot-actuator

kafka-health-check's Introduction

Kafka Health Check

Build Status Badge

This library provides a kafka health check for spring boot actuator.

Usage

Add the following dependency to your pom.xml

<dependency>
    <groupId>com.deviceinsight.kafka</groupId>
    <artifactId>kafka-health-check</artifactId>
    <version>1.3.0</version>
</dependency>

In the same maven module you can configure the topic, poll timeouts, subscription timeouts and the receive timeouts in the application.yml

An example for an application.yaml is:

kafka:
  health:
    topic: health-checks
    sendReceiveTimeout: 2.5s
    pollTimeout: 200ms
    subscriptionTimeout: 5s

The values shown are the defaults.

Important
Make sure the configured health check topic exists!
@Bean
@ConfigurationProperties("kafka.health")
public KafkaHealthProperties kafkaHealthProperties() {
    return new KafkaHealthProperties();
}
@Bean
public KafkaConsumingHealthIndicator kafkaConsumingHealthIndicator(KafkaHealthProperties kafkaProperties,
        KafkaProperties processingProperties) {
    return new KafkaConsumingHealthIndicator(kafkaHealthProperties, processingProperties.buildConsumerProperties(),
            processingProperties.buildProducerProperties());
}

Now if you call the actuator endpoint actuator/health you should see the following output:

{
   "status" : "UP",
   "details" : {
      "kafkaConsuming" : {
         "status" : "UP"
      }
   }
}

Configuration

Property Default Description

kafka.health.topic

health-checks

Topic to subscribe to

kafka.health.sendReceiveTimeout

2.5s

The maximum time, given as Duration, to wait for sending and receiving the message.

kafka.health.pollTimeout

200ms

The time, given as Duration, spent fetching the data from the topic

kafka.health.subscriptionTimeout

5s

The maximum time, given as Duration, to wait for subscribing to topic

kafka.health.cache.maximumSize

200

Specifies the maximum number of entries the cache may contain.

Releasing

Creating a new release involves the following steps:

  1. ./mvnw gitflow:release-start gitflow:release-finish

  2. git push origin master

  3. git push --tags

  4. git push origin develop

In order to deploy the release to Maven Central, you need to create an account at https://issues.sonatype.org and configure your account in ~/.m2/settings.xml:

<settings>
  <servers>
    <server>
      <id>ossrh</id>
      <username>your-jira-id</username>
      <password>your-jira-pwd</password>
    </server>
  </servers>
</settings>

The account also needs access to the project on Maven Central. This can be requested by another project member.

Then check out the release you want to deploy (git checkout x.y.z) and run ./mvnw deploy -Prelease.

kafka-health-check's People

Contributors

ezienecker avatar pvorb avatar sflandergan avatar stefan-hudelmaier avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kafka-health-check's Issues

The log statement for a timeout should not print the whole stacktrace

The log statement for a timeout should not print the whole stacktrace

2021-03-09 04:23:14.532  WARN 19 --- [nio-9090-exec-6] c.d.k.h.KafkaConsumingHealthIndicator    : Kafka health check timed out.

java.util.concurrent.TimeoutException: Timeout after waiting for 2500 ms.
	at org.apache.kafka.clients.producer.internals.FutureRecordMetadata.get(FutureRecordMetadata.java:78) ~[kafka-clients-2.5.1.jar!/:na]
	at org.apache.kafka.clients.producer.internals.FutureRecordMetadata.get(FutureRecordMetadata.java:30) ~[kafka-clients-2.5.1.jar!/:na]
	at com.deviceinsight.kafka.health.KafkaConsumingHealthIndicator.sendKafkaMessage(KafkaConsumingHealthIndicator.java:180) ~[kafka-health-check-1.2.0.jar!/:na]
	at com.deviceinsight.kafka.health.KafkaConsumingHealthIndicator.sendMessage(KafkaConsumingHealthIndicator.java:159) ~[kafka-health-check-1.2.0.jar!/:na]
	at com.deviceinsight.kafka.health.KafkaConsumingHealthIndicator.doHealthCheck(KafkaConsumingHealthIndicator.java:187) ~[kafka-health-check-1.2.0.jar!/:na]
	at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:82) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthIndicator.getHealth(HealthIndicator.java:37) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpointWebExtension.getHealth(HealthEndpointWebExtension.java:85) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpointWebExtension.getHealth(HealthEndpointWebExtension.java:44) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:99) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpointSupport.getAggregateHealth(HealthEndpointSupport.java:110) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:96) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:74) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:61) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpointWebExtension.health(HealthEndpointWebExtension.java:71) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.health.HealthEndpointWebExtension.health(HealthEndpointWebExtension.java:60) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at jdk.internal.reflect.GeneratedMethodAccessor105.invoke(Unknown Source) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
	at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) ~[spring-core-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:77) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:60) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$ServletWebOperationAdapter.handle(AbstractWebMvcEndpointHandlerMapping.java:305) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(AbstractWebMvcEndpointHandlerMapping.java:388) ~[spring-boot-actuator-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at jdk.internal.reflect.GeneratedMethodAccessor95.invoke(Unknown Source) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) ~[spring-webmvc-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) ~[spring-webmvc-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.boot.actuate.autoconfigure.web.servlet.CompositeHandlerAdapter.handle(CompositeHandlerAdapter.java:58) ~[spring-boot-actuator-autoconfigure-2.3.7.RELEASE.jar!/:2.3.7.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) ~[spring-webmvc-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:626) ~[tomcat-embed-core-9.0.41.jar!/:4.0.FR]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.12.RELEASE.jar!/:5.2.12.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.41.jar!/:4.0.FR]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:764) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.41.jar!/:9.0.41]
	at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]

Make Health Check more lenient

The health check should be given a period in which to recover. When the endpoint is requested, it should be asked if the time period is set. If the time period is set, you should ask if the time of the request is outside the set time period, only if this is true the health check should return the status down. Note that if the health check is set to Up within the time period, this should be set accordingly.

Upgrade Kafka Clients

Hi,

I ran into a problem with older Kafka Clients (2.0.1) your Spring Boot version is using: Health Check isn't aware of Kafka brokers' IP changes.

2021-02-01 18:46:22.141 - WARN [           ] 21 --- [pool-7-thread-1] o.a.k.c.c.internals.ConsumerCoordinator  : [Consumer clientId=consumer-health-check-XXXXX-15.1.0.162-3, groupId=health-check-XXXXXX-15.1.0.162] Offset commit failed on partition health-checks-3 at offset 134377: The request timed out.

(15.1.0.162 was the IP of an old Kafka pod).

The cause: KAFKA-7755 Kubernetes - Kafka clients are resolving DNS entries only one time, which was fixed in 2.1.1 and 2.2.0+

Could you please upgrade your Spring Boot/Kafka versions?

Make the cache size configurable

To be able to control the cache size better it must be configurable from the outside.

Since the default value of the property server.tomcat.threads.max is 200, this should also be used as the default for the cache size.

The maximum number of request processing threads to be created by this Connector, which therefore determines the maximum number of simultaneous requests that can be handled. If not specified, this attribute is set to 200.

https://tomcat.apache.org/tomcat-8.0-doc/config/http.html

Subscribe error during startup of spring boot application

I am using the default configuration and also created the kafka health check topic manually with command:

kafka-topics.sh --zookeeper 127.0.0.1:2181 --topic health-checks --create --partitions 1 --replication-factor 1

But getting the below error. Any reason as to why we get this:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kafkaConsumingHealthIndicator': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanInitializationException: Subscription to kafka failed, topic=health-checks
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:160) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:415) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1786) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:594) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar:5.2.8.RELEASE]

Checking multiple brokers

Hi all,

Having multiple brokers, using your library, is there any way to check if one of them is down?
Appreciate your help.

Thanks,
Marcelo

Missing Artifact 2.0.0-SNAPSHOT

When i try to use version 2.0.0-SNAPSHOT along with spring-kafka, i get following error message :
Missing artifact com.deviceinsight.kafka:kafka-health-check:jar:2.0.0-SNAPSHOT

Let me know what am I missing here.

Introduce spring boot auto configuration

There should be an auto configuration creating the health check and properties as beans.
The beans should only be created when no bean of same type have been found (conditional bean creation).
The health check properties should be configurable with application properties

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.