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
102 stars 35 forks source link

Different management port in spring boot #14

Closed pnowy closed 5 years ago

pnowy commented 5 years ago

I think that in the situation when we have the different management port that default application port we should replace ServicePort to that management port in order scrape metrics correctly. We could assume that in this configuration the prometheus actuator entries will be exposed on the management port and this is appropriate instance port to scrape metrics from. What do you think about that?

Example API response:

[{
    Address: "10.52.9.78",
    Node: "my-app-api",
    ServiceAddress: "10.52.9.78",
     ServiceID: "my-app-api-6b55bc559b-7bqfj:my-app-api:8080",
    ServicePort: 8080,
    NodeMeta: {
         jmx.port: "9999",
         management.port: "7777"
    },
    ServiceTags: [ ]
}]
tine2k commented 5 years ago

Hi pnowy, I recommend to supply your own InstanceInfoMapper on the Eureka server for this use case. I explicitly made this bean a @ConditionalOnMissingBean, so one can easily use a custom implementation. This is also the way to go if you want to set service tags based on your node metadata.

pnowy commented 5 years ago

Hi @tine2k, thanks for pointing this out!

rmie commented 5 years ago

I was just about filing a issue with the sample configuration, that could be easily improved to support this use case as well:

It is possible to relabel address like below, to use management.port instead of ServicePort for scraping.

  - source_labels: [__meta_consul_address, __meta_consul_metadata_management_port]
    separator: ':'
    regex: (.*)
    target_label: __address__
    replacement: $1
    action: replace

Note: management.port is provided by default for all services, which makes the above a safe default

pnowy commented 5 years ago

Well, finally I've dropped this adapter and moved to k8s endpoints 👍