*: remove health checker

pull/71/head
Quentin Machu 9 years ago committed by Jimmy Zelinskie
parent 63ebddfd36
commit b8b7be3f81

@ -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
}

@ -63,5 +63,6 @@ type Datastore interface {
Unlock(name, owner string)
FindLock(name string) (string, time.Time, error)
Ping() bool
Close()
}

@ -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.

@ -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
}

@ -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}}
}

@ -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 {

Loading…
Cancel
Save