cmd/cigocacher: make --stats flag best-effort (#18761)

--auth is already best-effort, but we saw some CI failures due to
failing to fetch stats when cigocached was overwhelmed recently. Make
sure it fails more gracefully in the absence of cigocached like the rest
of cigocacher already does.

Updates tailscale/corp#37059

Change-Id: I0703b30b1c5a7f8c649879a87e6bcd2278610208

Signed-off-by: Tom Proctor <tomhjp@users.noreply.github.com>
main
Tom Proctor 2 months ago committed by GitHub
parent 9acf22f9df
commit 7fb61e1765
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 14
      cmd/cigocacher/cigocacher.go

@ -103,9 +103,19 @@ func main() {
}
stats, err := fetchStats(httpClient(srvHost, *srvHostDial), *srvURL, tk)
if err != nil {
log.Fatalf("error fetching gocached stats: %v", err)
}
// Errors that are not due to misconfiguration are non-fatal so we
// don't fail builds if e.g. cigocached is down.
//
// Print error as JSON so it can still be piped through jq.
statsErr := map[string]any{
"error": fmt.Sprintf("fetching gocached stats: %v", err),
}
b, _ := jsonv1.Marshal(statsErr)
fmt.Println(string(b))
} else {
fmt.Println(stats)
}
return
}

Loading…
Cancel
Save