Skip to content

Conversation

tchap
Copy link

@tchap tchap commented Sep 8, 2025

What type of PR is this?

/kind bug

What this PR does / why we need it:

kube-apiserver now logs each HTTP request twice since there is an extra logging call when finishing the request. This duplicity is now removed.

Which issue(s) this PR fixes:

N/A

Special notes for your reviewer:

N/A

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

N/A

@openshift-ci-robot openshift-ci-robot added backports/unvalidated-commits Indicates that not all commits come to merged upstream PRs. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Sep 8, 2025
@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Sep 8, 2025
@openshift-ci-robot
Copy link

@tchap: This pull request references Jira Issue OCPBUGS-43994, which is invalid:

  • expected the bug to target the "4.21.0" version, but no target version was set

Comment /jira refresh to re-evaluate validity if changes to the Jira bug are made, or edit the title of this pull request to link to a different bug.

The bug has been updated to refer to the pull request using the external bug tracker.

In response to this:

What type of PR is this?

/kind bug

What this PR does / why we need it:

kube-apiserver now logs each HTTP request twice since there is an extra logging call when finishing the request. This duplicity is now removed.

Which issue(s) this PR fixes:

N/A

Special notes for your reviewer:

N/A

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

N/A

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot
Copy link

@tchap: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

@tchap
Copy link
Author

tchap commented Sep 8, 2025

/jira refresh

@openshift-ci-robot openshift-ci-robot added jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. and removed jira/invalid-bug Indicates that a referenced Jira bug is invalid for the branch this PR is targeting. labels Sep 8, 2025
@openshift-ci-robot
Copy link

@tchap: This pull request references Jira Issue OCPBUGS-43994, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (4.21.0) matches configured target version for branch (4.21.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)

Requesting review from QA contact:
/cc @wangke19

In response to this:

/jira refresh

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci openshift-ci bot added the vendor-update Touching vendor dir or related files label Sep 8, 2025
Copy link

openshift-ci bot commented Sep 8, 2025

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: tchap
Once this PR has been reviewed and has the lgtm label, please assign jerpeter1 for approval. For more information see the Code Review Process.

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

Needs approval from an approver in each of these files:

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

@tchap
Copy link
Author

tchap commented Sep 9, 2025

/retest

3 similar comments
@tchap
Copy link
Author

tchap commented Sep 9, 2025

/retest

@tchap
Copy link
Author

tchap commented Sep 10, 2025

/retest

@tchap
Copy link
Author

tchap commented Sep 22, 2025

/retest

}
defer func() {
if logFunc != nil {
logFunc()

Choose a reason for hiding this comment

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

so, previously, the request was first logged here

@p0lyn0mial
Copy link

@tchap please also find the pr that introduced this change and let's add a description to the commit pointing to the original pr with which the new changes should be squashed during the next rebase.

@tchap
Copy link
Author

tchap commented Sep 23, 2025

@p0lyn0mial Is this any kind of standardized process documented anywhere, or should I just add a generic comment?

@p0lyn0mial
Copy link

@p0lyn0mial Is this any kind of standardized process documented anywhere, or should I just add a generic comment?

@bertinatto ^^

@bertinatto
Copy link
Member

@p0lyn0mial Is this any kind of standardized process documented anywhere, or should I just add a generic comment?

@bertinatto ^^

We don't have a standarized process, but historically we either:

  1. use the same commit title as the original commit that introduced the change;
  2. or we add a (squash) to the commit title plus the original commit in the description (personally, I prefer this one).

That way, the person doing the rebase will easily notice that the carry patch can/should be squashed.

kube-apiserver now logs each HTTP request twice since there is an extra
logging call when finishing the request. This duplicity is now removed.
@openshift-ci-robot
Copy link

@tchap: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

return withLogging(handler, pred, func() bool {
return klog.V(withLoggingLevel).Enabled()
}, isTerminatingFn)
return withLogging(handler, pred, func(ctx context.Context) bool {

Choose a reason for hiding this comment

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

wait, why so many changes in this file ? should we simply remove the code we discussed previously ?

}
logger := klog.FromContext(ctx)
return logger.V(withLoggingLevel).Enabled() || (isTerminating && logger.V(1).Enabled())
})
Copy link
Author

@tchap tchap Sep 23, 2025

Choose a reason for hiding this comment

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

@p0lyn0mial I ended up refactoring the logic and private interfaces a bit, but the overall approach is not exactly bullet-proof.

There is now a single predicate function that merges previous shouldLogRequest and isTerminatingFn. This means withLogging is now much more clear and simple.

I added tests and use contextual logging internally that is handy for testing.

The issue really is that when you check respLogger.Log, it contains anyway klog.V(withLoggingLevel), but isTerminating flag is not passed there, so I am afraid the current implementation contains a bug anyway and isTerminating is pretty much ignored. So what I did was to check all the conditions initially here and remove .V call from .Log. This makes all the tests pass just fine.

Copy link
Author

Choose a reason for hiding this comment

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

Another approach would be to keep the isTerminating field in the logger and repeat the terminating check in Log as well...

Choose a reason for hiding this comment

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

I need to check but if rl.isTerminating is/was unused then maybe we can drop the entire patch. Assuming our issue was:

if klog.V(3).Enabled() || (rl.isTerminating && klog.V(1).Enabled()) {...}

Copy link
Author

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

yeah, I think that the patch was introduced in b052cde

But given that shouldLogRequest is always true when the loglevel is 3 (hardcoded value) and the fact that rl.isTerminating is unused beyond httplog what is the point of the original patch/pr ?

If we were to drop it, I think there would be no change in the behavior. am I right?

Choose a reason for hiding this comment

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

Otherwise we can just drop the original patch, which would mean no logging when terminating. Which is not happening right now anyway, but the question is whether we want to drop the intent.

I think the patch is very old. I think that the purpose was to find requests during server termination - not a feature users were using.

I think that we could simply drop the patch and test manually that when loglevel is 3 there are no duplicates during server shutdown.

Copy link
Author

Choose a reason for hiding this comment

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

I did push one last commit, but I guess the plan is to close this and also remove the original carry this is fixing then?

Choose a reason for hiding this comment

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

I think so, given that the behaviour will not change after removing the PR, right?. Unless there are some other parts that depend on the original PR.

Copy link
Author

Choose a reason for hiding this comment

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

I don't think anything depends on it, I've reverted the commit just to test it.

Choose a reason for hiding this comment

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

could you also test manually that httplog logs requests when appropriate loglevel is set and there are no duplicates ?

you can also open a new PR so that we get a signal from the CI.


// Log is intended to be called once at the end of your request handler, via defer
func (rl *respLogger) Log() {
func (rl *respLogger) Log(ctx context.Context) {
Copy link
Author

Choose a reason for hiding this comment

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

There is a change of interface, but it doesn't seem to be really used publicly as this is an unexported object.

@tchap
Copy link
Author

tchap commented Sep 24, 2025

/retest

2 similar comments
@tchap
Copy link
Author

tchap commented Sep 25, 2025

/retest

@tchap
Copy link
Author

tchap commented Sep 26, 2025

/retest

@openshift-ci-robot
Copy link

@tchap: the contents of this pull request could not be automatically validated.

The following commits could not be validated and must be approved by a top-level approver:

Comment /validate-backports to re-evaluate validity of the upstream PRs, for example when they are merged upstream.

Copy link

openshift-ci bot commented Sep 29, 2025

@tchap: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-aws-ovn-runc 3981cdc link true /test e2e-aws-ovn-runc
ci/prow/e2e-aws-ovn-fips 3981cdc link true /test e2e-aws-ovn-fips
ci/prow/k8s-e2e-conformance-aws 3981cdc link true /test k8s-e2e-conformance-aws
ci/prow/e2e-aws-csi 3981cdc link false /test e2e-aws-csi
ci/prow/verify-commits 3981cdc link true /test verify-commits
ci/prow/e2e-aws-crun-wasm 3981cdc link true /test e2e-aws-crun-wasm
ci/prow/k8s-e2e-aws-ovn-serial 3981cdc link false /test k8s-e2e-aws-ovn-serial
ci/prow/e2e-aws-ovn-cgroupsv2 3981cdc link true /test e2e-aws-ovn-cgroupsv2
ci/prow/e2e-aws-ovn-techpreview-serial 3981cdc link false /test e2e-aws-ovn-techpreview-serial
ci/prow/e2e-aws-ovn-techpreview 3981cdc link false /test e2e-aws-ovn-techpreview
ci/prow/e2e-agnostic-ovn-cmd 3981cdc link false /test e2e-agnostic-ovn-cmd
ci/prow/okd-scos-e2e-aws-ovn 3981cdc link false /test okd-scos-e2e-aws-ovn
ci/prow/e2e-aws-ovn-serial 3981cdc link true /test e2e-aws-ovn-serial
ci/prow/e2e-aws-ovn-crun 3981cdc link true /test e2e-aws-ovn-crun

Full PR test history. Your PR dashboard.

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-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backports/unvalidated-commits Indicates that not all commits come to merged upstream PRs. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. kind/bug Categorizes issue or PR as related to a bug. vendor-update Touching vendor dir or related files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants