Skip to content

Commit

Permalink
Add logging for the write buffer and the queue processor
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariano Uvalle committed Nov 27, 2024
1 parent c33e81b commit 78a2190
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions internal/controllers/reconciliation/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func (c *Controller) Reconcile(ctx context.Context, req *reconstitution.Request)
current.GetDeletionTimestamp() != nil ||
(resource.Deleted() && comp.Annotations["eno.azure.io/deletion-strategy"] == "orphan") // orphaning should be reflected on the status.
c.writeBuffer.PatchStatusAsync(ctx, &resource.ManifestRef, patchResourceState(deleted, ready))
logger.V(0).Info("Wrote patch status to the buffer", "deleted", deleted, "ready", ready)
if ready == nil {
return ctrl.Result{RequeueAfter: wait.Jitter(c.readinessPollInterval, 0.1)}, nil
}
Expand Down
10 changes: 9 additions & 1 deletion internal/flowcontrol/writebuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"golang.org/x/time/rate"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -171,7 +172,14 @@ func (w *ResourceSliceWriteBuffer) updateSlice(ctx context.Context, sliceNSN typ
if patch == nil {
continue
}

// NOTE: This is slow and purely for debugging.
u := &unstructured.Unstructured{}
if err := u.UnmarshalJSON([]byte(slice.Spec.Resources[update.SlicedResource.Index].Manifest)); err != nil {
logger = logger.WithValues("index", update.SlicedResource.Index)
} else {
logger = logger.WithValues("resource-name", u.GetName(), "resource-kind", u.GroupVersionKind().Kind)
}
logger.V(1).Info("will patch status for resource")
patches = append(patches, &jsonPatch{
Op: "replace",
Path: fmt.Sprintf("/status/resources/%d", update.SlicedResource.Index),
Expand Down
3 changes: 3 additions & 0 deletions internal/reconstitution/queueprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ func (q *queueProcessor) processQueueItem(ctx context.Context) bool {

logger := q.Logger.WithValues("compositionName", req.Composition.Name, "compositionNamespace", req.Composition.Namespace, "resourceKind", req.Resource.Kind, "resourceName", req.Resource.Name, "resourceNamespace", req.Resource.Namespace)
ctx = logr.NewContext(ctx, logger)
logger.Info("processing queue item")
defer logger.Info("done with queue item")

result, err := q.Handler.Reconcile(ctx, &req)
if err != nil {
Expand All @@ -60,6 +62,7 @@ func (q *queueProcessor) processQueueItem(ctx context.Context) bool {
return true
}

logger.Info("forgetting queue item")
q.Queue.Forget(item)
return true
}

0 comments on commit 78a2190

Please sign in to comment.