liveBook · Manning

Info endpoint

As explained in Spring in Action, Sixth Edition

The info endpoint is an Actuator interface that exposes application information such as build metadata and version-control commit details.

The Spring Boot Actuator info endpoint answers a basic question about a running application: what is it? Send a GET request to /actuator/info to see its information as JSON. An unconfigured response may be just {}. Unlike the health endpoint, which reports how the application is doing, the info endpoint is a place to publish details you choose. section 15.2.1

info:
  contact:
    email: support@tacocloud.com
    phone: 822-625-6831

Add these properties to application.yml to publish support contact details. Their names have no special meaning beyond the info prefix; the response nests email and phone under contact. section 15.2.1

Properties work well for values you can configure ahead of time. For information that must be calculated, implement Spring Boot’s InfoContributor interface. Its contribute() method receives a Builder; call withDetail() to add a named piece of information to the response. section 15.3.1

Listing 15.3 A custom implementation of InfoContributor
package tacos.actuator;
 
import java.util.HashMap;
import java.util.Map;
 
import org.springframework.boot.actuate.info.Info.Builder;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Component;
 
import tacos.data.TacoRepository;
 
@Component
public class TacoCountInfoContributor implements InfoContributor {
  private TacoRepository tacoRepo;
 
  public TacoCountInfoContributor(TacoRepository tacoRepo) {
    this.tacoRepo = tacoRepo;
  }
 
  @Override
  public void contribute(Builder builder) {
    long tacoCount = tacoRepo.count().block();
    Map<String, Object> tacoMap = new HashMap<String, Object>();
    tacoMap.put("count", tacoCount);
    builder.withDetail("taco-stats", tacoMap);
  }
}

This @Component injects a repository, obtains its count, and publishes it under taco-stats. The repository is reactive, so the example calls block() to obtain the value from its Mono<Long>; the resulting JSON contains taco-stats.count. section 15.3.1

The endpoint can also identify the build and source revision:

  • Configure the Spring Boot Maven plugin’s build-info goal or Gradle’s springBoot { buildInfo() }. The illustrated build response includes the artifact, name, time, version, and group. section 15.3.1
  • Use the illustrated Maven Git commit ID plugin or Gradle Git properties plugin to supply Git information such as branch, commit ID, and commit time. Setting management.info.git.mode to full exposes more commit details than the shorter response. section 15.3.1

Once available, the same information can appear in Spring Boot Admin’s Details screen alongside application health. Decide what to expose before using the endpoint operationally: Actuator web endpoints can be selectively exposed and secured with Spring Security, and full Git details can include a committer’s name and email. section 16.2.1 section 15.5

How Spring in Action, Sixth Edition covers it

How deep it goes
Works through configuration properties and a custom InfoContributor, then shows build and Git configuration without examining endpoint internals.
Examples
Uses support contact properties, a repository-backed count, build and Git JSON responses, and an Admin Details screen.
What it assumes
Assumes a running Spring Boot application and introduces the info property prefix and InfoContributor before using them.
What you can do after
Operate/configure it to publish static, calculated, build, and Git details, then inspect them through HTTP or Spring Boot Admin.
How it connects
Connects Actuator, the health endpoint, InfoContributor, build metadata, Git commit information, and Spring Boot Admin.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.