mirror of
https://github.com/prymitive/karma
synced 2026-05-05 03:16:51 +00:00
Merge pull request #1156 from prymitive/health
feat(backend): add /health endpoint for healthcheck probes
This commit is contained in:
@@ -194,6 +194,11 @@ apply as with `make run`. Example:
|
||||
|
||||
make PORT=5000 ALERTMANAGER_URI=https://alertmanager.example.com run-docker
|
||||
|
||||
### Health checks
|
||||
|
||||
`/health` endpoint can be used for health check probes, it always responds with
|
||||
`200 OK` code and `Pong` response body.
|
||||
|
||||
## Configuration
|
||||
|
||||
Please see [CONFIGURATION](/docs/CONFIGURATION.md) for full list of available
|
||||
|
||||
@@ -98,6 +98,7 @@ func setupRouter(router *gin.Engine) {
|
||||
}))
|
||||
|
||||
router.GET(getViewURL("/"), index)
|
||||
router.GET(getViewURL("/health"), pong)
|
||||
router.GET(getViewURL("/alerts.json"), alerts)
|
||||
router.GET(getViewURL("/autocomplete.json"), autocomplete)
|
||||
router.GET(getViewURL("/labelNames.json"), knownLabelNames)
|
||||
|
||||
@@ -33,6 +33,10 @@ func noCache(c *gin.Context) {
|
||||
c.Header("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||
}
|
||||
|
||||
func pong(c *gin.Context) {
|
||||
c.String(200, "Pong")
|
||||
}
|
||||
|
||||
func compressResponse(data []byte) ([]byte, error) {
|
||||
var b bytes.Buffer
|
||||
gz, err := gzip.NewWriterLevel(&b, 3)
|
||||
|
||||
@@ -49,6 +49,30 @@ func ginTestEngine() *gin.Engine {
|
||||
return r
|
||||
}
|
||||
|
||||
func TestHealth(t *testing.T) {
|
||||
mockConfig()
|
||||
r := ginTestEngine()
|
||||
req := httptest.NewRequest("GET", "/health", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
r.ServeHTTP(resp, req)
|
||||
if resp.Code != http.StatusOK {
|
||||
t.Errorf("GET /health returned status %d", resp.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHealthPrefix(t *testing.T) {
|
||||
os.Setenv("LISTEN_PREFIX", "/prefix")
|
||||
defer os.Unsetenv("LISTEN_PREFIX")
|
||||
mockConfig()
|
||||
r := ginTestEngine()
|
||||
req := httptest.NewRequest("GET", "/prefix/health", nil)
|
||||
resp := httptest.NewRecorder()
|
||||
r.ServeHTTP(resp, req)
|
||||
if resp.Code != http.StatusOK {
|
||||
t.Errorf("GET /prefix/health returned status %d", resp.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndex(t *testing.T) {
|
||||
mockConfig()
|
||||
r := ginTestEngine()
|
||||
|
||||
Reference in New Issue
Block a user