Skip to content

Commit

Permalink
feat: added health check (#14) (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
adubovik authored Oct 30, 2023
1 parent 48393a3 commit b3ebbb7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.gradle/
.idea/
build/
.vscode/
build/
bin/
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ ENV AIDIAL_SETTINGS=/app/config/aidial.settings.json
ENV JAVA_OPTS="-Dgflog.config=/app/config/gflog.xml"
WORKDIR /app

RUN adduser -u 1001 --disabled-password --gecos "" appuser
RUN adduser -u 1001 --disabled-password --gecos "" appuser

COPY --from=builder --chown=appuser:appuser /build/ .
COPY --chown=appuser:appuser ./config/* /app/config/
RUN mkdir /app/log && chown -R appuser:appuser /app

USER appuser

HEALTHCHECK --start-period=30s --interval=1m --timeout=3s \
CMD wget --no-verbose --spider --tries=1 http://localhost:80/health || exit 1

EXPOSE 8080 9464
ENTRYPOINT ["/app/bin/aidial-core"]
9 changes: 9 additions & 0 deletions src/main/java/com/epam/aidial/core/Proxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Objects;

@Slf4j
@Getter
@RequiredArgsConstructor
public class Proxy implements Handler<HttpServerRequest> {

public static final String HEALTH_CHECK_PATH = "/health";

public static final String HEADER_API_KEY = "API-KEY";
public static final String HEADER_JOB_TITLE = "X-JOB-TITLE";
public static final String HEADER_CONVERSATION_ID = "X-CONVERSATION-ID";
Expand Down Expand Up @@ -76,6 +80,11 @@ private Future<?> handleRequest(HttpServerRequest request) throws Exception {
return respond(request, HttpStatus.REQUEST_ENTITY_TOO_LARGE, "Request body is too large");
}

String path = URLDecoder.decode(request.path(), StandardCharsets.UTF_8);
if (request.method() == HttpMethod.GET && path.equals(HEALTH_CHECK_PATH)) {
return respond(request, HttpStatus.OK);
}

String apiKey = request.headers().get(HEADER_API_KEY);
if (apiKey == null) {
return respond(request, HttpStatus.UNAUTHORIZED, "Missing API-KEY header");
Expand Down

0 comments on commit b3ebbb7

Please sign in to comment.