Improvements in logger and audit webhooks (#16102)

This commit is contained in:
Shireesh Anjal
2022-11-28 21:33:26 +05:30
committed by GitHub
parent 9b1e70e4f9
commit 98a67a3776
8 changed files with 96 additions and 84 deletions

View File

@@ -77,6 +77,9 @@ type Target struct {
// Channel of log entries
logCh chan interface{}
// is the target online?
online bool
config Config
client *http.Client
}
@@ -90,6 +93,11 @@ func (h *Target) String() string {
return h.config.Name
}
// IsOnline returns true if the initialization was successful
func (h *Target) IsOnline() bool {
return h.online
}
// Stats returns the target statistics.
func (h *Target) Stats() types.TargetStats {
return types.TargetStats{
@@ -140,6 +148,7 @@ func (h *Target) Init() error {
}
h.lastStarted = time.Now()
h.online = true
atomic.AddInt64(&h.workers, 1)
go h.startHTTPLogger()
return nil
@@ -230,6 +239,7 @@ func New(config Config) *Target {
logCh: make(chan interface{}, config.QueueSize),
doneCh: make(chan struct{}),
config: config,
online: false,
}
return h
@@ -237,6 +247,10 @@ func New(config Config) *Target {
// Send log message 'e' to http target.
func (h *Target) Send(entry interface{}) error {
if !h.online {
return nil
}
select {
case <-h.doneCh:
return nil