fix: Correct version check and refactor healthz check (#609)
This commit is contained in:
+15
-1
@@ -94,7 +94,21 @@ func (w *worker) handleStatus(c *gin.Context) {
|
||||
}
|
||||
|
||||
func (w *worker) handleHealthz(c *gin.Context) {
|
||||
c.Status(w.healthz())
|
||||
status := w.status()
|
||||
|
||||
if status.Origin.Status != "success" {
|
||||
c.Status(http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
|
||||
for _, replica := range status.Replicas {
|
||||
if replica.Status != "success" {
|
||||
c.Status(http.StatusServiceUnavailable)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
c.Status(http.StatusOK)
|
||||
}
|
||||
|
||||
func (w *worker) listenAndServe() {
|
||||
|
||||
+1
-24
@@ -3,7 +3,6 @@ package sync
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"sort"
|
||||
"time"
|
||||
@@ -21,10 +20,7 @@ import (
|
||||
"github.com/bakito/adguardhome-sync/version"
|
||||
)
|
||||
|
||||
var (
|
||||
l = log.GetLogger("sync")
|
||||
fixVersionCompareRegExp = regexp.MustCompile(`[^0-9.]`)
|
||||
)
|
||||
var l = log.GetLogger("sync")
|
||||
|
||||
// Sync config from origin to replica.
|
||||
func Sync(cfg *types.Config) error {
|
||||
@@ -124,22 +120,6 @@ func (w *worker) status() *syncStatus {
|
||||
return syncStatus
|
||||
}
|
||||
|
||||
func (w *worker) healthz() int {
|
||||
status := w.status()
|
||||
|
||||
if status.Origin.Status != "success" {
|
||||
return 503
|
||||
}
|
||||
|
||||
for _, replica := range status.Replicas {
|
||||
if replica.Status != "success" {
|
||||
return 503
|
||||
}
|
||||
}
|
||||
|
||||
return 200
|
||||
}
|
||||
|
||||
func (w *worker) getStatus(inst types.AdGuardInstance) replicaStatus {
|
||||
st := replicaStatus{Host: inst.WebHost, URL: inst.WebURL}
|
||||
|
||||
@@ -313,9 +293,6 @@ func (w *worker) syncTo(l *zap.SugaredLogger, o *origin, replica types.AdGuardIn
|
||||
return
|
||||
}
|
||||
|
||||
replicaStatus.Version = fixVersionCompareRegExp.ReplaceAllString(replicaStatus.Version, "")
|
||||
o.status.Version = fixVersionCompareRegExp.ReplaceAllString(o.status.Version, "")
|
||||
|
||||
rl.With("version", replicaStatus.Version).Info("Connected to replica")
|
||||
|
||||
if versions.IsNewerThan(versions.MinAgh, replicaStatus.Version) {
|
||||
|
||||
Reference in New Issue
Block a user