fix(processorhandler): reduce GC pressure

* this onboards an optimization from the opa-utils package (caching
exceptions processing)

Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
This commit is contained in:
Frédéric BIDON
2023-02-22 20:53:02 +01:00
committed by Frederic BIDON
parent 915fa919b2
commit 65c26e22cf
4 changed files with 19 additions and 9 deletions
@@ -7,15 +7,15 @@ import (
)
func Test_has_signature(t *testing.T) {
tests := []struct {
name string
img string
img string
want bool
}{
{
name: "valid signature",
img: "quay.io/kubescape/gateway",
img: "quay.io/kubescape/gateway",
want: true,
},
}
-1
View File
@@ -15,7 +15,6 @@ import (
)
// VerifyCommand verifies a signature on a supplied container image
// nolint
type VerifyCommand struct {
options.RegistryOptions
Annotations sigs.AnnotationsMap
+3 -2
View File
@@ -74,6 +74,9 @@ func (opap *OPAProcessor) Process(ctx context.Context, policies *cautils.Policie
ctx, span := otel.Tracer("").Start(ctx, "OPAProcessor.Process")
defer span.End()
opap.loggerStartScanning()
defer opap.loggerDoneScanning()
cautils.StartSpinner()
defer cautils.StopSpinner()
if progressListener != nil {
progressListener.Start(len(policies.Controls))
@@ -109,8 +112,6 @@ func (opap *OPAProcessor) Process(ctx context.Context, policies *cautils.Policie
opap.Report.ReportGenerationTime = time.Now().UTC()
opap.loggerDoneScanning()
return nil
}
+13 -3
View File
@@ -7,9 +7,11 @@ import (
"github.com/kubescape/k8s-interface/k8sinterface"
"github.com/kubescape/k8s-interface/workloadinterface"
"github.com/kubescape/kubescape/v2/core/cautils"
"github.com/kubescape/opa-utils/exceptions"
"github.com/kubescape/opa-utils/reporthandling"
"github.com/kubescape/opa-utils/reporthandling/apis"
"github.com/kubescape/opa-utils/reporthandling/results/v1/reportsummary"
"github.com/kubescape/opa-utils/reporthandling/results/v1/resourcesresults"
resources "github.com/kubescape/opa-utils/resources"
"go.opentelemetry.io/otel"
)
@@ -23,19 +25,27 @@ import (
func (opap *OPAProcessor) updateResults(ctx context.Context) {
ctx, span := otel.Tracer("").Start(ctx, "OPAProcessor.updateResults")
defer span.End()
// remove data from all objects
for i := range opap.AllResources {
removeData(opap.AllResources[i])
}
processor := exceptions.NewProcessor()
// set exceptions
for i := range opap.ResourcesResult {
t := opap.ResourcesResult[i]
// first set exceptions
// first set exceptions (reuse the same exceptions processor)
if resource, ok := opap.AllResources[i]; ok {
t.SetExceptions(resource, opap.Exceptions, cautils.ClusterName, opap.AllPolicies.Controls)
t.SetExceptions(
resource,
opap.Exceptions,
cautils.ClusterName,
opap.AllPolicies.Controls, // update status depending on action required
resourcesresults.WithExceptionsProcessor(processor),
)
}
// summarize the resources