Skip to content

Commit

Permalink
Reduce the log noise
Browse files Browse the repository at this point in the history
This has been an issue, especially in the template-sync, that there is a
lot of log noise so when a user reports an issue, the logs on Kubernetes
have already rolled over.

Relates:
https://issues.redhat.com/browse/ACM-10403

Signed-off-by: mprahl <[email protected]>
  • Loading branch information
mprahl authored and openshift-merge-bot[bot] committed Mar 21, 2024
1 parent 050bf23 commit 86d0595
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
10 changes: 9 additions & 1 deletion controllers/gatekeepersync/gatekeeper_constraint_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (r *GatekeeperConstraintReconciler) Reconcile(
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
}

log.Info("Reconciling a Policy with one or more Gatekeeper constraints")
log.V(1).Info("Reconciling a Policy with one or more Gatekeeper constraints")

policyObjID := depclient.ObjectIdentifier{
Group: policyv1.GroupVersion.Group,
Expand Down Expand Up @@ -411,6 +411,14 @@ func (r *GatekeeperConstraintReconciler) sendComplianceEvent(
return err
}

log.Info(
"Sent a compliance message for the Gatekeeper constraint",
"policy", refreshedPolicy.Name,
"constraintKind", constraint.GetKind(),
"constraintName", constraint.GetName(),
"msg", msg,
)

r.lastSentMessages.Store(kn, msgSHA1)
} else {
// The message is already recorded in the Policy status so the sent message in the cache can be removed. This
Expand Down
4 changes: 2 additions & 2 deletions controllers/specsync/policy_spec_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
}

reqLogger.Info("Reconciling Policy...")
reqLogger.V(1).Info("Reconciling Policy...")

// Fetch the Policy instance
instance := &policiesv1.Policy{}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
r.TargetNamespace))
}

reqLogger.Info("Reconciliation complete.")
reqLogger.V(2).Info("Reconciliation complete.")

return reconcile.Result{}, nil
}
8 changes: 4 additions & 4 deletions controllers/statussync/policy_status_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
return reconcile.Result{RequeueAfter: 5 * time.Minute}, nil
}

reqLogger.Info("Reconciling the policy")
reqLogger.V(1).Info("Reconciling the policy")

// Fetch the Policy instance
instance := &policiesv1.Policy{}
Expand Down Expand Up @@ -454,7 +454,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
fmt.Sprintf("Policy %s status was updated in cluster namespace %s", instance.GetName(),
instance.GetNamespace()))
} else {
reqLogger.Info("status match on managed, nothing to update")
reqLogger.V(1).Info("status match on managed, nothing to update")
}

if os.Getenv("ON_MULTICLUSTERHUB") != "true" {
Expand All @@ -480,11 +480,11 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
fmt.Sprintf("Policy %s status was updated to %s in cluster namespace %s", hubPlc.GetName(),
hubPlc.Status.ComplianceState, hubPlc.GetNamespace()))
} else {
reqLogger.Info("status match on hub, nothing to update")
reqLogger.V(1).Info("status match on hub, nothing to update")
}
}

reqLogger.Info("Reconciling complete")
reqLogger.V(2).Info("Reconciling complete")

return reconcile.Result{}, nil
}
Expand Down
6 changes: 3 additions & 3 deletions controllers/templatesync/template_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type PolicyReconciler struct {
// Result.Requeue is true, otherwise upon completion it will remove the work from the queue.
func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {
reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
reqLogger.Info("Reconciling the Policy")
reqLogger.V(1).Info("Reconciling the Policy")

// Fetch the Policy instance
instance := &policiesv1.Policy{}
Expand Down Expand Up @@ -843,7 +843,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
policySystemErrorsCounter.WithLabelValues(instance.Name, tName, "patch-error").Inc()
}

tLogger.Info("Existing object matches the policy template")
tLogger.V(1).Info("Existing object matches the policy template")
}

if isClusterScoped {
Expand Down Expand Up @@ -913,7 +913,7 @@ func (r *PolicyReconciler) Reconcile(ctx context.Context, request reconcile.Requ
}
}

reqLogger.Info("Completed the reconciliation")
reqLogger.V(2).Info("Completed the reconciliation")

return reconcile.Result{}, resultError
}
Expand Down

0 comments on commit 86d0595

Please sign in to comment.