From d5f24feb9e10e42f50084449e3a371055f60d4ad Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Sun, 20 Apr 2025 17:21:14 +0200 Subject: [PATCH] add last_mirror_ts to general stats --- api.go | 26 +++++++++++++++++++++----- openapi_alhp.yaml | 5 +++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/api.go b/api.go index e3e4919..935e1e1 100644 --- a/api.go +++ b/api.go @@ -5,6 +5,7 @@ import ( "github.com/go-chi/render" log "github.com/sirupsen/logrus" "net/http" + "os" "somegit.dev/ALHP/ALHP.GO/ent" "somegit.dev/ALHP/ALHP.GO/ent/dbpackage" "somegit.dev/ALHP/ALHP.GO/ent/predicate" @@ -14,11 +15,12 @@ import ( ) type StatsResponse struct { - Failed int `json:"failed"` - Skipped int `json:"skipped"` - Latest int `json:"latest"` - Queued int `json:"queued"` - LTO *struct { + Failed int `json:"failed"` + Skipped int `json:"skipped"` + Latest int `json:"latest"` + Queued int `json:"queued"` + LastMirrorTimestamp *int64 `json:"last_mirror_timestamp,omitempty"` + LTO *struct { Enabled int `json:"enabled"` Disabled int `json:"disabled"` Unknown int `json:"unknown"` @@ -93,6 +95,20 @@ func GetStats(w http.ResponseWriter, r *http.Request) { } } + if os.Getenv("ALHP_TIMESTAMP_PATH") != "" { + tsFile, err := os.ReadFile(os.Getenv("ALHP_TIMESTAMP_PATH")) + if err != nil { + log.Warningf("error reading timestamp file: %v", err) + } else { + ts, err := strconv.ParseInt(string(tsFile), 10, 64) + if err != nil { + log.Warningf("error parsing timestamp file: %v", err) + } else { + resp.LastMirrorTimestamp = &ts + } + } + } + render.Status(r, http.StatusOK) render.JSON(w, r, resp) } diff --git a/openapi_alhp.yaml b/openapi_alhp.yaml index 7c87134..8756f77 100644 --- a/openapi_alhp.yaml +++ b/openapi_alhp.yaml @@ -224,6 +224,11 @@ components: format: int64 description: Number of packages currently in the build queue example: 5 + last_mirror_timestamp: + type: integer + format: int64 + description: Latest mirror timestamp to detect outdated mirrors (Unix timestamp) + example: 1702612991 lto: type: object description: LTO status summary across all packages