Skip to content

Commit

Permalink
feat: activate stats when flag is on in audit, webhook (#2749)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Pana <8968914+acpana@users.noreply.github.com>
Co-authored-by: Max Smythe <smythe@google.com>
  • Loading branch information
acpana and maxsmythe committed May 10, 2023
1 parent e59ae18 commit b0e9f5a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions pkg/audit/manager.go
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/go-logr/logr"
constraintclient "github.com/open-policy-agent/frameworks/constraint/pkg/client"
"github.com/open-policy-agent/frameworks/constraint/pkg/client/drivers"
"github.com/open-policy-agent/gatekeeper/pkg/controller/config/process"
"github.com/open-policy-agent/gatekeeper/pkg/expansion"
"github.com/open-policy-agent/gatekeeper/pkg/logging"
Expand Down Expand Up @@ -486,7 +487,7 @@ func (am *Manager) auditFromCache(ctx context.Context) ([]Result, []error) {
Object: obj,
Namespace: ns,
}
resp, err := am.opa.Review(ctx, au)
resp, err := am.opa.Review(ctx, au, drivers.Stats(*logStatsAudit))
if err != nil {
am.log.Error(err, "Unable to review object from audit cache %v %s/%s", obj.GroupVersionKind().String(), obj.GetNamespace(), obj.GetName())
continue
Expand Down Expand Up @@ -576,7 +577,8 @@ func (am *Manager) reviewObjects(ctx context.Context, kind string, folderCount i
Namespace: ns,
Source: mutationtypes.SourceTypeOriginal,
}
resp, err := am.opa.Review(ctx, augmentedObj)

resp, err := am.opa.Review(ctx, augmentedObj, drivers.Stats(*logStatsAudit))
if err != nil {
am.log.Error(err, "Unable to review object from file", "fileName", fileName, "objNs", objNs)
continue
Expand All @@ -600,7 +602,7 @@ func (am *Manager) reviewObjects(ctx context.Context, kind string, folderCount i
Namespace: ns,
Source: mutationtypes.SourceTypeGenerated,
}
resultantResp, err := am.opa.Review(ctx, au)
resultantResp, err := am.opa.Review(ctx, au, drivers.Stats(*logStatsAudit))
if err != nil {
am.log.Error(err, "Unable to review expanded object", "objName", (*resultant.Obj).GetName(), "objNs", ns)
continue
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/policy.go
Expand Up @@ -601,7 +601,7 @@ func (h *validationHandler) reviewRequest(ctx context.Context, req *admission.Re
}

func (h *validationHandler) review(ctx context.Context, review interface{}, trace bool, dump bool) (*rtypes.Responses, error) {
resp, err := h.opa.Review(ctx, review, drivers.Tracing(trace))
resp, err := h.opa.Review(ctx, review, drivers.Tracing(trace), drivers.Stats(*logStatsAdmission))
if resp != nil && trace {
log.Info(resp.TraceDump())
}
Expand Down

0 comments on commit b0e9f5a

Please sign in to comment.