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 <sspaink@styra.com>
This commit is contained in:
Sebastian Spaink
2025-04-25 11:04:18 -05:00
committed by GitHub
parent 9b5f6010c0
commit 254f3bf0b9
2 changed files with 17 additions and 4 deletions
+14 -1
View File
@@ -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()
+3 -3
View File
@@ -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,
},
}