twinformatics / eureka-consul-adapter

This project contains a Spring Boot Starter that registers HTTP endpoints on a Spring Cloud Eureka server to support Prometheus's service discovery mechanism for Consul (<consul_sd_config>)
MIT License
103 stars 35 forks source link
consul eureka prometheus service-discovery spring spring-boot spring-cloud

Eureka Consul Adapter (for Prometheus)

This project contains a Spring Boot Starter that registers HTTP endpoints on a Spring Cloud Eureka server to support Prometheus's discovery mechanism for Consul ()

Restrictions

This adapter does not support everything of Consul's HTTP API but only those endpoints and attributes that are required for Prometheus' service discovery mechanism.

Functionality

This starter adds the following HTTP endpoints:

Long-polling

Consul HTTP API offers long-polling on some of its endpoints. Prometheus' client uses this functionality to get notified about changes in the registry (i.e. service de-/registrations). Prometheus adds the wait parameter (e.g. http://service-registry/v1/catalog/service/MY-SERVICE?wait=30000ms ), which causes the response to be delayed by specified time passed or returns immediately if the service itself changes within this time range. This behaviour has the benefit, that services changes are detected at once whithout have to wait the whole polling interval. Prometheus opens one long-polling request for each service. In order not to block one thread for each call, this adapter uses the async capabilities of Spring MVC. The default timeout for async requests is by default lower than 30 seconds and can cause AsyncRequestTimeoutExceptions. To prevent this you need to set spring.mvc.async.request-timeout to at least 35000 (35 seconds).

Configuration options

Add the following options to your config (e.g. application.properties), if required.

How to use this starter

Simply add this dependency the your Spring Cloud Eureka Server (https://github.com/spring-cloud-samples/eureka):

Maven

<dependency>
  <groupId>at.twinformatics</groupId>
  <artifactId>eureka-consul-adapter</artifactId>
  <version>${eureka-consul-adapter.version}</version>
</dependency>

Gradle

dependencies {
    compile 'at.twinformatics:eureka-consul-adapter:${eureka-consul-adapter.version}'
}

Requirements

Versions 1.1.x and later

Versions 1.0.x and later

Versions 0.x