diff --git a/v1/plugins/status/plugin.go b/v1/plugins/status/plugin.go index 115fbe9d5a..f80b5664c1 100644 --- a/v1/plugins/status/plugin.go +++ b/v1/plugins/status/plugin.go @@ -24,7 +24,7 @@ import ( ) const ( - statusBufferLimit = int64(10) + statusBufferLimit = int64(1) statusBufferDropCounterName = "status_dropped_buffer_limit_exceeded" ) @@ -394,8 +394,11 @@ func (p *Plugin) loop(ctx context.Context) { p.reconfigure(update.config) update.done <- struct{}{} case respCh := <-p.queryCh: + p.readBundleStatus() respCh <- p.snapshot() case update := <-p.trigger: + // make sure the more recent status is registered + p.readBundleStatus() err := p.oneShot(update.ctx) if err != nil { p.logger.Error("%v.", err) @@ -414,6 +417,16 @@ func (p *Plugin) loop(ctx context.Context) { } } +// readBundleStatus is a non-blocking read to make sure the latest status is received +func (p *Plugin) readBundleStatus() { + select { + case status := <-p.bulkBundleCh: + p.lastBundleStatuses = status + case status := <-p.bundleCh: + p.lastBundleStatus = &status + default: + } +} func (p *Plugin) oneShot(ctx context.Context) error { req := p.snapshot() diff --git a/v1/plugins/status/plugin_test.go b/v1/plugins/status/plugin_test.go index 6b28f73050..0a3ae7dae1 100644 --- a/v1/plugins/status/plugin_test.go +++ b/v1/plugins/status/plugin_test.go @@ -48,15 +48,15 @@ func TestStatusUpdateBuffer(t *testing.T) { expectedNameDropped string }{ { - name: "add one over the limit and drop oldest", + name: "add multiple events dropping the oldest", numberOfStatusUpdates: 11, - expectedStatusUpdates: 10, + expectedStatusUpdates: 1, expectedNameDropped: "0", }, { name: "don't drop anything", numberOfStatusUpdates: 5, - expectedStatusUpdates: 5, + expectedStatusUpdates: 1, }, }