From fc511b632f679e593a2495796b63bdc323948eaa Mon Sep 17 00:00:00 2001 From: Markus Wiegand Date: Sat, 23 Jan 2021 23:39:02 +0100 Subject: [PATCH] add configurable latency threshold --- model/api/health.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/model/api/health.go b/model/api/health.go index 250f5f0..535cdb4 100644 --- a/model/api/health.go +++ b/model/api/health.go @@ -2,11 +2,28 @@ package api import ( "context" + "log" + "os" "time" "github.com/tarkov-database/rest-api/core/database" ) +var latencyThreshold time.Duration + +func init() { + if env := os.Getenv("UNHEALTHY_LATENCY"); len(env) > 0 { + d, err := time.ParseDuration(env) + if err != nil { + log.Printf("Unhealthy latency value is not valid: %s\n", err) + os.Exit(2) + } + latencyThreshold = d + } else { + latencyThreshold = 300 * time.Millisecond + } +} + // Status represents the status code of a service type Status int @@ -66,7 +83,7 @@ func getDatabaseStatus() (Status, error) { return Failure, err } - if time.Since(start).Seconds() > 3 { + if time.Since(start) > latencyThreshold { return Warning, nil }