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

refactor(logging): add logging helper and minor refactor #1494

Closed
wants to merge 1 commit into from

Conversation

zarvd
Copy link
Contributor

@zarvd zarvd commented Apr 14, 2022

What type of PR is this?

What this PR does / why we need it:

Currently, logging seems arbitrary, and it mixed-use plain-text logging and structural logging. The PR tries to propose consistently using structural logging and introduces some helper functions to ease the pain of handling mass log fields.

Please feel free to add any input or suggestions!

Sample logs

E0414 18:26:13.043600   83448 azure_loadbalancer.go:107] "failed to reconcile load balancer" err="Retriable: false, RetryAfter: 0s, HTTPStatusCode: 404, RawError: instance not found" cluster="testCluster" service="default/service5"
I0414 18:26:13.043620   83448 azure_loadbalancer.go:158] "process finished" cluster="testCluster" service="default/service5" name="sigs.k8s.io/cloud-provider-azure/pkg/provider.(*Cloud).EnsureLoadBalancer" error="Retriable: false, RetryAfter: 0s, HTTPStatusCode: 404, RawError: instance not found" took-ms=0
I0414 18:26:13.043702   83448 azure_loadbalancer.go:214] "process started" cluster="testCluster" service="default/service5" service-spec="&Service{ObjectMeta:{service5  default  service5  0 0001-01-01 00:00:00 +0000 UTC <nil> <nil> map[] map[service.beta.kubernetes.io/azure-load-balancer-resource-group:random-rg] [] []  []},Spec:ServiceSpec{Ports:[]ServicePort{ServicePort{Name:port-tcp-80,Protocol:TCP,Port:80,TargetPort:{0 0 },NodePort:10080,AppProtocol:nil,},},Selector:map[string]string{},ClusterIP:10.0.0.2,Type:LoadBalancer,ExternalIPs:[],SessionAffinity:,LoadBalancerIP:,LoadBalancerSourceRanges:[],ExternalName:,ExternalTrafficPolicy:,HealthCheckNodePort:0,PublishNotReadyAddresses:false,SessionAffinityConfig:nil,IPFamilyPolicy:nil,ClusterIPs:[],IPFamilies:[],AllocateLoadBalancerNodePorts:nil,LoadBalancerClass:nil,InternalTrafficPolicy:nil,},Status:ServiceStatus{LoadBalancer:LoadBalancerStatus{Ingress:[]LoadBalancerIngress{},},Conditions:[]Condition{},},}" name="sigs.k8s.io/cloud-provider-azure/pkg/provider.(*Cloud).EnsureLoadBalancerDeleted"
W0414 18:26:13.043725   83448 azure_backoff.go:333] ListManagedLBs: no LBs found

refs:

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

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


@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 14, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @lodrem. Thanks for your PR.

I'm waiting for a kubernetes-sigs 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 the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 14, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lodrem
To complete the pull request process, please assign nilo19 after the PR has been reviewed.
You can assign the PR to them by writing /assign @nilo19 in a comment when ready.

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

@coveralls
Copy link

coveralls commented Apr 14, 2022

Coverage Status

Coverage increased (+0.0006%) to 80.285% when pulling 279ba10 on lodrem:refactor/logging-helper into 36999d0 on kubernetes-sigs:master.

@MartinForReal
Copy link
Contributor

IMHO, we could adopt https://github.com/go-logr/logr and https://opentelemetry.io/

@zarvd zarvd force-pushed the refactor/logging-helper branch from c7b6102 to 8924a3e Compare April 24, 2022 08:03
@zarvd
Copy link
Contributor Author

zarvd commented Apr 24, 2022

IMHO, we could adopt https://github.com/go-logr/logr and https://opentelemetry.io/

@MartinForReal
Is klog a wrapper for logr? Do you suggest that we use logr directly?
And for opentelemetry, the statuses of metrics and logging parts are not stable. Should we adopt it after its stable release?

@MartinForReal
Copy link
Contributor

logr is a simple log wrapper and klog is one of the supported backend implementations. https://github.com/kubernetes/klog/tree/main/klogr
I agree we should hold for opentelemetry adoption.

@MartinForReal
Copy link
Contributor

/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 Apr 25, 2022
@MartinForReal
Copy link
Contributor

/retest

@nilo19
Copy link
Contributor

nilo19 commented Apr 26, 2022

/kind cleanup

@k8s-ci-robot k8s-ci-robot added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Apr 26, 2022
@@ -22,6 +22,7 @@ import (
"fmt"
"math"
"reflect"
"sigs.k8s.io/cloud-provider-azure/pkg/logging"
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: please re-arrange the imports

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@nilo19
Copy link
Contributor

nilo19 commented Apr 26, 2022

do you plan to refactor other files too?

@lzhecheng
Copy link
Contributor

lzhecheng commented Apr 26, 2022

pkg/provider/azure_loadbalancer.go:25: File is not goimports-ed

Could you fix the problem?

@zarvd zarvd mentioned this pull request Apr 26, 2022
3 tasks
@zarvd
Copy link
Contributor Author

zarvd commented Apr 26, 2022

do you plan to refactor other files too?

Yes. I will refactor others afterward if the logging convention of this PR works for you guys.

And do you have any other thoughts about improving logging (and observability)? I open a new issue #1575 to discuss and gather more ideas. @nilo19 @MartinForReal @lzhecheng @feiskyer

@zarvd zarvd force-pushed the refactor/logging-helper branch from bb6c58c to 279ba10 Compare April 26, 2022 06:35
@k8s-ci-robot
Copy link
Contributor

@lodrem: 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
pull-cloud-provider-azure-e2e-ccm-capz 279ba10 link true /test pull-cloud-provider-azure-e2e-ccm-capz
pull-cloud-provider-azure-e2e-ccm-vmss 279ba10 link true /test pull-cloud-provider-azure-e2e-ccm-vmss
pull-cloud-provider-azure-e2e-ccm-vmss-basic-lb 279ba10 link true /test pull-cloud-provider-azure-e2e-ccm-vmss-basic-lb

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 1, 2022
@k8s-ci-robot
Copy link
Contributor

@lodrem: PR needs rebase.

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.

@zarvd zarvd closed this Jun 27, 2022
@zarvd zarvd deleted the refactor/logging-helper branch July 13, 2022 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants