Skip to content

feat:structured logging - #29

Merged
karmada-bot merged 1 commit into
karmada-io:mainfrom
FAUST-BENCHOU:feat/structured-logging
Jan 12, 2026
Merged

feat:structured logging#29
karmada-bot merged 1 commit into
karmada-io:mainfrom
FAUST-BENCHOU:feat/structured-logging

Conversation

@FAUST-BENCHOU

Copy link
Copy Markdown
Member

What type of PR is this?

What this PR does / why we need it:

Which issue(s) this PR fixes:
Fixes #26

Special notes for your reviewer:

You can use logging-format like below

multicluster-cloud-provider % ./controller-manager --logging-format=json --multicluster-provider=fake --provider-ingress-class=fake
{"ts":1766906188213.9038,"caller":"app/manager.go:104","msg":"multicluster-controller-manager version: version.Info{GitVersion:\"v0.0.0-master\", GitCommit:\"unknown\", GitShortCommit:\"unknown\", GitTreeState:\"unknown\", BuildDate:\"unknown\", GoVersion:\"go1.25.1\", Compiler:\"gc\", Platform:\"darwin/arm64\"}","v":0}
{"ts":1766906188216.369,"caller":"cluster/cluster.go:170","msg":"Failed to get API Group-Resources","err":"Get \"https://127.0.0.1:64753/api?timeout=32s\": dial tcp 127.0.0.1:64753: connect: connection refused"}
{"ts":1766906188216.387,"caller":"app/manager.go:137","msg":"Failed to build controller manager: Get \"https://127.0.0.1:64753/api?timeout=32s\": dial tcp 127.0.0.1:64753: connect: connection refused"}
{"ts":1766906188216.395,"caller":"cli/run.go:72","msg":"command failed","err":"Get \"https://127.0.0.1:64753/api?timeout=32s\": dial tcp 127.0.0.1:64753: connect: connection refused"}

Does this PR introduce a user-facing change?:


@karmada-bot

Copy link
Copy Markdown
Contributor

Welcome @FAUST-BENCHOU! It looks like this is your first PR to karmada-io/multicluster-cloud-provider 🎉

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @FAUST-BENCHOU, 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 enhances the multicluster-controller-manager by integrating structured logging. This change improves the observability of the application by enabling logs to be generated in a consistent, machine-readable format, which is crucial for efficient analysis and monitoring in complex distributed systems. It modernizes the logging infrastructure by adopting Kubernetes' component-base/logs/api/v1 package for configuration.

Highlights

  • Structured Logging Implementation: This pull request introduces structured logging capabilities to the multicluster-controller-manager, allowing logs to be output in a machine-readable format, such as JSON.
  • Logging Configuration Update: The logging flag handling has been migrated from klogflag to k8s.io/component-base/logs/api/v1, providing a more standardized way to configure logging options, including the --logging-format flag.
  • Early Logging Application: The structured logging configuration is now applied early in the application's Run function to ensure all subsequent logs adhere to the specified format.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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

  1. 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.

@karmada-bot karmada-bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 28, 2025

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request successfully adds support for structured logging by integrating the k8s.io/component-base/logs package. The implementation correctly introduces the necessary options, command-line flags, and initialization logic to enable formats like JSON, which is a significant improvement for observability.

To fully capitalize on this new feature, I recommend a follow-up effort to refactor existing logging statements. For instance, calls like klog.Infof and klog.Errorf could be converted to their structured counterparts, klog.InfoS and klog.ErrorS. A good example is the version logging in app/manager.go, which could be changed from klog.Infof("multicluster-controller-manager version: %s", version.Get()) to klog.InfoS("multicluster-controller-manager version", "version", version.Get()). This would log the version details as a structured object, making the logs much easier to parse and query automatically. Adopting this pattern throughout the codebase would greatly enhance the utility of the structured logging feature you've introduced.

@XiShanYongYe-Chang

Copy link
Copy Markdown
Member

Thanks~
/assign

@XiShanYongYe-Chang XiShanYongYe-Chang 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.

Thanks a lot @FAUST-BENCHOU

I noticed a few differences compared to the changes made in the Karmada main repository. I want to confirm whether these also need to be modified.

flush log in the main function:

        // Ensure any buffered log entries are flushed
	logs.FlushLogs()

and other questions in the comments.

Comment thread app/manager.go Outdated
func Run(ctx context.Context, opts *options.MultiClusterControllerManagerOptions, cloudProvider multiclusterprovider.Interface) error {
// Apply structured logging configuration
// This must be called as early as possible to apply the logging format
if err := logsapi.ValidateAndApply(opts.Logging, nil); err != nil {

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.

ValidateAndApply has been added to the PersistentPreRunE function under cmd, and some feature gates have been included. Do we also need the same setup and provide these feature gates?

https://github.com/karmada-io/karmada/blob/010b8024926b0de6a77342fa6fd93dc3819d81ff/pkg/features/features.go#L84-L105

Comment thread app/manager.go
// Set logging flags
logsFlagSet := fss.FlagSet("logs")
klogflag.Add(logsFlagSet)
// Add logging configuration flags including --logging-format

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.

Should we set logsFlagSet as follows?

logs.AddFlags(logsFlagSet, logs.SkipLoggingConfigurationFlags())

@karmada-bot karmada-bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Dec 29, 2025
@FAUST-BENCHOU

FAUST-BENCHOU commented Dec 31, 2025

Copy link
Copy Markdown
Member Author

Updated.Use default featuregate

@XiShanYongYe-Chang

Copy link
Copy Markdown
Member

Updated.Use default featuregate

Thanks~, let me take a look.

@FAUST-BENCHOU
FAUST-BENCHOU force-pushed the feat/structured-logging branch from 045961d to 8acfe9f Compare January 4, 2026 11:49
@FAUST-BENCHOU

Copy link
Copy Markdown
Member Author
image image

@FAUST-BENCHOU

Copy link
Copy Markdown
Member Author

image image

useless now,the feature gate log will not print out

@XiShanYongYe-Chang

Copy link
Copy Markdown
Member

Thanks
/lgtm
cc @RainbowMango

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 7, 2026

@RainbowMango RainbowMango 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.

/assign

@RainbowMango

Copy link
Copy Markdown
Member

Looks good to me, but would you mind squashing the commits? https://karmada.io/docs/next/contributor/github-workflow/#squash-commits

@FAUST-BENCHOU
FAUST-BENCHOU force-pushed the feat/structured-logging branch from 7fee772 to c9555f9 Compare January 10, 2026 06:46
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 10, 2026
@FAUST-BENCHOU

Copy link
Copy Markdown
Member Author

@RainbowMango sure and sorry for the dely.updated now

@RainbowMango RainbowMango 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
/approve

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2026
@karmada-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: RainbowMango

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:

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

@karmada-bot karmada-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 12, 2026
Signed-off-by: zhoujinyu <2319109590@qq.com>
@FAUST-BENCHOU
FAUST-BENCHOU force-pushed the feat/structured-logging branch from c9555f9 to 828acab Compare January 12, 2026 02:47
@karmada-bot karmada-bot removed the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2026
@FAUST-BENCHOU

Copy link
Copy Markdown
Member Author

@RainbowMango lint has been fixed,i have tested it in my own repo and ci should pass now.a LGTM label is needed.Thanks for your review :)

@RainbowMango

Copy link
Copy Markdown
Member

/lgtm
Thanks.

@karmada-bot karmada-bot added the lgtm Indicates that a PR is ready to be merged. label Jan 12, 2026
@karmada-bot
karmada-bot merged commit 8696624 into karmada-io:main Jan 12, 2026
4 checks passed
@RainbowMango

Copy link
Copy Markdown
Member

/kind feature
(for testing prow)

@karmada-bot karmada-bot added the kind/feature Categorizes issue or PR as related to a new feature. label Jan 26, 2026
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Structured Logging for multicluster-cloud-provider

4 participants