From f771383c4b9c4a7d3debbf3b674f3300fcbd7757 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 16 Sep 2021 12:09:12 +0200 Subject: [PATCH] cmd: fix outpost metrics not being set in embedded mode Signed-off-by: Jens Langhammer --- .github/workflows/ci-main.yml | 1 + cmd/server/main.go | 1 + internal/outpost/ak/api.go | 14 +++++++------- internal/web/metrics.go | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci-main.yml b/.github/workflows/ci-main.yml index 19ed3a670..03488b9fe 100644 --- a/.github/workflows/ci-main.yml +++ b/.github/workflows/ci-main.yml @@ -133,6 +133,7 @@ jobs: python-version: '3.9' - name: checkout stable run: | + git fetch # Copy current, latest config to local cp authentik/lib/default.yml local.env.yml git checkout $(git describe --abbrev=0 --match 'version/*') diff --git a/cmd/server/main.go b/cmd/server/main.go index e93ab1c93..91277a0f1 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -106,6 +106,7 @@ func attemptProxyStart(ws *web.WebServer, u *url.URL) { log.WithField("logger", "authentik").Debug("attempting to start outpost") err := ac.StartBackgorundTasks() if err != nil { + log.WithField("logger", "authentik").WithError(err).Warning("outpost failed to start") attempt += 1 time.Sleep(15 * time.Second) if attempt > maxTries { diff --git a/internal/outpost/ak/api.go b/internal/outpost/ak/api.go index 319841350..21b12b32b 100644 --- a/internal/outpost/ak/api.go +++ b/internal/outpost/ak/api.go @@ -94,13 +94,6 @@ func NewAPIController(akURL url.URL, token string) *APIController { // Start Starts all handlers, non-blocking func (a *APIController) Start() error { - OutpostInfo.With(prometheus.Labels{ - "outpost_name": a.Outpost.Name, - "outpost_type": a.Server.Type(), - "uuid": a.instanceUUID.String(), - "version": constants.VERSION, - "build": constants.BUILD(), - }).Set(1) err := a.StartBackgorundTasks() if err != nil { return err @@ -131,6 +124,13 @@ func (a *APIController) OnRefresh() error { } func (a *APIController) StartBackgorundTasks() error { + OutpostInfo.With(prometheus.Labels{ + "outpost_name": a.Outpost.Name, + "outpost_type": a.Server.Type(), + "uuid": a.instanceUUID.String(), + "version": constants.VERSION, + "build": constants.BUILD(), + }).Set(1) err := a.OnRefresh() if err != nil { return errors.Wrap(err, "failed to run initial refresh") diff --git a/internal/web/metrics.go b/internal/web/metrics.go index 0d71197a1..29489c55e 100644 --- a/internal/web/metrics.go +++ b/internal/web/metrics.go @@ -22,7 +22,7 @@ var ( func RunMetricsServer() { m := mux.NewRouter() m.Path("/metrics").HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { - defer promhttp.InstrumentMetricHandler( + promhttp.InstrumentMetricHandler( prometheus.DefaultRegisterer, promhttp.HandlerFor(prometheus.DefaultGatherer, promhttp.HandlerOpts{ DisableCompression: true, }),