Biswajit
Biswajit

Reputation: 169

Prometheus endpoint not exposed when running spring boot application inside docker container

I have a simple spring boot application with a single endpoint which returns hello. Dependencies in pom.xml as follows

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

with application properties as below

spring:
  application:
    name: app1

server:
  port: 9091

management:
  endpoints:
    web:
      base-path: /actuator
      exposure:
        include: health,prometheus,info,metrics
  endpoint:
    health:
      show-details: always
    metrics:
      enabled: true
    prometheus:
      enabled: true

logging:
  level:
    org.springframework.web.filter.CommonsRequestLoggingFilter: DEBUG

when run locally, the actuator endpoint exposed the prometheus metrics correctly

/actuator endpoint when runnign spring boot application locally

However when i run the same application inside a docker container, the prometheus metrics are not exposed

Following is my docker file

FROM eclipse-temurin:17-jdk-jammy as builder
WORKDIR /opt/app
COPY .mvn/ .mvn
COPY mvnw pom.xml ./
RUN ./mvnw dependency:go-offline
COPY ./src ./src
RUN ./mvnw clean install

FROM eclipse-temurin:17-jre-jammy
WORKDIR /opt/app
EXPOSE 9091
COPY --from=builder /opt/app/target/*.jar /opt/app/*.jar
ENTRYPOINT ["java", "-jar", "/opt/app/*.jar" ]

run command docker run -p 9091:9091 app1:latest produces

enter image description here

why are the prometheus sub-endpoints not exposed on the actuator endpoint when running inside docker? Can someple please help me with what am I missing

Upvotes: 0

Views: 859

Answers (1)

Biswajit
Biswajit

Reputation: 169

it turns out the actuator profile needs to be set explicitly in spring boot for dockr to expose them

Upvotes: 0

Related Questions