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:
Ashutosh Narkar
2023-06-02 18:09:14 -07:00
parent 143c5dc8d2
commit ab817b215c
2 changed files with 7 additions and 4 deletions
+6 -3
View File
@@ -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 {
+1 -1
View File
@@ -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: