Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Health Checks

Stephen Jung edited this page Mar 6, 2015 · 7 revisions

p2 can run healthchecks to monitor the status of each pod. To opt into this behavior, some launchable in your pod needs to expose a /_status HTTPS endpoint. p2 will issue a GET request to this endpoint every 5 seconds (might be configurable in the future). If it gets a 200 response, the pod is considered healthy. Any other response is unhealthy.

p2 needs to know the port that hosts the /_status endpoint. This comes from your pod manifest:

id: carsales.com
status_port: 8001
launchables:
  web:
    launchable_type: hoist
    launchable_id: web
    location: foo.tar.gz

This tells p2 that the /_status endpoint is on port 8001.

A single pod may have several launchables, but p2 does not care which launchable provides the /_status endpoint. The healthcheck applies to the entire pod. The launchable that hosts the endpoint can check the status of the other launchables, if your application requires it.

HTTPS and HTTP in Health Checks

By default, health checks use HTTPS with the default CA certificate bundle on the host machine. You can switch to HTTP by setting the top-level status_http key to true.

Alternatively, if your health check is served using a different CA certificate, you can specify that certificate in the preparer's configuration using the ca_path key. Refer to the preparer configuration for more details. Remember that health checking is implemented as a Consul feature, so the certificate must be readable by the Consul agent.

Testing Health Checks

If you want to test the health checking behavior of p2, you can use this simple Go application. All it does is respond to the /_status endpoint.

// isup.go
package main

import (
	"fmt"
	"net/http"
	"os"
)

func main() {
	http.HandleFunc("/_status", func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "%v\n%v\n", os.Args, os.Environ())
	})
	http.ListenAndServe(":8040", nil)
}

Compile this go application (go build isup.go) and convert it into a pod (p2-bin2pod isup). This will also generate a pod manifest isup.yaml. Set the manifest's status_portto 8040, then p2-schedule isup.yaml to launch it on your local p2-preparer.

Once you've scheduled the manifest, you can ask consul about the status of its health check like so:

$ p2-inspect --pod isup | python -m json.tool
{
    "isup": {
        "aws1.example.com": {
            "health_check": {
                "output": "[/data/pods/isup/isup/installs/isup_vsjlzlxvnkizuxmkutqmkqhwukyryztuxhusnkpm/bin/launch]\n[PATH=/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/sbin:/sbin:/bin TERM=linux RUNLEVEL=3 PREVLEVEL=N UPSTART_EVENTS=runlevel UPSTART_JOB=runit UPSTART_INSTANCE= CONFIG_PATH=/data/pods/isup/config/isup_717cc0d58df240e2668c865cdc063d715446e6db09ad4b64f7a2f0f4e361ea8f.yaml]\n",
                "status": "passing"
            },
            "intent_manifest_sha": "717cc0d58df240e2668c865cdc063d715446e6db09ad4b64f7a2f0f4e361ea8f",
            "reality_manifest_sha": "717cc0d58df240e2668c865cdc063d715446e6db09ad4b64f7a2f0f4e361ea8f"
        }
    }
}

You can also see that the HTTP response from the /_status endpoint is saved in Consul for debugging purposes.

Clone this wiki locally