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 logging guidelines #182

Merged
merged 3 commits into from
Jan 17, 2025
Merged

Conversation

liu-cong
Copy link
Contributor

@liu-cong liu-cong commented Jan 9, 2025

This is the first attempt to define logging guidelines in our current code base. This is not meant to be perfect/permanent, but something that can improve our logging quickly.

I am happy to follow up with a PR to update logging once this is approved.

Related issue: #108

cc @danehans @ahg-g

@k8s-ci-robot k8s-ci-robot requested a review from ahg-g January 9, 2025 23:30
@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 9, 2025
@k8s-ci-robot k8s-ci-robot requested a review from kfswain January 9, 2025 23:30
@k8s-ci-robot k8s-ci-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 9, 2025
@kfswain
Copy link
Collaborator

kfswain commented Jan 10, 2025

This looks reasonable. Can we give a crisp name to each log level?

That would let us make some enums that we can expect to be used as the log level params. It'll give us semantics within the code that makes readability, and following this style decision a tad easier.

@liu-cong
Copy link
Contributor Author

This looks reasonable. Can we give a crisp name to each log level?

I added the definitions from the k8s logging guidelines. They didn't define "crisp names" but I find it pretty helpful to follow. Pls suggest names if you have better ideas. Thanks!

@kfswain
Copy link
Collaborator

kfswain commented Jan 10, 2025

I wonder if we do this anywhere else in K8s but we could do something like:

const(
REQUIRED=0
DEFAULT=1
VERBOSE_DEFAULT=2
DETAILED=3
DEBUG=5
TRACE=5
)

Names are a quick attempt and probably suck. But this would make reasoning about what log level to use a little easier and keeps someone from having to constantly refer to our dev guide in the middle of development.

@liu-cong
Copy link
Contributor Author

I wonder if we do this anywhere else in K8s but we could do something like:

const(
REQUIRED=0
DEFAULT=1
VERBOSE_DEFAULT=2
DETAILED=3
DEBUG=5
TRACE=5
)

Names are a quick attempt and probably suck. But this would make reasoning about what log level to use a little easier and keeps someone from having to constantly refer to our dev guide in the middle of development.

I like it. I think it covers most cases, and people can refer to the dev guide for more nuanced cases if unsure. Will wait to see if others have any suggestions, otherwise I will update the doc.

Copy link
Contributor

@danehans danehans left a comment

Choose a reason for hiding this comment

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

A few non-blocking nits.

/lgtm

docs/dev.md Show resolved Hide resolved
docs/dev.md Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 10, 2025
@danehans
Copy link
Contributor

@liu-cong you should also consider including a formatting subsection to resolve 2 from #108.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 14, 2025
Copy link

netlify bot commented Jan 14, 2025

Deploy Preview for gateway-api-inference-extension ready!

Name Link
🔨 Latest commit c0f4727
🔍 Latest deploy log https://app.netlify.com/sites/gateway-api-inference-extension/deploys/67893dfda26d55000839f043
😎 Deploy Preview https://deploy-preview-182--gateway-api-inference-extension.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@liu-cong
Copy link
Contributor Author

@liu-cong you should also consider including a formatting subsection to resolve 2 from #108.

@danehans I am skipping this for now. Also I think we can better address point 2 by creating a logger wrapper in common places to include those context.

@kfswain I slightly changed the logging level constant names you suggested. PTAL!

docs/dev.md Outdated Show resolved Hide resolved
docs/dev.md Outdated Show resolved Hide resolved

4. Metric scraping loops. These loops run at a very high frequency, and logs can be very spammy if not handled properly.
* `klog.V(DEBUG).InfoS`
* Transient errors/warnings, such as failure to get response from a pod.
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be logged as error so that it shows up clearly in the logs for the platform admin

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This loop runs very frequently (current default is 20ms). Even some transient error will create a spam. So I am suggesting using DEBUG for any logging here.

I think to solve the error visibility problem, we can have that in the debug loop under the "Misc" section below, which runs every 5s. Wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

ok, we can discuss on the specific implementation PRs.

docs/dev.md Outdated Show resolved Hide resolved
@kfswain
Copy link
Collaborator

kfswain commented Jan 16, 2025

Small comment, but otherwise LGTM! Thanks for doing this, I'll put a hold as well so others can still make a pass, fix small nits, what have you. But feel free to pull the hold off at your leisure.

/hold
/lgtm
/approve

@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 16, 2025
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 16, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: danehans, kfswain, liu-cong

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 Jan 16, 2025
@ahg-g
Copy link
Contributor

ahg-g commented Jan 16, 2025

/lgtm

@liu-cong
Copy link
Contributor Author

/unhold

@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 Jan 17, 2025
@k8s-ci-robot k8s-ci-robot merged commit fa40dc5 into kubernetes-sigs:main Jan 17, 2025
7 checks passed
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/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.

5 participants