mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
plugins/logs: Make a local copy of plugin's status
Previously while passing the plugins's status to the Status API, the decision log plugin held the lock while a status upload was in process. So if a status upload took a while or the status plugin was blocked as it processed some other update, this would block policy evaluation requests received by the OPA server and increase client latency. This is because since the decision log plugin held the lock, new log events could be inserted into its buffer only after the lock was released. This change makes a copy of the decision log status so that the lock is not held during a status update. Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
This commit is contained in:
@@ -779,13 +779,16 @@ func (p *Plugin) loop() {
|
||||
func (p *Plugin) doOneShot(ctx context.Context) error {
|
||||
uploaded, err := p.oneShot(ctx)
|
||||
|
||||
// Make a local copy of the plugins's status. This is needed as locking the status for
|
||||
// the status upload duration will block policy evaluation and result in
|
||||
// increased latency for OPA clients
|
||||
p.mtx.Lock()
|
||||
defer p.mtx.Unlock()
|
||||
|
||||
p.status.SetError(err)
|
||||
oldStatus := p.status
|
||||
p.mtx.Unlock()
|
||||
|
||||
if s := status.Lookup(p.manager); s != nil {
|
||||
s.UpdateDecisionLogsStatus(*p.status)
|
||||
s.UpdateDecisionLogsStatus(*oldStatus)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -398,7 +398,7 @@ func (p *Plugin) loop() {
|
||||
if err != nil {
|
||||
p.logger.Error("%v.", err)
|
||||
} else {
|
||||
p.logger.Info("Status update sent successfully in response to discovery update.")
|
||||
p.logger.Info("Status update sent successfully in response to decision log update.")
|
||||
}
|
||||
}
|
||||
case update := <-p.reconfig:
|
||||
|
||||
Reference in New Issue
Block a user