feat: Added more debug logging
Chart Release / chart (push) Successful in 16s
Server Deploy / deploy (push) Successful in 7m1s

This commit is contained in:
2026-08-25 13:26:23 +00:00
parent e5947489e4
commit 3e4ccc9720
4 changed files with 42 additions and 10 deletions
+28 -7
View File
@@ -2,6 +2,7 @@ package api
import (
"errors"
"log"
"net/http"
"strconv"
"time"
@@ -79,17 +80,24 @@ func RateLimitPublicStatus() gin.HandlerFunc {
// @Failure 404 {object} ErrorResponse
// @Failure 429 {object} ErrorResponse
func getPublicStatusPage(c *gin.Context) {
pageID := c.Param("pageId")
inst, ok := publicStatusInstance(c)
if !ok {
// Every 404 on this route is indistinguishable to the caller by
// design, so the log is the only place the three reasons are told
// apart. It carries no monitor data and no page contents.
log.Printf("public status: 404 page=%q reason=no_instance", pageID)
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
return
}
snap, err := services.PublicStatusSnapshot(inst.InstanceID, c.Param("pageId"))
snap, err := services.PublicStatusSnapshot(inst.InstanceID, pageID)
if errors.Is(err, services.ErrPageNotFound) {
log.Printf("public status: 404 page=%q instance=%s reason=page_missing_or_unpublished", pageID, inst.InstanceID)
c.JSON(http.StatusNotFound, gin.H{"error": "not found"})
return
}
if err != nil {
log.Printf("public status: 500 page=%q instance=%s: %v", pageID, inst.InstanceID, err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "internal error"})
return
}
@@ -114,21 +122,34 @@ func getPublicStatusPage(c *gin.Context) {
// without this every self-hosted status page 404s forever. More than one is a
// refusal rather than a guess.
func publicStatusInstance(c *gin.Context) (*models.Instance, bool) {
// Host resolution is where this route fails silently: an untrusted peer
// means X-Forwarded-Host is ignored and the request host is the Go
// service's own name, which names no slug. Log the inputs and the branch
// taken, so the 404 says which of the four it was.
host := c.Request.Host
if trustedPeer(c) {
if h := firstForwarded(c.GetHeader("X-Forwarded-Host")); h != "" {
host = h
}
xfh := firstForwarded(c.GetHeader("X-Forwarded-Host"))
trusted := trustedPeer(c)
if trusted && xfh != "" {
host = xfh
}
log.Printf("public status: resolve peer=%s trusted=%t request_host=%q x_forwarded_host=%q using_host=%q slug=%q",
c.RemoteIP(), trusted, c.Request.Host, xfh, host, auth.HostSlug(host))
if inst, ok := auth.InstanceForHost(host); ok {
return inst, true
}
if auth.HostSlug(host) != "" {
if slug := auth.HostSlug(host); slug != "" {
// The host named an instance and that instance does not exist.
log.Printf("public status: no instance for slug=%q (host=%q)", slug, host)
return nil, false
}
if services.DeploymentMode() == license.DeploymentCloud {
log.Printf("public status: host %q names no slug and deployment is cloud, refusing to guess", host)
return nil, false
}
return auth.SoleInstance()
inst, ok := auth.SoleInstance()
if !ok {
log.Printf("public status: host %q names no slug and this deployment has no single instance", host)
}
return inst, ok
}
@@ -405,6 +405,7 @@ func unavailableSnapshot(reason, title string) *StatusSnapshot {
// unpublished" would confirm it exists.
func PublicStatusSnapshot(instanceID, pageID string) (*StatusSnapshot, error) {
if err := ValidatePageID(pageID); err != nil {
log.Printf("public status: page id %q is not a valid id: %v", pageID, err)
return nil, ErrPageNotFound
}
if snap := cachedSnapshot(instanceID, pageID); snap != nil {
@@ -413,9 +414,11 @@ func PublicStatusSnapshot(instanceID, pageID string) (*StatusSnapshot, error) {
page, err := GetStatusPage(instanceID, pageID)
if err != nil {
log.Printf("public status: instance=%s page=%q lookup: %v", instanceID, pageID, err)
return nil, err
}
if !page.Published {
log.Printf("public status: instance=%s page=%q exists but published=false", instanceID, pageID)
return nil, ErrPageNotFound
}