add last_mirror_ts to general stats

This commit is contained in:
2025-04-20 17:21:14 +02:00
parent ad5ce609fc
commit d5f24feb9e
2 changed files with 26 additions and 5 deletions

26
api.go
View File

@@ -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)
}

View File

@@ -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