Adding build data to /application/info

One of the biggest issues in getting to the heart of problems is knowing what version is running! Have you ever gotten a 3:00 a.m. call from a customer reporting that the system is broken? In a half-awake state, it's easy to start trying to solve the problem only to discover two hours later, the customer is running an older version and that their issue was patched last week.

The solution is embedding precise versions in every release so that the customer can relay this over the phone. Then, we can quickly figure out if this issue is new, fixed, or a regression. Interested?

Just add this to the build.gradle file, right below the buildscripts section:

    id "com.gorylenko.gradle-git-properties" version "1.4.17" 

This will add a new task, generateGitProperties, to our system. Anytime we engage Gradle to build the app, whether it's to package up a runnable JAR or simply to bootRun it, a new build/resources/main/git.properties file will be generated and served up via Spring Boot Actuator's /application/info endpoint:

    {
        git: {
            commit: {
                time: 1474434957000,
                id: "3ac9c1c"
            },
            branch: "master"
        }
    }  

This report gives us the timestamp, git commit hash, and branch. That tiny nugget of knowledge has the potential to save us hours of effort over the long haul.

Using Maven? There is a similar plugin:

    <build> 
        <plugins> 
            <plugin> 
                <groupId>pl.project13.maven</groupId> 
                <artifactId>git-commit-id-plugin</artifactId> 
            </plugin> 
        </plugins> 
    </build> 

It works the same.

One extra tidbit--Spring Boot has two different modes of git information. The format shown is the SIMPLE mode. To get more details, add this to application.properties:

    management.info.git.mode=full 

This will produce a much more detailed report:

    {
        git: {
            commit: {
                message: {
                    full: "Move images back to 1/image",
                    short: "Move images back to 1/image"
                },
                time: 1474434957000,
                id: "3ac9c1c7875d7378d6fbd607d0af5ef206e21ede",
                id.abbrev: "3ac9c1c",
                user: {
                    email: "[email protected]",
                    name: "Greg Turnquist"
                }
            },
            branch: "master"
        }
    }  

It's up to each team to decide which version is the most useful and which version doesn't leak out unnecessary details.

Additionally, we can grab more details about the build by adding this to our build.gradle file:

    springBoot { 
      buildInfo() 
    } 

This little addition, when we run Gradle's build task, will add a build-info.properties file to our JAR file, showing content like this:

    #Properties
    #Tue Sep 12 23:53:05 CDT 2017
    build.time=2017-09-12T23:53:05-0500
    build.artifact=5/part2
    build.group=learning-spring-boot
    build.name=5/part2
    build.version=unspecified  

Both of these reports (a simple git report + build info details) would give us this nice bit of information useful to start debugging an issue by visiting localhost:8080/application/info.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.163.197