Skip to content

removed time.sleep and using ticker instead #648

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

Merged
merged 4 commits into from
Apr 4, 2025

Conversation

nirrozenbaum
Copy link
Contributor

fix #647.

in some places in the code, there is a periodic task needs to be executed and the code is using time.sleep which is a bad practice.
for example, time.sleep may cause delays when receiving SIGTERM - if the go routine started the sleep section we will need to wait until sleep competes and only then the go routine will exist (due to context close).

the Go way for doing periodic task endlessly (until a cancel/close is received) is by using ticker.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Apr 3, 2025
@k8s-ci-robot k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Apr 3, 2025
Copy link

netlify bot commented Apr 3, 2025

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

Name Link
🔨 Latest commit 926260a
🔍 Latest deploy log https://app.netlify.com/sites/gateway-api-inference-extension/deploys/67eee1113a9ba8000896104e
😎 Deploy Preview https://deploy-preview-648--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

liu-cong commented Apr 3, 2025

/lgtm
/approve

Thanks!

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 3, 2025
@nirrozenbaum
Copy link
Contributor Author

/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 Apr 3, 2025
make sure refresh internal is valid at the ticker creation time

Signed-off-by: Nir Rozenbaum <[email protected]>
once ticker was introduced instead of sleep, having 0 as the refresh internal is not valid.

Signed-off-by: Nir Rozenbaum <[email protected]>
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Apr 3, 2025
…ly on the values.

up until now, the metrics go routine ran in tests with time.Sleep(0), which means metrics were avaiable immediately.
while in tests in might be acceptable to wait few seconds using sleep, in the actual code (not tests) it's a bad practice to use
sleep which was replaced with a ticker (to perform periodic task in an endless loop).

Signed-off-by: Nir Rozenbaum <[email protected]>
@liu-cong
Copy link
Contributor

liu-cong commented Apr 3, 2025

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 3, 2025
@nirrozenbaum
Copy link
Contributor Author

/retest

@nirrozenbaum
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 Apr 3, 2025
@ahg-g
Copy link
Contributor

ahg-g commented Apr 4, 2025

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ahg-g, liu-cong, nirrozenbaum

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 Apr 4, 2025
@k8s-ci-robot k8s-ci-robot merged commit 2759e3f into kubernetes-sigs:main Apr 4, 2025
8 checks passed
@nirrozenbaum nirrozenbaum deleted the remove-sleep branch April 5, 2025 03:32
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.

code is using time.Sleep when doing periodic task
4 participants