Spring Actuator /info returns an empty body
Asked Answered
S

4

13

How to add custom metrics to /info endpoint in Spring Boot 2.7.0 Actuator?

pom.xml

<version>0.0.1-SNAPSHOT</version>
...
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>2.7.0</version>
</dependency>

Currently have the following related to actuator.

application.properties

[email protected]@

management.endpoint.info.enabled=true
management.endpoints.web.exposure.include=info,health

I have verified that the info.app.version property can be retrieved using @Value. But despite this I am only getting an empty response on /info.

Response header:

< HTTP/1.1 200 
< X-Content-Type-Options: nosniff
< X-XSS-Protection: 1; mode=block
< Cache-Control: no-cache, no-store, max-age=0, must-revalidate
< Pragma: no-cache
< Expires: 0
< X-Frame-Options: DENY
< Content-Type: application/vnd.spring-boot.actuator.v3+json
< Transfer-Encoding: chunked
< Date: Wed, 15 Jun 2022 04:12:47 GMT


* Received 7 B chunk
* Received 5 B chunk
* Connection #26 to host localhost left intact

Response body :

{}

My understanding is any property under info is included in /info endpoint. Or does this not work on actuator v2+ ? Source

Showiness answered 15/6, 2022 at 4:24 Comment(0)
S
24

From Spring Boot 2.6 Release Notes - Actuator Env InfoContributor Disabled by Default

You need to enable the info env property:

management.info.env.enabled=true
Soprano answered 15/6, 2022 at 9:47 Comment(0)
M
8

Latest spring boot requires two things to be set up:

1- exposing the endpoint in application.properties file:

management.endpoints.web.exposure.include=info, health

You can use a wildcard and expose all endpoints if you want

management.endpoints.web.exposure.include=*

2- enabling info.env in application.properties:

management.info.env.enabled=true
Mauriciomaurie answered 20/9, 2022 at 9:28 Comment(0)
A
2

Our project includes the git-commit-id-plugin, which puts in the response body of the actuator some data regarding the last commit.

I was running a new Maven project which didn't still have the. git/ folder, therefore the plugin couldn't do its job, and the whole endpoint's response was an empty body. So, include in your checklist the fact that all the contributors to /admin/info/ are correctly configured.

Apathetic answered 28/3, 2023 at 6:11 Comment(0)
G
0

Many things you need analyse. I gonna put bellow all configs that i putted into my projets

At pom.xml file:

Dependency:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <version>YOUR_SERSION</version>
</dependency>

Plugins

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>build-info</id>
            <goals>
                <goal>build-info</goal>
            </goals>
        </execution>
    </executions>
</plugin>

<plugin>
    <groupId>io.github.git-commit-id</groupId>
    <artifactId>git-commit-id-maven-plugin</artifactId>
    <version>5.0.0</version>
    <executions>
        <execution>
            <id>get-the-git-infos</id>
            <goals>
                <goal>revision</goal>
            </goals>
            <phase>initialize</phase>
        </execution>
    </executions>
    <configuration>
        <failOnNoGitDirectory>false</failOnNoGitDirectory>
        <generateGitPropertiesFile>true</generateGitPropertiesFile>
        <generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
        <includeOnlyProperties>
            <includeOnlyProperty>^git.build.user.(name|email)$</includeOnlyProperty>
            <includeOnlyProperty>^git.build.(time|version)$</includeOnlyProperty>
            <includeOnlyProperty>^git.commit.user.name$</includeOnlyProperty>
            <includeOnlyProperty>^git.commit.time.(abbrev|full)$</includeOnlyProperty>
            <includeOnlyProperty>^git.commit.id.(abbrev|full)$</includeOnlyProperty>
            <includeOnlyProperty>^git.branch$</includeOnlyProperty>
            <includeOnlyProperty>^git.build.version$</includeOnlyProperty>
        </includeOnlyProperties>
        <commitIdGenerationMode>full</commitIdGenerationMode>
    </configuration>
</plugin>

At application.yaml file

management:
  info:
    git:
      mode: full
  env:
    enabled: true 
  endpoints:
    web:
      base-path: /actuator
      exposure:
        include: health,prometheus,metrics,info
  endpoint:
    health:
      show-details: always
    metrics:
      metrics:
        enabled: true
      prometheus:
        enabled: true
  metrics:
    tags:
      application: ${spring.application.name}

Pay attention to the environment files that Spring has, for example: application-homolog.yaml, application-production.yaml, as there may be overwriting of these properties in your application.yaml file.

I hope that help you.

Glaciology answered 5/6, 2024 at 12:55 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.