Skip to content

Commit

Permalink
add configurable latency threshold
Browse files Browse the repository at this point in the history
  • Loading branch information
morphy2k committed Jan 23, 2021
1 parent 29482ef commit fc511b6
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion model/api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit fc511b6

Please sign in to comment.