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

Configure contextual and structured logging for NEG controller #1746

Merged
merged 2 commits into from
Jul 29, 2022

Conversation

gauravkghildiyal
Copy link
Member

@gauravkghildiyal gauravkghildiyal commented Jul 11, 2022

This PR incorporates changes suggested by structured logging (KEP) and contextual logging (KEP) into the NEG controller, which improves the overall observability of the logs.

Migration guide that was referred: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-instrumentation/migration-to-structured-logging.md

Changes introduced:

  • Update klog version from v1 to v2
  • All NEG controller log messages will be prefixed by NEGController
    Example:
    "NEGController: Starting network endpoint group controller"
    
  • Various sub-components like Syncer, ReadinessReflector, ClusterL4ILBEndpointsCalculator etc will also have their component name prefixed.
    Example:
    "NEGController/Syncer: Stopping NEG syncer for service port"
    ...
    "NEGController/ReadinessReflector: Starting NEG readiness reflector"
    
  • Syncer (as well as other some other sub-component logs), will include additional context like the name of the service and NEG.
    Example:
    "NEGController/Syncer: Stats for NEG" service="default/neg-demo-svc" negName="my-neg-name" description="desired NEG endpoints" stats="3 endpoints in zone \"us-central1-c\""
    

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 11, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @gauravkghildiyal!

It looks like this is your first PR to kubernetes/ingress-gce 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/ingress-gce has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @gauravkghildiyal. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 11, 2022
@gauravkghildiyal
Copy link
Member Author

/assign @swetharepakula

It would make sense to review the commits separately. The delta looks large, but the major contributor in this delta is the changes to the vendor directory introduced in the first commit "Update klog version to v2". The second commit "Add contextual logging to NEG controller and its components" is the one which includes the changes to the logs.

@swetharepakula
Copy link
Member

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 12, 2022
Copy link
Member

@swetharepakula swetharepakula left a comment

Choose a reason for hiding this comment

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

Thanks Gaurav! Comments are mostly on improving the log level of log lines and some suggestions to make the log line clearer.

cmd/glbc/main.go Outdated Show resolved Hide resolved
cmd/glbc/main.go Outdated Show resolved Hide resolved
pkg/neg/manager.go Show resolved Hide resolved
pkg/neg/manager.go Outdated Show resolved Hide resolved
pkg/neg/readiness/poller.go Outdated Show resolved Hide resolved
pkg/neg/syncers/transaction.go Show resolved Hide resolved
pkg/neg/syncers/transaction.go Outdated Show resolved Hide resolved
pkg/neg/syncers/transaction.go Outdated Show resolved Hide resolved
pkg/neg/syncers/transaction.go Outdated Show resolved Hide resolved
pkg/neg/syncers/transaction.go Outdated Show resolved Hide resolved
@gauravkghildiyal gauravkghildiyal force-pushed the contextLogging branch 2 times, most recently from 6473054 to 892bf61 Compare July 28, 2022 20:59
@spencerhance
Copy link
Contributor

lgtm

return
}
if endpointSlice, ok = tombstone.Obj.(*discovery.EndpointSlice); !ok {
klog.Errorf("Unexpected tombstone object type: %T, expected *discovery.EndpointSlice", obj)
c.logger.Error(nil, "Unexpected tombstone object type: %T, expected *discovery.EndpointSlice", "objectTypeFound", fmt.Sprintf("%T", obj))
Copy link
Member

Choose a reason for hiding this comment

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

remove the format %T in the error message.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@@ -541,16 +547,17 @@ func mergeTransactionIntoZoneEndpointMap(endpointMap map[string]negtypes.Network

// logStats logs aggregated stats of the input endpointMap
func (s *transactionSyncer) logStats(endpointMap map[string]negtypes.NetworkEndpointSet, desc string) {
stats := []string{}
stats := []interface{}{}
Copy link
Member

Choose a reason for hiding this comment

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

nit: var stats []interface{}

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

@swetharepakula
Copy link
Member

Thanks for all your work Gaurav. A few more small comments and this should be ready to merge.

Copy link
Member

@swetharepakula swetharepakula left a comment

Choose a reason for hiding this comment

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

Thanks for the change!

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gauravkghildiyal, swetharepakula

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:

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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jul 29, 2022
@k8s-ci-robot k8s-ci-robot merged commit c577834 into kubernetes:master Jul 29, 2022
@gauravkghildiyal gauravkghildiyal deleted the contextLogging branch July 29, 2022 20:34
gauravkghildiyal pushed a commit to gauravkghildiyal/ingress-gce that referenced this pull request Aug 26, 2022
Configure contextual and structured logging for NEG controller
sawsa307 added a commit to sawsa307/ingress-gce that referenced this pull request Oct 24, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
sawsa307 added a commit to sawsa307/ingress-gce that referenced this pull request Oct 27, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
sawsa307 added a commit to sawsa307/ingress-gce that referenced this pull request Oct 28, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
sawsa307 added a commit to sawsa307/ingress-gce that referenced this pull request Nov 1, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
sawsa307 added a commit to sawsa307/ingress-gce that referenced this pull request Nov 2, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
sawsa307 added a commit to sawsa307/ingress-gce that referenced this pull request Nov 2, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
sawsa307 added a commit to sawsa307/ingress-gce that referenced this pull request Nov 3, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
sawsa307 added a commit to sawsa307/ingress-gce that referenced this pull request Nov 4, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
sawsa307 added a commit to sawsa307/ingress-gce that referenced this pull request Nov 7, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
code-elinka pushed a commit to akhmanova/ingress-gce that referenced this pull request Nov 8, 2023
This PR is the continuation of kubernetes#1746(contextual logging for components
in NEG controller).
* Functions will accept a logger object from its caller, so the prefix
  will be determined based on the caller objects.
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. 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.

None yet

4 participants