-
Notifications
You must be signed in to change notification settings - Fork 398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging: move clusterworkspaceshard reconciler to structured logging #1614
logging: move clusterworkspaceshard reconciler to structured logging #1614
Conversation
ac7e356
to
5862781
Compare
@@ -83,16 +85,19 @@ func (c *Controller) enqueue(obj interface{}) { | |||
runtime.HandleError(err) | |||
return | |||
} | |||
klog.Infof("queueing workspace shard %q", key) | |||
klog.Background().WithValues(logging.ReconcilerKey, controllerName, logging.KeyKey, key).Info("queueing workspace shard") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unclear if we ever really need logs here (that we're enqueuing) given that we should be safe to assume that we de-queue at some point.... but in any case there's no context provided to the controller's constructor, so we can't share the logger.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have had cases where we missed events from the informers. And we had cases with backoffs. Having these has had value.
5862781
to
8e450e8
Compare
8e450e8
to
d79e1f9
Compare
pkg/reconciler/tenancy/clusterworkspaceshard/clusterworkspaceshard_controller.go
Outdated
Show resolved
Hide resolved
d79e1f9
to
defdfe0
Compare
Signed-off-by: Steve Kuznetsov <skuznets@redhat.com>
defdfe0
to
c3231e0
Compare
@@ -83,16 +85,19 @@ func (c *Controller) enqueue(obj interface{}) { | |||
runtime.HandleError(err) | |||
return | |||
} | |||
klog.Infof("queueing workspace shard %q", key) | |||
logger := logging.WithQueueKey(logging.WithReconciler(klog.Background(), controllerName), key) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
klog.Infof("processing key %q", key) | ||
logger := logging.WithQueueKey(klog.FromContext(ctx), key) | ||
ctx = klog.NewContext(ctx, logger) | ||
logger.Info("processing key") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: lower or upper case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lower probably best?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tend to prefer lower
@@ -182,6 +193,7 @@ func (c *Controller) process(ctx context.Context, key string) error { | |||
return uerr | |||
} | |||
|
|||
logger.V(6).Info("processed ClusterWorkspaceShard") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these V levels map directly to klog levels?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
return nil // object deleted before we handled it | ||
} | ||
return err | ||
} | ||
previous := obj | ||
obj = obj.DeepCopy() | ||
|
||
logger = logging.WithObject(logger, obj) | ||
ctx = klog.NewContext(ctx, logger) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everytime I see these I wished klog.NewContext
would return the logger in order to write
ctx, logger := klog.NewContext(ctx, logging.WithObject(logger, obj))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll probably want a helper
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, we can do that too - it's not every case where you want to decorate the context and the logger, but can't hurt to over-helper it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would argue that 95% of cases where you forget to augment the context is a mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we'll find that 95% of our logging code is in terminal/leaf calls where you're not passing the thing on to anyone else but yes, maybe better just to be explicit about it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _, item := range collection {
logger = logger.WithValue("item", item)
// use it
}
LGTM. We can always evolve our patterns and styles over time. Let's also add some logging conventions to a markdown doc somewhere (can be another PR)? |
/approve Anything left open to do? |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: sttts The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/lgtm We will iterate. |
/retest |
Hit flake #1626 |
/retest |
Signed-off-by: Steve Kuznetsov skuznets@redhat.com
Example output:
/cc @ncdc @sttts