clair: mv notifier to top level
This commit is contained in:
parent
9c63a63944
commit
e5c567f3f9
@ -32,7 +32,6 @@ import (
|
|||||||
"github.com/coreos/clair/api/context"
|
"github.com/coreos/clair/api/context"
|
||||||
"github.com/coreos/clair/config"
|
"github.com/coreos/clair/config"
|
||||||
"github.com/coreos/clair/database"
|
"github.com/coreos/clair/database"
|
||||||
"github.com/coreos/clair/notifier"
|
|
||||||
"github.com/coreos/clair/pkg/stopper"
|
"github.com/coreos/clair/pkg/stopper"
|
||||||
|
|
||||||
// Register database driver.
|
// Register database driver.
|
||||||
@ -102,7 +101,7 @@ func Boot(config *config.Config) {
|
|||||||
|
|
||||||
// Start notifier
|
// Start notifier
|
||||||
st.Begin()
|
st.Begin()
|
||||||
go notifier.Run(config.Notifier, db, st)
|
go clair.RunNotifier(config.Notifier, db, st)
|
||||||
|
|
||||||
// Start API
|
// Start API
|
||||||
st.Begin()
|
st.Begin()
|
||||||
|
@ -12,15 +12,11 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
// Package notifier fetches notifications from the database and informs the
|
package clair
|
||||||
// specified remote handler about their existences, inviting the third party to
|
|
||||||
// actively query the API about it.
|
|
||||||
package notifier
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/pkg/capnslog"
|
|
||||||
"github.com/coreos/pkg/timeutil"
|
"github.com/coreos/pkg/timeutil"
|
||||||
"github.com/pborman/uuid"
|
"github.com/pborman/uuid"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
@ -33,15 +29,13 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
checkInterval = 5 * time.Minute
|
notifierCheckInterval = 5 * time.Minute
|
||||||
refreshLockDuration = time.Minute * 2
|
notifierMaxBackOff = 15 * time.Minute
|
||||||
lockDuration = time.Minute*8 + refreshLockDuration
|
notifierLockRefreshDuration = time.Minute * 2
|
||||||
maxBackOff = 15 * time.Minute
|
notifierLockDuration = time.Minute*8 + notifierLockRefreshDuration
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
log = capnslog.NewPackageLogger("github.com/coreos/clair", "notifier")
|
|
||||||
|
|
||||||
promNotifierLatencyMilliseconds = prometheus.NewHistogram(prometheus.HistogramOpts{
|
promNotifierLatencyMilliseconds = prometheus.NewHistogram(prometheus.HistogramOpts{
|
||||||
Name: "clair_notifier_latency_milliseconds",
|
Name: "clair_notifier_latency_milliseconds",
|
||||||
Help: "Time it takes to send a notification after it's been created.",
|
Help: "Time it takes to send a notification after it's been created.",
|
||||||
@ -58,8 +52,9 @@ func init() {
|
|||||||
prometheus.MustRegister(promNotifierBackendErrorsTotal)
|
prometheus.MustRegister(promNotifierBackendErrorsTotal)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run starts the Notifier service.
|
// RunNotifier begins a process that checks for new notifications that should
|
||||||
func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *stopper.Stopper) {
|
// be sent out to third parties.
|
||||||
|
func RunNotifier(config *config.NotifierConfig, datastore database.Datastore, stopper *stopper.Stopper) {
|
||||||
defer stopper.End()
|
defer stopper.End()
|
||||||
|
|
||||||
// Configure registered notifiers.
|
// Configure registered notifiers.
|
||||||
@ -113,8 +108,8 @@ func Run(config *config.NotifierConfig, datastore database.Datastore, stopper *s
|
|||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
break outer
|
break outer
|
||||||
case <-time.After(refreshLockDuration):
|
case <-time.After(notifierLockRefreshDuration):
|
||||||
datastore.Lock(notification.Name, whoAmI, lockDuration, true)
|
datastore.Lock(notification.Name, whoAmI, notifierLockDuration, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +128,7 @@ func findTask(datastore database.Datastore, renotifyInterval time.Duration, whoA
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wait.
|
// Wait.
|
||||||
if !stopper.Sleep(checkInterval) {
|
if !stopper.Sleep(notifierCheckInterval) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +136,7 @@ func findTask(datastore database.Datastore, renotifyInterval time.Duration, whoA
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Lock the notification.
|
// Lock the notification.
|
||||||
if hasLock, _ := datastore.Lock(notification.Name, whoAmI, lockDuration, false); hasLock {
|
if hasLock, _ := datastore.Lock(notification.Name, whoAmI, notifierLockDuration, false); hasLock {
|
||||||
log.Infof("found and locked a notification: %s", notification.Name)
|
log.Infof("found and locked a notification: %s", notification.Name)
|
||||||
return ¬ification
|
return ¬ification
|
||||||
}
|
}
|
||||||
@ -173,7 +168,7 @@ func handleTask(n database.VulnerabilityNotification, st *stopper.Stopper, maxAt
|
|||||||
// Send failed; increase attempts/backoff and retry.
|
// Send failed; increase attempts/backoff and retry.
|
||||||
promNotifierBackendErrorsTotal.WithLabelValues(senderName).Inc()
|
promNotifierBackendErrorsTotal.WithLabelValues(senderName).Inc()
|
||||||
log.Errorf("could not send notification '%s' via notifier '%s': %v", n.Name, senderName, err)
|
log.Errorf("could not send notification '%s' via notifier '%s': %v", n.Name, senderName, err)
|
||||||
backOff = timeutil.ExpBackoff(backOff, maxBackOff)
|
backOff = timeutil.ExpBackoff(backOff, notifierMaxBackOff)
|
||||||
attempts++
|
attempts++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user