From e48f7e83b0f25b76eaa6c6b7b70eaf4116f8d4c9 Mon Sep 17 00:00:00 2001 From: Robert Fratto Date: Mon, 10 Jan 2022 17:25:55 -0500 Subject: [PATCH 1/2] operator: fix bug where /-/ready and /-/healthy always returned 404 controller-runtime must have at least one ready/healthy check for the endpoints to exist --- CHANGELOG.md | 3 +++ cmd/agent-operator/main.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 200edf4398a9..54a48a112dfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,9 @@ for detailed information. - [BUGFIX] Fix panic when using 'stdout' in automatic logging (@mapno) +- [BUGFIX] Grafana Agent Operator: The /-/ready and /-/healthy endpoints will + no longer always return 404 (@rfratto). + - [DEPRECATION] The node_exporter integration's `netdev_device_whitelist` field is deprecated in favor of `netdev_device_include`. Support for the old field name will be removed in a future version. (@rfratto) diff --git a/cmd/agent-operator/main.go b/cmd/agent-operator/main.go index aae4009da3cf..0d574b041d45 100644 --- a/cmd/agent-operator/main.go +++ b/cmd/agent-operator/main.go @@ -3,6 +3,7 @@ package main import ( "flag" "fmt" + "net/http" "os" cortex_log "github.com/cortexproject/cortex/pkg/util/log" @@ -33,6 +34,9 @@ func main() { os.Exit(1) } + m.AddReadyzCheck("running", func(req *http.Request) error { return nil }) + m.AddHealthzCheck("running", func(req *http.Request) error { return nil }) + if err := operator.New(logger, cfg, m); err != nil { level.Error(logger).Log("msg", "unable to create operator", "err", err) os.Exit(1) From dd32fe0613b32cc13fe29a7703febc756e7c0987 Mon Sep 17 00:00:00 2001 From: Robert Fratto Date: Tue, 11 Jan 2022 14:48:49 -0500 Subject: [PATCH 2/2] fix lint error, use healthz.Ping --- cmd/agent-operator/main.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/agent-operator/main.go b/cmd/agent-operator/main.go index 0d574b041d45..09d0d0f9bcc0 100644 --- a/cmd/agent-operator/main.go +++ b/cmd/agent-operator/main.go @@ -3,7 +3,6 @@ package main import ( "flag" "fmt" - "net/http" "os" cortex_log "github.com/cortexproject/cortex/pkg/util/log" @@ -13,6 +12,7 @@ import ( "github.com/grafana/agent/pkg/operator/logutil" "github.com/prometheus/common/version" controller "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/healthz" // Needed for clients. _ "k8s.io/client-go/plugin/pkg/client/auth" @@ -34,8 +34,12 @@ func main() { os.Exit(1) } - m.AddReadyzCheck("running", func(req *http.Request) error { return nil }) - m.AddHealthzCheck("running", func(req *http.Request) error { return nil }) + if err := m.AddReadyzCheck("running", healthz.Ping); err != nil { + level.Warn(logger).Log("msg", "failed to set up 'running' readyz check", "err", err) + } + if err := m.AddHealthzCheck("running", healthz.Ping); err != nil { + level.Warn(logger).Log("msg", "failed to set up 'running' healthz check", "err", err) + } if err := operator.New(logger, cfg, m); err != nil { level.Error(logger).Log("msg", "unable to create operator", "err", err)