Search code examples
spring-bootmicrometerspring-micrometer

programmatically configuration for spring boot micrometer with influxdb


I am facing some challenges while configuring Spring Boot Micrometer for my application. Micrometer documents says we can configure influxdb uri, userName, password, db etc through application.yml file which is working fine for my demo application but for production ready application we are using docker-compose and we are setting all our environment variable through docker-compose. Now I am facing challenges like -

  1. How can I force micrometer to use docker-compose environment variable influxdb uri
  2. For influxdb password, our application stores passwords in AWS secret Manager, how micrometer will access password from secret manager?
  3. Can I configure all this micrometer properties programmatically (Spring Bean)? How?

Solution

  • I'm not sure how to leverage AWS Secret Manager, but for point 1 and 3 I can offer some advice.

    I'm not familiar with Influx specifically, but based on the javadoc it uses management.metrics.export.influx.username to set the password.

    1- To set a application property via an environment variable, set the equivalent using the typical 'SCREAMING_SNAKE_CASE' format:

    MANAGEMENT_METRICS_EXPORT_INFLUX_USERNAME=myInfluxUser
    

    Or if you already have an environment variable that you want to reference in you application.yml file you con reference in as a property:

    management.metrics.export.influx.username: ${INFLUX_USER}
    

    3- To configure Micromerter/influx programatically create a bean on type InfluxProperties:

    @Bean
    public InfluxProperties influxProperties() {
      return new InfluxProperties(); // Programatically set any properties here.
    }