Skip to content

Commit 254f3bf

Browse files
authored
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 <[email protected]>
1 parent 9b5f601 commit 254f3bf

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

v1/plugins/status/plugin.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
)
2525

2626
const (
27-
statusBufferLimit = int64(10)
27+
statusBufferLimit = int64(1)
2828
statusBufferDropCounterName = "status_dropped_buffer_limit_exceeded"
2929
)
3030

@@ -394,8 +394,11 @@ func (p *Plugin) loop(ctx context.Context) {
394394
p.reconfigure(update.config)
395395
update.done <- struct{}{}
396396
case respCh := <-p.queryCh:
397+
p.readBundleStatus()
397398
respCh <- p.snapshot()
398399
case update := <-p.trigger:
400+
// make sure the more recent status is registered
401+
p.readBundleStatus()
399402
err := p.oneShot(update.ctx)
400403
if err != nil {
401404
p.logger.Error("%v.", err)
@@ -414,6 +417,16 @@ func (p *Plugin) loop(ctx context.Context) {
414417
}
415418
}
416419

420+
// readBundleStatus is a non-blocking read to make sure the latest status is received
421+
func (p *Plugin) readBundleStatus() {
422+
select {
423+
case status := <-p.bulkBundleCh:
424+
p.lastBundleStatuses = status
425+
case status := <-p.bundleCh:
426+
p.lastBundleStatus = &status
427+
default:
428+
}
429+
}
417430
func (p *Plugin) oneShot(ctx context.Context) error {
418431
req := p.snapshot()
419432

v1/plugins/status/plugin_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ func TestStatusUpdateBuffer(t *testing.T) {
4848
expectedNameDropped string
4949
}{
5050
{
51-
name: "add one over the limit and drop oldest",
51+
name: "add multiple events dropping the oldest",
5252
numberOfStatusUpdates: 11,
53-
expectedStatusUpdates: 10,
53+
expectedStatusUpdates: 1,
5454
expectedNameDropped: "0",
5555
},
5656
{
5757
name: "don't drop anything",
5858
numberOfStatusUpdates: 5,
59-
expectedStatusUpdates: 5,
59+
expectedStatusUpdates: 1,
6060
},
6161
}
6262

0 commit comments

Comments
 (0)