From 254f3bf0b9ee5faf1972ba31bbbe749bba19a000 Mon Sep 17 00:00:00 2001 From: Sebastian Spaink <3441183+sspaink@users.noreply.github.com> Date: Fri, 25 Apr 2025 11:04:18 -0500 Subject: [PATCH] fix(status plugin): make sure the latest status is read before manually triggering or returning a snapshot (#7533) * when manually triggering, make sure the latest status event is registered. Only one status event should exist. * read bundle status for snapshot as well * revert back to buffering 1 status event Signed-off-by: sspaink --- v1/plugins/status/plugin.go | 15 ++++++++++++++- v1/plugins/status/plugin_test.go | 6 +++--- 2 files changed, 17 insertions(+), 4 deletions(-) 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, }, }