mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-13 03:42:35 -06:00
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:
@@ -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()
|
||||
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user