-
Notifications
You must be signed in to change notification settings - Fork 960
Use structured logging for cluster taint policy controller #6539
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
Use structured logging for cluster taint policy controller #6539
Conversation
Welcome @zhangsquared! It looks like this is your first PR to karmada-io/karmada 🎉 |
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
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.
Summary of Changes
Hello @zhangsquared, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request transitions the cluster taint policy controller
to use structured logging. By adopting klog.InfoS
and klog.ErrorS
, the logs generated by this controller will now include key-value pairs, significantly improving their machine readability and enabling more robust log aggregation and analysis. This change aligns with best practices for observability in cloud-native environments.
Highlights
- Structured Logging Adoption: The
ClusterTaintPolicyController
has been updated to utilizeklog.InfoS
andklog.ErrorS
for all its logging statements. This change replaces the olderklog.Info
,klog.Infof
, andklog.Errorf
calls, thereby introducing structured logging which enhances log parsing and analysis efficiency. - Error Handling Refinement: The
errors
package has been imported and is now used to explicitly create an error object for structured logging in cases such as encountering an unsupportedMatchCondition
operator, providing more context in log entries.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Pull Request Overview
This PR migrates the ClusterTaintPolicyController to use structured JSON logging via klog.InfoS
and klog.ErrorS
.
- Replaces unstructured
klog.Infof
,klog.Errorf
, andklog.Info
withInfoS
,ErrorS
, andV().InfoS
. - Adds structured key/value pairs to error and debug logs.
- Introduces an
errors
import for creating structured error messages.
Comments suppressed due to low confidence (2)
pkg/controllers/taint/clustertaintpolicy_controller.go:73
- [nitpick] The structured log key "clusterTaintPolicyList" is misleading because it logs the ListOptions rather than the policy list. Consider renaming the key to "listOptions" to accurately describe the logged data.
klog.ErrorS(err, "Failed to list ClusterTaintPolicy", "clusterTaintPolicyList", listOption)
pkg/controllers/taint/clustertaintpolicy_controller.go:239
- [nitpick] The log key "clusterList" refers to the ListOptions being passed, not the retrieved list. Rename the key to "listOptions" for clarity.
klog.ErrorS(err, "Failed to list Cluster", "clusterList", listOption)
@@ -147,7 +148,7 @@ func conditionMatches(conditions []metav1.Condition, matchConditions []policyv1a | |||
} | |||
} | |||
default: | |||
klog.Errorf("Unsupported MatchCondition operator: %s", matchCondition.Operator) | |||
klog.ErrorS(errors.New("Unsupported MatchCondition operator"), "operator", matchCondition.Operator) |
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.
The ErrorS call sets "operator" as the log message instead of a descriptive message. It should be: ErrorS(err, "Unsupported MatchCondition operator", "operator", matchCondition.Operator)
so the message and key/value are correctly ordered.
klog.ErrorS(errors.New("Unsupported MatchCondition operator"), "operator", matchCondition.Operator) | |
klog.ErrorS(errors.New("Unsupported MatchCondition operator"), "Unsupported MatchCondition operator", "operator", matchCondition.Operator) |
Copilot uses AI. Check for mistakes.
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.
Code Review
The pull request transitions the clusterTaintPolicyController
to use structured logging. Key areas for improvement include clarifying key names in structured logs, correctly using klog.InfoS
with structured logging, and fixing a bug in one klog.ErrorS
call that suppresses the intended error log.
return controllerruntime.Result{}, client.IgnoreNotFound(err) | ||
} | ||
|
||
clusterTaintPolicyList := &policyv1alpha1.ClusterTaintPolicyList{} | ||
listOption := &client.ListOptions{UnsafeDisableDeepCopy: ptr.To(true)} | ||
if err := c.Client.List(ctx, clusterTaintPolicyList, listOption); err != nil { | ||
klog.Errorf("Failed to list ClusterTaintPolicy, error: %v", err) | ||
klog.ErrorS(err, "Failed to list ClusterTaintPolicy", "clusterTaintPolicyList", listOption) |
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.
The key "clusterTaintPolicyList"
is the variable name, but the value being logged is listOption
. Consider using a more descriptive key like "listOptions"
to avoid confusion.
klog.ErrorS(err, "Failed to list ClusterTaintPolicy", "clusterTaintPolicyList", listOption) | |
klog.ErrorS(err, "Failed to list ClusterTaintPolicy", "listOptions", listOption) |
@@ -235,7 +236,7 @@ func (c *ClusterTaintPolicyController) SetupWithManager(mgr controllerruntime.Ma | |||
clusterList := &clusterv1alpha1.ClusterList{} | |||
listOption := &client.ListOptions{UnsafeDisableDeepCopy: ptr.To(true)} | |||
if err := c.Client.List(ctx, clusterList, listOption); err != nil { | |||
klog.Errorf("Failed to list Cluster, error: %v", err) | |||
klog.ErrorS(err, "Failed to list Cluster", "clusterList", listOption) |
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.
The key "clusterList"
is the variable name, but the value being logged is listOption
. Consider using a more descriptive key like "listOptions"
to avoid confusion.
klog.ErrorS(err, "Failed to list Cluster", "clusterList", listOption) | |
klog.ErrorS(err, "Failed to list Cluster", "listOptions", listOption) |
Signed-off-by: zzhang881 <[email protected]>
3abf3f4
to
0849492
Compare
Signed-off-by: zzhang881 <[email protected]> Signed-off-by: zhangsquared <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Signed-off-by: zhangsquared <[email protected]>
80ffaab
to
d77dedc
Compare
Signed-off-by: RainbowMango <[email protected]>
Signed-off-by: mszacillo <[email protected]>
Signed-off-by: Bhaumik Patel <[email protected]> namespace-sync-ctrl:Address comments Signed-off-by: Bhaumik Patel <[email protected]>
Signed-off-by: sdutta133 <[email protected]> linter issue Signed-off-by: sdutta133 <[email protected]> fix logging pattern Signed-off-by: sdutta133 <[email protected]>
Signed-off-by: wei-chenglai <[email protected]>
Signed-off-by: wei-chenglai <[email protected]>
Signed-off-by: lzhou286 <[email protected]> Fix test image Signed-off-by: lzhou286 <[email protected]> Fix linter Signed-off-by: lzhou286 <[email protected]> Fix linter Signed-off-by: lzhou286 <[email protected]>
Signed-off-by: RainbowMango <[email protected]>
… handle with clusterResourceBinding Signed-off-by: changzhen <[email protected]>
Bumps [sigstore/cosign-installer](https://github.com/sigstore/cosign-installer) from 3.9.0 to 3.9.1. - [Release notes](https://github.com/sigstore/cosign-installer/releases) - [Commits](sigstore/cosign-installer@v3.9.0...v3.9.1) --- updated-dependencies: - dependency-name: sigstore/cosign-installer dependency-version: 3.9.1 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]>
…resource usage Signed-off-by: zhzhuang-zju <[email protected]>
Signed-off-by: zhzhuang-zju <[email protected]>
Signed-off-by: wenhuwang <[email protected]>
Signed-off-by: Eugene Ryazanov <[email protected]>
Signed-off-by: Rituraj Singh <[email protected]> Add persistentprerune Signed-off-by: Rituraj Singh <[email protected]> Remove whitespace Signed-off-by: Rituraj Singh <[email protected]>
….com> Signed-off-by: Abhinav Kumar <[email protected]>
Signed-off-by: RainbowMango <[email protected]>
Bump sigs.k8s.io/custom-metrics-apiserver to v1.33.0 Bump controller-runtime to v0.21.0 Bump sigs.k8s.io/metrics-server to v0.7.1-0.20250620093659-55b4961bc1ec Signed-off-by: RainbowMango <[email protected]>
…R129416 Adopt Kubernetes breaking change: change storage interface in PR130400 Adopt Kubernetes breaking change: use CacheDelegator to replace Cacher in PR129443 Adopt Kubernetes breaking change: Refactor explain cmd in PR129784 Adopt controller-runtime changes: Deprecates result.requeue in PR3107 Adopt Kubernetes breaking change: disable watchlist in PR131359 Signed-off-by: changzhen <[email protected]> Signed-off-by: RainbowMango <[email protected]>
Bumps [aquasecurity/trivy-action](https://github.com/aquasecurity/trivy-action) from 0.31.0 to 0.32.0. - [Release notes](https://github.com/aquasecurity/trivy-action/releases) - [Commits](aquasecurity/trivy-action@0.31.0...0.32.0) --- updated-dependencies: - dependency-name: aquasecurity/trivy-action dependency-version: 0.32.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]>
…rces Signed-off-by: wei-chenglai <[email protected]>
Signed-off-by: zhzhuang-zju <[email protected]>
…controller Signed-off-by: yteng35 <[email protected]>
Signed-off-by: Mohamed Awnallah <[email protected]>
…uling Signed-off-by: mszacillo <[email protected]>
…r dispatching Signed-off-by: changzhen <[email protected]>
Signed-off-by: whitewindmills <[email protected]>
Signed-off-by: zhzhuang-zju <[email protected]>
…o#6526) Signed-off-by: Kai Zhang <[email protected]> Co-authored-by: Kai Zhang <[email protected]>
Signed-off-by: zzhang881 <[email protected]>
Signed-off-by: zzhang881 <[email protected]> Signed-off-by: zhangsquared <[email protected]>
…a into log-taint-controller
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #6539 +/- ##
==========================================
+ Coverage 45.43% 45.45% +0.02%
==========================================
Files 687 687
Lines 56334 56334
==========================================
+ Hits 25594 25608 +14
+ Misses 29140 29129 -11
+ Partials 1600 1597 -3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Keywords which can automatically close issues and at(@) or hashtag(#) mentions are not allowed in commit messages. The list of commits with invalid commit messages:
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. |
Adding label 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. |
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
JSON logging support. More details are highlighted in #6230.
Which issue(s) this PR fixes:
Fixes #
Part of #6230
Special notes for your reviewer:
Does this PR introduce a user-facing change?: