diff --git a/cmd/controller/main.go b/cmd/controller/main.go index cf2ef5ba7..09ed4e3e5 100644 --- a/cmd/controller/main.go +++ b/cmd/controller/main.go @@ -14,7 +14,6 @@ import ( "github.com/stefanprodan/steerer/pkg/logging" "github.com/stefanprodan/steerer/pkg/server" "github.com/stefanprodan/steerer/pkg/version" - "go.uber.org/zap" "k8s.io/client-go/kubernetes" _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" "k8s.io/client-go/tools/cache" @@ -73,16 +72,21 @@ func main() { rolloutInformerFactory := informers.NewSharedInformerFactory(rolloutClient, time.Second*30) rolloutInformer := rolloutInformerFactory.Apps().V1beta1().Rollouts() + logger.Infof("Starting steerer version %s revision %s", version.VERSION, version.REVISION) + ver, err := kubeClient.Discovery().ServerVersion() if err != nil { logger.Fatalf("Error calling Kubernetes API: %v", err) } - logger.Infow("Starting steerer", - zap.String("version", version.VERSION), - zap.String("revision", version.REVISION), - zap.String("metrics provider", metricsServer), - zap.Any("kubernetes version", ver)) + logger.Infof("Connected to Kubernetes API %s", ver) + + ok, err := controller.CheckMetricsServer(metricsServer) + if ok { + logger.Infof("Connected to metrics server %s", metricsServer) + } else { + logger.Errorf("Metrics server %s unreachable %v", metricsServer, err) + } // start HTTP server go server.ListenAndServe(port, 3*time.Second, logger, stopCh) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 0bb26d7c0..12f43cc3c 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -158,7 +158,6 @@ func (c *Controller) processNextWorkItem() bool { // Finally, if no error occurs we Forget this item so it does not // get queued again until another change happens. c.workqueue.Forget(obj) - c.logger.Infof("Successfully synced '%s'", key) return nil }(obj) diff --git a/pkg/controller/observer.go b/pkg/controller/observer.go index 6cfd8c77a..8956c534e 100644 --- a/pkg/controller/observer.go +++ b/pkg/controller/observer.go @@ -66,7 +66,6 @@ func (c *Controller) queryMetric(query string) (*VectorQueryResponse, error) { } return &values, nil - } func (c *Controller) getDeploymentMetric(name string, namespace string, counter string, interval string) (float64, error) { @@ -97,3 +96,42 @@ func (c *Controller) getDeploymentMetric(name string, namespace string, counter } return rate, nil } + +func CheckMetricsServer(address string) (bool, error) { + promURL, err := url.Parse(address) + if err != nil { + return false, err + } + + u, err := url.Parse("./api/v1/status/flags") + if err != nil { + return false, err + } + + u = promURL.ResolveReference(u) + + req, err := http.NewRequest("GET", u.String(), nil) + if err != nil { + return false, err + } + + ctx, cancel := context.WithTimeout(req.Context(), 5*time.Second) + defer cancel() + + r, err := http.DefaultClient.Do(req.WithContext(ctx)) + if err != nil { + return false, err + } + defer r.Body.Close() + + b, err := ioutil.ReadAll(r.Body) + if err != nil { + return false, fmt.Errorf("error reading body: %s", err.Error()) + } + + if 400 <= r.StatusCode { + return false, fmt.Errorf("error response: %s", string(b)) + } + + return true, nil +}