Skip to content

Commit

Permalink
Minor improvements to opaServeResponse filter (#3191)
Browse files Browse the repository at this point in the history
* OPA: Add decision outcome to span in opaServeResponse filter
* Increment OPA decision counter metric in opaServeResponse filter

To be symmetric with opaAuthorizeRequest filter, OPA decision counts are updated

Signed-off-by: Farasath Ahamed <[email protected]>
  • Loading branch information
mefarazath authored Aug 27, 2024
1 parent ba12cf7 commit 2c39d54
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions filters/openpolicyagent/opaserveresponse/opaserveresponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,21 @@ func (f *opaServeResponseFilter) Request(fc filters.FilterContext) {
fc.Metrics().MeasureSince(f.opa.MetricsKey("eval_time"), start)
if err != nil {
f.opa.ServeInvalidDecisionError(fc, span, result, err)
return
}

allowed, err := result.IsAllowed()
if err != nil {
f.opa.ServeInvalidDecisionError(fc, span, result, err)
return
}
span.SetTag("opa.decision.allowed", allowed)

if allowed {
fc.Metrics().IncCounter(f.opa.MetricsKey("decision.allow"))
} else {
fc.Metrics().IncCounter(f.opa.MetricsKey("decision.deny"))
}

f.opa.ServeResponse(fc, span, result)
}
Expand Down

0 comments on commit 2c39d54

Please sign in to comment.