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 health/ready endpoints #116

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/java/io/prometheus/cloudwatch/HealthServlet.java
@@ -0,0 +1,15 @@
package io.prometheus.cloudwatch;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class HealthServlet extends HttpServlet {

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
resp.setContentType("text/html");
resp.getWriter().print("OK");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't valid HTML.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair, i took inspiration from the prometheus health endpoint, which I don't believe is valid html either... would:

<html>ok</html>

be sufficient?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Switching to text/plain is simplest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess to be html valid it'd have to be:

<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>cloudwatch exporter</title>
</head>
<body>ok
</body>
</html>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, i'm not a smart man :)

}
}
2 changes: 2 additions & 0 deletions src/main/java/io/prometheus/cloudwatch/WebServer.java
Expand Up @@ -33,6 +33,8 @@ public static void main(String[] args) throws Exception {
server.setHandler(context);
context.addServlet(new ServletHolder(new MetricsServlet()), "/metrics");
context.addServlet(new ServletHolder(new DynamicReloadServlet(collector)), "/-/reload");
context.addServlet(new ServletHolder(new HealthServlet()), "/-/healthy");
context.addServlet(new ServletHolder(new HealthServlet()), "/-/ready");
context.addServlet(new ServletHolder(new HomePageServlet()), "/");
server.start();
server.join();
Expand Down