Skip to content
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

Add context logging for all controllers #2436

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

alexkats
Copy link
Member

@alexkats alexkats commented Jan 17, 2024

This PR adds context logging, with these changes we'll have only one root logger, and all other loggers are children, which gives us the ability to track the context of the source of a log line. It also changes the way of logging, we have a pair of key/values instead of formatting string. It gives the ability to introduce a logger with some common key/value pairs and not repeat them every time in the following log lines. As an example, when we process some service and have 20 log lines, we can create a new logger with serviceKey and it will be logged in all of those 20 lines. This PR aims to do only the first iteration of introducing context loggers everywhere, and in order not to make it even bigger, all other improvements (especially with more complex contexts and loggers with specified key/value pair) will be in the follow-up PRs.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 17, 2024
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 17, 2024
@alexkats
Copy link
Member Author

/assign @cezarygerard
/assign @swetharepakula

pkg/backends/backends.go Outdated Show resolved Hide resolved
Copy link
Contributor

@sawsa307 sawsa307 left a comment

Choose a reason for hiding this comment

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

Add some comments in pkg/healthshecks and pkg/backends. Most comments apply for other places too. PTAL!

pkg/backends/backends.go Outdated Show resolved Hide resolved
pkg/backends/backends.go Outdated Show resolved Hide resolved
pkg/backends/backends.go Outdated Show resolved Hide resolved
pkg/backends/backends.go Outdated Show resolved Hide resolved
pkg/backends/backends.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks.go Outdated Show resolved Hide resolved
pkg/healthchecks/healthchecks.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 18, 2024
@alexkats
Copy link
Member Author

Waiting for #2317 and #2335 to go in
/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jan 18, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 9, 2024
@alexkats
Copy link
Member Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 12, 2024
@@ -81,16 +81,17 @@ func main() {
os.Exit(0)
}

klog.V(0).Infof("Starting GLBC image: %q, cluster name %q", version.Version, flags.F.ClusterName)
klog.V(0).Infof("Latest commit hash: %q", version.GitCommit)
rootLogger := klog.TODO()
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should use klog.Background() here? I tried finding a recommended way of creating a new root logger but I have no idea

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know as well, but TODO() technically just invokes Background()

@@ -109,18 +111,21 @@ type L4ILBParams struct {
}

// NewL4Handler creates a new L4Handler for the given L4 service.
func NewL4Handler(params *L4ILBParams) *L4 {
func NewL4Handler(params *L4ILBParams, logger klog.Logger) *L4 {
logger = logger.WithName("L4Handler")
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should also do .WithValues("service", svcKey) here so that all lines produced by this handler have service details?
we could do this as a follow up not to make things too complicated

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe if we do this right then we can get rid of the "serviceKey" key that is added to many log lines in the handlers

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, but I'd rather postpone it for a follow-up. It feels like we already have a lot of changes, so I'd suggest to have straightforward change from klog... to context logger, and then have another PR with all the improvements


if ctx.NetworkInformer != nil {
l4c.networkLister = ctx.NetworkInformer.GetIndexer()
}
if ctx.GKENetworkParamsInformer != nil {
l4c.gkeNetworkParamSetLister = ctx.GKENetworkParamsInformer.GetIndexer()
}
l4c.networkResolver = network.NewNetworksResolver(l4c.networkLister, l4c.gkeNetworkParamSetLister, ctx.Cloud, ctx.EnableMultinetworking, klog.TODO())
l4c.networkResolver = network.NewNetworksResolver(l4c.networkLister, l4c.gkeNetworkParamSetLister, ctx.Cloud, ctx.EnableMultinetworking, logger)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I messed up the Resolver. Probably it should not keep the logger reference but instead accept a param when resolving the service network so that the lines from there have all context. I'll have to redo it later

@alexkats alexkats force-pushed the l4-context-logging branch 2 times, most recently from fa2022b to d254353 Compare March 5, 2024 14:41
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 5, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 6, 2024
@cezarygerard
Copy link
Contributor

Alex, add more description to this PR

  • what it gives us
  • why you chose to only 'replace' existing loggers in this PR (rather than utilize klog features)

@alexkats
Copy link
Member Author

alexkats commented Mar 6, 2024

Alex, add more description to this PR

  • what it gives us
  • why you chose to only 'replace' existing loggers in this PR (rather than utilize klog features)

Makes sense, thanks, added

@cezarygerard
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 6, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexkats, cezarygerard

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:
  • OWNERS [alexkats,cezarygerard]

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

@k8s-ci-robot k8s-ci-robot merged commit 699b699 into kubernetes:master Mar 6, 2024
5 checks passed
@alexkats alexkats deleted the l4-context-logging branch March 6, 2024 15:42
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants