Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hearthbeat endpoint to Ruuter #245

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ COPY gradlew.bat .
COPY gradle gradle
COPY build.gradle .
COPY src src
COPY .env .env

RUN chmod 754 ./gradlew
RUN ./gradlew -Pprod clean bootJar
Expand All @@ -21,6 +22,9 @@ COPY --from=build ${DEPENDENCY}/BOOT-INF/classes /app

ENV application.config-path=/DSL

COPY .env /app/.env
RUN echo BUILDTIME=`date +%s` >> /app/.env

RUN adduser ruuter
RUN mkdir logs
RUN mkdir DSL
Expand All @@ -29,4 +33,5 @@ RUN chown -R ruuter:ruuter /app
RUN chown -R ruuter:ruuter /DSL
USER ruuter


ENTRYPOINT ["java","-cp","app:app/lib/*","ee.buerokratt.ruuter.RuuterApplication"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ee.buerokratt.ruuter.configuration;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;

import java.util.Properties;

@Getter
@Configuration
@PropertySource("classpath:heartbeat.properties")
public class PackageInfoConfiguration {

@Value("${app.name:}")
private String appName;

@Value("${app.version}")
private String version;

@Value("${app.packaging.time:}")
private long packagingTime;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package ee.buerokratt.ruuter.configuration;

import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

@Getter
@Configuration
@PropertySource("file:/app/.env")
public class PackageVersionConfiguration {

@Value("${RELEASE}")
private String release;

@Value("${VERSION}")
private String version;

@Value("${BUILD}")
private String build;

@Value("${FIX}")
private String fix;

@Value("${BUILDTIME}")
private Long buildTime;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ee.buerokratt.ruuter.controller;

import ee.buerokratt.ruuter.domain.HeartBeatInfo;
import ee.buerokratt.ruuter.service.HeartBeatService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor
public class HeartBeatController {
private final HeartBeatService heartBeatService;

@GetMapping("/healthz")
public HeartBeatInfo get() {
return heartBeatService.getData();
}
}
14 changes: 14 additions & 0 deletions src/main/java/ee/buerokratt/ruuter/domain/HeartBeatInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ee.buerokratt.ruuter.domain;

import lombok.Builder;
import lombok.Data;

@Data
@Builder
public class HeartBeatInfo {
private String appName;
private String version;
private long packagingTime;
private long appStartTime;
private long serverTime;
}
53 changes: 53 additions & 0 deletions src/main/java/ee/buerokratt/ruuter/service/HeartBeatService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ee.buerokratt.ruuter.service;

import ee.buerokratt.ruuter.configuration.ApplicationProperties;
import ee.buerokratt.ruuter.configuration.PackageVersionConfiguration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ee.buerokratt.ruuter.configuration.PackageInfoConfiguration;
import ee.buerokratt.ruuter.domain.HeartBeatInfo;

import java.util.Properties;

@Slf4j
@Service
public class HeartBeatService {

private final ServerInfoService serverInfoService;

private final PackageInfoConfiguration packageInfoConfiguration;

private final PackageVersionConfiguration packageVersionConfiguration;

private String version;

public HeartBeatService(ServerInfoService serverInfoService,
PackageInfoConfiguration packageInfoConfiguration,
PackageVersionConfiguration packageVersionConfiguration) {
this.serverInfoService = serverInfoService;
this.packageInfoConfiguration = packageInfoConfiguration;
this.packageVersionConfiguration = packageVersionConfiguration;
}

private String getVersion() {
if (version == null)
version = packageVersionConfiguration.getRelease() + "-" +
packageVersionConfiguration.getVersion() + "." +
packageVersionConfiguration.getBuild() + "." +
packageVersionConfiguration.getFix();
return version;
}


public HeartBeatInfo getData() {
return HeartBeatInfo.builder()
.appName(packageInfoConfiguration.getAppName())
.packagingTime(packageVersionConfiguration.getBuildTime())
.version(getVersion())
.appStartTime(serverInfoService.getStartupTime())
.serverTime(serverInfoService.getServerTime())
.build();
}

}
24 changes: 24 additions & 0 deletions src/main/java/ee/buerokratt/ruuter/service/ServerInfoService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package ee.buerokratt.ruuter.service;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Date;

@Slf4j
@Service
public class ServerInfoService {

@Getter
private final long startupTime;

public ServerInfoService() {
this.startupTime = new Date().getTime();
}

public long getServerTime() {
return new Date().getTime();
}

}
3 changes: 3 additions & 0 deletions src/main/resources/heartbeat.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
app.name=ruuter
app.version=1.0
app.packaging.time=1702552914000