From b8b7be3f8127e0858c14eda0557ae51f2f897129 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Fri, 22 Jan 2016 15:57:57 -0500 Subject: [PATCH] *: remove health checker --- api/handlers.go | 17 ++++----- database/database.go | 1 + database/pgsql/pgsql.go | 4 ++ health/health.go | 82 ----------------------------------------- notifier/notifier.go | 9 ----- updater/updater.go | 21 ----------- 6 files changed, 13 insertions(+), 121 deletions(-) delete mode 100644 health/health.go diff --git a/api/handlers.go b/api/handlers.go index b8848852..3a6b0624 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -21,7 +21,6 @@ import ( "github.com/julienschmidt/httprouter" "github.com/coreos/clair/database" - "github.com/coreos/clair/health" httputils "github.com/coreos/clair/utils/http" "github.com/coreos/clair/worker" ) @@ -47,14 +46,14 @@ func GETVersions(w http.ResponseWriter, r *http.Request, _ httprouter.Params, _ // GETHealth sums up the health of all the registered services. func GETHealth(w http.ResponseWriter, r *http.Request, _ httprouter.Params, e *Env) { - globalHealth, statuses := health.Healthcheck(e.Datastore) - - httpStatus := http.StatusOK - if !globalHealth { - httpStatus = http.StatusServiceUnavailable - } - - httputils.WriteHTTP(w, httpStatus, statuses) + // globalHealth, statuses := health.Healthcheck(e.Datastore) + // + // httpStatus := http.StatusOK + // if !globalHealth { + // httpStatus = http.StatusServiceUnavailable + // } + // + // httputils.WriteHTTP(w, httpStatus, statuses) return } diff --git a/database/database.go b/database/database.go index 65447dbb..46a0e5e8 100644 --- a/database/database.go +++ b/database/database.go @@ -63,5 +63,6 @@ type Datastore interface { Unlock(name, owner string) FindLock(name string) (string, time.Time, error) + Ping() bool Close() } diff --git a/database/pgsql/pgsql.go b/database/pgsql/pgsql.go index 797e95e2..ca4bc5a8 100644 --- a/database/pgsql/pgsql.go +++ b/database/pgsql/pgsql.go @@ -44,6 +44,10 @@ func (pgSQL *pgSQL) Close() { pgSQL.DB.Close() } +func (pgSQL *pgSQL) Ping() bool { + return pgSQL.Ping() +} + // Open creates a Datastore backed by a PostgreSQL database. // // It will run immediately every necessary migration on the database. diff --git a/health/health.go b/health/health.go deleted file mode 100644 index 2dbfbefd..00000000 --- a/health/health.go +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2015 clair authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package health defines a standard healthcheck response format and expose -// a function that summarizes registered healthchecks. -package health - -import ( - "fmt" - "sync" - - "github.com/coreos/clair/database" -) - -// Status defines a way to know the health status of a service -type Status struct { - // IsEssential determines if the service is essential to the app, which can't - // run in case of a failure - IsEssential bool - // IsHealthy defines whether the service is working or not - IsHealthy bool - // Details gives informations specific to the service - Details interface{} -} - -// A Healthchecker function is a method returning the Status of the tested service -type Healthchecker func(database.Datastore) Status - -var ( - healthcheckersLock sync.Mutex - healthcheckers = make(map[string]Healthchecker) -) - -// RegisterHealthchecker registers a Healthchecker function which will be part of Healthchecks -func RegisterHealthchecker(name string, f Healthchecker) { - if name == "" { - panic("Could not register a Healthchecker with an empty name") - } - if f == nil { - panic("Could not register a nil Healthchecker") - } - - healthcheckersLock.Lock() - defer healthcheckersLock.Unlock() - - if _, alreadyExists := healthcheckers[name]; alreadyExists { - panic(fmt.Sprintf("Healthchecker '%s' is already registered", name)) - } - healthcheckers[name] = f -} - -// Healthcheck calls every registered Healthchecker and summarize their output -func Healthcheck(datastore database.Datastore) (bool, map[string]interface{}) { - globalHealth := true - - statuses := make(map[string]interface{}) - for serviceName, serviceChecker := range healthcheckers { - status := serviceChecker(datastore) - - globalHealth = globalHealth && (!status.IsEssential || status.IsHealthy) - statuses[serviceName] = struct { - IsHealthy bool - Details interface{} `json:",omitempty"` - }{ - IsHealthy: status.IsHealthy, - Details: status.Details, - } - } - - return globalHealth, statuses -} diff --git a/notifier/notifier.go b/notifier/notifier.go index 4b85b44c..711eca28 100644 --- a/notifier/notifier.go +++ b/notifier/notifier.go @@ -100,9 +100,6 @@ func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *u whoAmI := uuid.New() log.Infof("notifier service started. lock identifier: %s\n", whoAmI) - // Register healthchecker. - health.RegisterHealthchecker("notifier", Healthcheck) - for running := true; running; { // Find task. // TODO(Quentin-M): Combine node and notification. @@ -203,9 +200,3 @@ func handleTask(notificationName string, st *utils.Stopper, maxAttempts int) (bo log.Infof("successfully sent notification '%s'\n", notificationName) return true, false } - -// Healthcheck returns the health of the notifier service. -func Healthcheck(datastore database.Datastore) health.Status { - queueSize, err := datastore.CountAvailableNotifications() - return health.Status{IsEssential: false, IsHealthy: err == nil, Details: struct{ QueueSize int }{QueueSize: queueSize}} -} diff --git a/updater/updater.go b/updater/updater.go index 9da57f1e..f1d5d2ef 100644 --- a/updater/updater.go +++ b/updater/updater.go @@ -24,7 +24,6 @@ import ( "github.com/coreos/clair/config" "github.com/coreos/clair/database" - "github.com/coreos/clair/health" "github.com/coreos/clair/utils" "github.com/coreos/pkg/capnslog" "github.com/pborman/uuid" @@ -51,9 +50,6 @@ func Run(config *config.UpdaterConfig, datastore database.Datastore, st *utils.S return } - // Register healthchecker. - health.RegisterHealthchecker("updater", Healthcheck) - whoAmI := uuid.New() log.Infof("updater service started. lock identifier: %s", whoAmI) @@ -200,23 +196,6 @@ func fetch(datastore database.Datastore) (bool, []database.Vulnerability, map[st return status, vulnerabilities, flags, notes } -// Healthcheck returns the health of the updater service. -func Healthcheck(datastore database.Datastore) health.Status { - notes := getNotes(datastore) - - return health.Status{ - IsEssential: false, - IsHealthy: len(notes) == 0, - Details: struct { - LatestSuccessfulUpdate time.Time - Notes []string `json:",omitempty"` - }{ - LatestSuccessfulUpdate: getLastUpdate(datastore), - Notes: notes, - }, - } -} - func getLastUpdate(datastore database.Datastore) time.Time { if lastUpdateTSS, err := datastore.GetKeyValue(flagName); err == nil && lastUpdateTSS != "" { if lastUpdateTS, err := strconv.ParseInt(lastUpdateTSS, 10, 64); err == nil {