Skip to content

Log Info when a re-queue happens due to optimistic locking - #3794

Merged
jetstack-bot merged 2 commits into
cert-manager:masterfrom
JoshVanL:dont-log-optimistic-logging
Apr 28, 2021
Merged

jetstack-bot merged 2 commits into
cert-manager:masterfrom
JoshVanL:dont-log-optimistic-logging

Conversation

@JoshVanL

@JoshVanL JoshVanL commented Mar 23, 2021 •

Copy link
Copy Markdown
Contributor

This PR stops the pollution of cert-manager-controller logs with errors from multiple controllers attempting to update the same object version. Instead, we log to info, however we still re-queue the object so has not functional change to any controller.

E0323 18:09:56.487221       1 controller.go:158] cert-manager/controller/CertificateReadiness "msg"="re-queuing item due to error processing" "error"="Operation cannot be fulfilled on certificates.cert-manager.io \"osm-ca\": the object has been modified; please apply your changes to the latest version and try again" "key"="default/osm-ca" 

/assign @irbekrm @jakexks @maelvls @wallrj
/milestone v1.3
/cleanup
fixes #3667

Optimistic locking messages (the object has been modified) are now logged at the Info level instead of the Error level, as cert-manager controllers will automatically retry until successful.

@jetstack-bot jetstack-bot added the release-note-none Denotes a PR that doesn't merit a release note. label Mar 23, 2021
@jetstack-bot jetstack-bot added this to the v1.3 milestone Mar 23, 2021
@jetstack-bot jetstack-bot added the dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. label Mar 23, 2021
@jetstack-bot
jetstack-bot requested a review from munnerz March 23, 2021 18:24
@jetstack-bot jetstack-bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 23, 2021
@JoshVanL

Copy link
Copy Markdown
Contributor Author

/kind cleanup

@jetstack-bot jetstack-bot added kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. and removed needs-kind Indicates a PR lacks a `kind/foo` label and requires one. labels Mar 23, 2021
@munnerz

munnerz commented Mar 24, 2021

Copy link
Copy Markdown
Member

Hm, I'm uneasy about this change.. won't this make it seem like a sync had succeeded from the log output point of view? In cases where legitimate thrashing is occurring on a resource, this could really send people down a rabbit hole.

@munnerz

munnerz commented Mar 24, 2021

Copy link
Copy Markdown
Member

If this is our own behavior causing this, it'd make sense to try and address the root cause of the problem rather than just hiding the messages IMO

@wallrj wallrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume that multiple controllers are attempting to update the Certificate.Status.
Should we attempt to impose order on the controller operations by having each of them set a controller specific Condition to true when they have completed their operations.

And each controller could declare its dependencies in terms of other controller Conditions and ignore resources that do not have the required conditions matching the current resource generation.

@irbekrm irbekrm left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To me it seems like at the moment this is the better easy fix.

I have observed these messages when a Certificate is being renewed as the multiple control loops attempt to update Certficate's status.
This does not seem to be causing issues as such as the loops eventually stabilize.

These messages seem to be quite misleading for users - i.e if someone's Certificate is not being renewed correctly and they are looking at the controller logs- these error messages will be there in both success and error cases and, even though if there were 'too many' of them that would signal another issue this probably isn't helpful for someone looking at the controller logs first time- they end up missing the actual problem in most cases I have seen.

I think in the case if the controller was sending too many updates to the API server, we would get throttled and that error message would then appear in the logs as expected.

Example output here from when a Certificate is being renewed. There is also no indication of having recovered from these 'errors'

W0326 14:07:10.488153       1 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
I0326 14:15:48.000916       1 trigger_controller.go:189] cert-manager/controller/certificates-trigger "msg"="Certificate must be re-issued" "key"="default/test5" "message"="Renewing certificate as renewal was scheduled at 2021-03-26 14:15:48 +0000 UTC" "reason"="Renewing"
I0326 14:15:48.000959       1 conditions.go:182] Setting lastTransitionTime for Certificate "test5" condition "Issuing" to 2021-03-26 14:15:48.000952589 +0000 UTC m=+3653.661894848
I0326 14:15:48.048530       1 conditions.go:242] Setting lastTransitionTime for CertificateRequest "test5-428j8" condition "Approved" to 2021-03-26 14:15:48.048522624 +0000 UTC m=+3653.709464843
I0326 14:15:48.050203       1 conditions.go:242] Setting lastTransitionTime for CertificateRequest "test5-428j8" condition "Ready" to 2021-03-26 14:15:48.050198257 +0000 UTC m=+3653.711140469
E0326 14:15:48.060921       1 controller.go:158] cert-manager/controller/certificaterequests-issuer-selfsigned "msg"="re-queuing item due to error processing" "error"="Operation cannot be fulfilled on certificaterequests.cert-manager.io \"test5-428j8\": the object has been modified; please apply your changes to the latest version and try again" "key"="default/test5-428j8" 
I0326 14:15:48.062351       1 conditions.go:242] Setting lastTransitionTime for CertificateRequest "test5-428j8" condition "Ready" to 2021-03-26 14:15:48.062346889 +0000 UTC m=+3653.723289101
E0326 14:15:48.078118       1 controller.go:158] cert-manager/controller/certificates-readiness "msg"="re-queuing item due to error processing" "error"="Operation cannot be fulfilled on certificates.cert-manager.io \"test5\": the object has been modified; please apply your changes to the latest version and try again" "key"="default/test5" 
E0326 14:15:48.082165       1 controller.go:158] cert-manager/controller/certificates-issuing "msg"="re-queuing item due to error processing" "error"="Operation cannot be fulfilled on certificates.cert-manager.io \"test5\": the object has been modified; please apply your changes to the latest version and try again" "key"="default/test5" 
E0326 14:15:48.084272       1 controller.go:158] cert-manager/controller/certificates-key-manager "msg"="re-queuing item due to error processing" "error"="Operation cannot be fulfilled on certificates.cert-manager.io \"test5\": the object has been modified; please apply your changes to the latest version and try again" "key"="default/test5" 
W0326 14:16:50.488454       1 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; 

@irbekrm

irbekrm commented Mar 26, 2021

Copy link
Copy Markdown
Contributor

Adding a hold to this as not everyone agreed with the approach, but feel free to unhold.

/hold
/lgtm

@jetstack-bot jetstack-bot added do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. lgtm Indicates that a PR is ready to be merged. labels Mar 26, 2021

@maelvls maelvls left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one tiny comment on my side 😅

Comment thread pkg/controller/controller.go Outdated
err := b.syncHandler(ctx, key)
if err != nil {
if strings.Contains(err.Error(), genericregistry.OptimisticLockErrorMsg) {
log.V(logf.DebugLevel).Error(err, "re-queuing item due to optimistic locking")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Knowing when a resync happens due to optimistic locking is still important information to anyone since it allows to understand that the sync is being retried (useful to understand why the same log line appears twice for example).

Pushing this log line to -v=4 seems unfortunate to me since most users use -v=2 at this point. Would it make sense to use logf.InfoLevel + Info instead?

Suggested change
log.V(logf.DebugLevel).Error(err, "re-queuing item due to optimistic locking")
log.V(logf.InfoLevel).Info(err, "re-queuing item due to optimistic locking")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ what do you think?

@munnerz

munnerz commented Mar 31, 2021

Copy link
Copy Markdown
Member

To me it seems like at the moment this is the better easy fix.

Personally I'm not sure I agree, but I'll leave it up to the group :) I think this does hide transient errors somewhat, however in cases where users are running into genuine failures, this will make it a lot harder to actually dig in/work out what's going wrong.

I'd strongly advocate for actually fixing the underlying issue - if we are going to merge this change, can we make it a priority to come up with a strategy that avoids these messages in the first place?

Given that each one of these controllers actually only manages a very specific subset of the Certificate status, some careful programming and a switch to either managed fields based server-side apply (or perhaps more simply right now, a patch operation) would help a lot.

As an alternative, instead of hiding these messages, could we add some additional text to the error when it is logged for the Certificate controllers cases? e.g. "Failed to update status, this is likely to not be an error and will be corrected on the next sync iteration: Operation could not be fulfilled..." (potentially with a link to the GitHub issue tracking these errors too, so the user has more information they can follow along with?)

@irbekrm

irbekrm commented Mar 31, 2021 •

Copy link
Copy Markdown
Contributor

Given that each one of these controllers actually only manages a very specific subset of the Certificate status, some careful programming and a switch to either managed fields based server-side apply (or perhaps more simply right now, a patch operation) would help a lot.

At the moment there are conditions that are managed by multiple controllers (i.e Issuing condition would be applied by certificate-trigger controller, removed by certificate-issuing controller)

We could prioritize re-designing it so that each condition is only managed by a single controller and that would allow patching the status updates?

Is it generally a bad practice if multiple controllers manage a condition?

@munnerz

munnerz commented Mar 31, 2021

Copy link
Copy Markdown
Member

At the moment there are conditions that are managed by multiple controllers (i.e Issuing condition would be applied by certificate-trigger controller, removed by certificate-issuing controller)

That's true, however, the design for the certificates controller is such that one controllers adds the condition, and then the issuing controller removes it after a complete issuance.

We could re-design this, however I think given the fact that an issuance has to happen in between these two events (which implies caches have observed changes to add the condition), this is actually a case that is very unlikely to be causing the conflict.

You can see this noted here: https://github.com/jetstack/cert-manager/blob/master/design/20200326.extensible-certificate-controller.md#proposal

  • issuing - issues the signed x509 certificate and 'next private key' into the spec.secretName when the CertificateRequest is valid. Manages the status.revision field. Responsible for removing the Issuing condition.
  • trigger - monitors the Secret resource and certificate.spec and adds the Issuing condition when issuance is required.

(added emphasis :))

@munnerz

munnerz commented Mar 31, 2021

Copy link
Copy Markdown
Member

Perhaps leaving these two specific cases to continue using an Update operation, and have the others use a Patch, would improve things? :)

@irbekrm

irbekrm commented Mar 31, 2021

Copy link
Copy Markdown
Contributor

I wonder if it'd be confusing if some were patched some not, but I guess we can live with that?
I will create an issue for this.

@maelvls

maelvls commented Mar 31, 2021 •

Copy link
Copy Markdown
Member

I am also in favor of not hiding these messages under the -v=4 level since the optimistic locking retry messages are useful to understand why a logline appears twice in a row; it is also useful to us to spot unexpected data races.

-E0326 controller.go:158] "msg"="re-queuing item due to error processing" "error"="Operation cannot be fulfilled on certificates.cert-manager.io \"test5\": the object has been modified; please apply your changes to the latest version and try again" "key"="default/test5" 
+I0326 controller.go:158] "msg"="happily re-queuing item thanks to optimistic locking" "key"="default/test5"

A switch to either managed fields based server-side apply would help a lot.

Good point, I never thought about managed fields + server-side apply. I guess we can investigate this idea.

Regarding the PATCH idea, it sounds like a good idea but wouldn't it skip some updates due to not looking at the revision? Also, how can we enforce (as you said: some careful programming) that we are always careful? 😅

@JoshVanL

JoshVanL commented Apr 28, 2021 •

Copy link
Copy Markdown
Contributor Author

/close

It is clear to me that this is not a good approach to fixing these error logs. Rather than suppressing these messages which are a symptom of a larger problem, we should fix that larger problem.

I'm closing this PR since I don't think it is relevant for fixing this separate issue.

@jetstack-bot

Copy link
Copy Markdown
Contributor

@JoshVanL: Closed this PR.

Details

In response to this:

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@maelvls

maelvls commented Apr 28, 2021 •

Copy link
Copy Markdown
Member

/close

I am a bit confused, why close the PR?

@JoshVanL

Copy link
Copy Markdown
Contributor Author

/close cancel

As discussed, I am changing this PR to instead Info log that the resource will be re-queued due to optimistic locking, rather than suppressing the log at debug.

@JoshVanL JoshVanL reopened this Apr 28, 2021
@jetstack-bot jetstack-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 28, 2021
@JoshVanL
JoshVanL force-pushed the dont-log-optimistic-logging branch from 6c754aa to b543d10 Compare April 28, 2021 13:19
@jetstack-bot jetstack-bot removed lgtm Indicates that a PR is ready to be merged. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 28, 2021
@JoshVanL JoshVanL changed the title Don't log on default log level when an error occurs in optimistic locking Log Info when a re-queue happens due to optimistic logging Apr 28, 2021
@jakexks jakexks changed the title Log Info when a re-queue happens due to optimistic logging Log Info when a re-queue happens due to optimistic locking Apr 28, 2021

@jakexks jakexks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
I would suggest a release note for this, on the lines of

Optimistic locking messages (the object has been modified) are now logged at the Info level instead of the Error level, as cert-manager controllers will automatically retry until successful.

/hold
Hold until after the 1.4-alpha.0 release

@jetstack-bot jetstack-bot added the lgtm Indicates that a PR is ready to be merged. label Apr 28, 2021
@jetstack-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: irbekrm, jakexks, JoshVanL

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:
  • OWNERS [JoshVanL,irbekrm,jakexks]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jakexks jakexks removed their assignment Apr 28, 2021
@jetstack-bot jetstack-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Apr 28, 2021
@JoshVanL

Copy link
Copy Markdown
Contributor Author

/hold cancel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

'..error"="Operation cannot be fulfilled...object has been modified..' lines in the logs

7 participants