0

I have a Spring boot application with Prometheus Pushgateway using Micrometer, mainly based on this tutorial: https://luramarchanjo.tech/2020/01/05/spring-boot-2.2-and-prometheus-pushgateway-with-micrometer.html

pom.xml has following related dependencies:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-core</artifactId>
</dependency>
<dependency>
    <groupId>io.micrometer</groupId>
    <artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient_pushgateway</artifactId>
    <version>0.16.0</version>
</dependency>

And application.properties file has:

management.metrics.export.prometheus.pushgateway.enabled=false
management.metrics.export.prometheus.pushgateway.shutdown-operation=PUSH
management.metrics.export.prometheus.pushgateway.baseUrl=localhost:9091

It is working fine locally in Dev environment while connecting to Pushgateway without any authentication. In our CI environment, Prometheus Pushgateway has basic auth enabled. How do I configure Basic auth credentials in this Spring boot application?

adesai
  • 370
  • 3
  • 22

1 Answers1

0

It seems neither Spring Boot's auto-configuration not Prometheus' PushGateway supports providing credentials directly.

I think you can do two things:

  1. I'm not sure if it is supported in the HTTP client but some does/did support passing credentials in the url that will be translated to headers: https://serverfault.com/a/371918
  2. You can also create your own PrometheusPushGatewayManager bean and call setConnectionFactory on the PushGateway instance with a factory that has the creds before you pass the PushGateway to the ctor of PrometheusPushGatewayManager.
Jonatan Ivanov
  • 4,895
  • 2
  • 15
  • 30
  • Thanks for the response @Jonatan. I have already tried 1. and still gets 401. Regarding No 2., once I create my custom`PrometheusPushGatewayManager`, how can I set that bean so that Spring AOP can use it? – adesai Aug 30 '22 at 11:32
  • I'm not sure what you want to do with Spring AOP. Read the Spring Boot docs and see how to create a @Bean, once you have one, Spring will use yours. – Jonatan Ivanov Aug 30 '22 at 19:52
  • I meant actuator. Getting the bean is easy, the trouble is bean for `PrometheusPushGatewayManager` is created under static class `PrometheusPushGatewayConfiguration` under `PrometheusMetricsExportAutoConfiguration`. – adesai Sep 01 '22 at 13:33