From d8da7481aacad5212fdca6e9658e7b38f6596147 Mon Sep 17 00:00:00 2001 From: Frank Jogeleit Date: Fri, 6 Sep 2024 18:42:37 +0200 Subject: [PATCH] add logging Signed-off-by: Frank Jogeleit --- charts/policy-reporter/values.yaml | 2 +- pkg/target/factory/factory.go | 2 +- pkg/target/securityhub/securityhub.go | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/charts/policy-reporter/values.yaml b/charts/policy-reporter/values.yaml index 723ce43c..22669b13 100644 --- a/charts/policy-reporter/values.yaml +++ b/charts/policy-reporter/values.yaml @@ -11,7 +11,7 @@ image: registry: ghcr.io repository: kyverno/policy-reporter pullPolicy: IfNotPresent - tag: 2e1d691 + tag: 2e8fd3d imagePullSecrets: [] diff --git a/pkg/target/factory/factory.go b/pkg/target/factory/factory.go index cd2ca49e..3d2134f1 100644 --- a/pkg/target/factory/factory.go +++ b/pkg/target/factory/factory.go @@ -650,7 +650,7 @@ func (f *TargetFactory) CreateSecurityHubTarget(config, parent *target.Config[ta config.Config.Endpoint, ) - sugar.Infof("%s configured", config.Name) + zap.L().Info(config.Name+" configured", zap.Bool("cleanup", config.Config.Cleanup)) hub := securityhub.NewClient(securityhub.Options{ ClientOptions: target.ClientOptions{ diff --git a/pkg/target/securityhub/securityhub.go b/pkg/target/securityhub/securityhub.go index 1ee832d4..944d96ee 100644 --- a/pkg/target/securityhub/securityhub.go +++ b/pkg/target/securityhub/securityhub.go @@ -183,6 +183,7 @@ func (c *client) Sync(ctx context.Context) error { if !c.cleanup { return nil } + defer zap.L().Info(c.Name() + ": START SYNC") list, err := c.getFindings(ctx, "") if err != nil { @@ -191,6 +192,7 @@ func (c *client) Sync(ctx context.Context) error { } if len(list) == 0 { + zap.L().Info(c.Name() + ": no findings to sync") return nil } @@ -201,12 +203,14 @@ func (c *client) Sync(ctx context.Context) error { } }) - _, err = c.batchUpdate(ctx, findings, types.WorkflowStatusResolved) + count, err := c.batchUpdate(ctx, findings, types.WorkflowStatusResolved) if err != nil { - zap.L().Error("failed to sync findings", zap.Error(err)) + zap.L().Error(c.Name()+": failed to sync findings", zap.Error(err)) return err } + zap.L().Info(c.Name()+": FINISHED SYNC", zap.Int("updated", count)) + return nil } @@ -215,6 +219,8 @@ func (c *client) CleanUp(ctx context.Context, report v1alpha2.ReportInterface) { return } + zap.L().Info(c.Name()+": start cleanup", zap.String("report", report.GetKey())) + if source := report.GetSource(); source != "" && len(c.BaseClient.Sources()) > 0 { if !helper.Contains(source, c.BaseClient.Sources()) { return