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 Len and Capacity methods for ring buffer #321

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xigang
Copy link

@xigang xigang commented Dec 10, 2024

What type of PR is this?
/kind feature

What this PR does / why we need it:

Add Len and Capacity methods for Informer metrics to calculate numberOfPendingNotifications and sizeOfRingGrowing.

PR: kubernetes/kubernetes#129160

KEP: https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/4346-informer-metrics

type eventHandlerMetrics struct {

  // number of pending data
  numberOfPendingNotifications GaugeMetric

  // size of RingGrowring data
  sizeOfRingGrowing GaugeMetric

  // how long processing an item from informer reflector
  prcoessDuration  HistogramMetric
        
}

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Release note:

NONE

Signed-off-by: xigang <wangxigang2014@gmail.com>
@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Dec 10, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: xigang
Once this PR has been reviewed and has the lgtm label, please assign deads2k for approval. For more information see the Kubernetes Code Review Process.

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

@k8s-ci-robot
Copy link
Contributor

Welcome @xigang!

It looks like this is your first PR to kubernetes/utils 🎉. 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/utils 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 k8s-ci-robot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Dec 10, 2024
@xigang
Copy link
Author

xigang commented Dec 10, 2024

/cc @deads2k @liggitt @aojea PTAL

@k8s-ci-robot k8s-ci-robot requested a review from deads2k December 10, 2024 03:32
@k8s-ci-robot
Copy link
Contributor

@xigang: GitHub didn't allow me to request PR reviews from the following users: PTAL.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @deads2k PTAL

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-sigs/prow repository.

@xigang
Copy link
Author

xigang commented Dec 12, 2024

/assign @liggitt @aojea

@@ -70,3 +70,13 @@ func (r *RingGrowing) WriteOne(data interface{}) {
r.data[(r.readable+r.beg)%r.n] = data
r.readable++
}

Copy link
Member

Choose a reason for hiding this comment

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

does anything ever shrink this buffer?

Copy link
Author

@xigang xigang Dec 18, 2024

Choose a reason for hiding this comment

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

@liggitt No, this ring buffer implementation (RingGrowing) only grows and never shrinks. Looking at the code:

  1. The buffer starts with an initialSize specified in NewRingGrowing.
  2. When the buffer becomes full (r.readable == r.n), the WriteOne method doubles the size (newN := r.n * 2).
  3. There are no methods that reduce the size of the buffer.

If shrinking capability is needed, a method can be added to shrink the buffer when it becomes too empty (for example, when readability falls below a certain threshold, such as 25% of the capacity).

Thank you, liggitt, for reviewing the code.:)

@xigang
Copy link
Author

xigang commented Dec 29, 2024

ping @deads2k Please take a look.

@xigang
Copy link
Author

xigang commented Jan 4, 2025

@liggitt Can this PR be approved?

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/feature Categorizes issue or PR as related to a new feature. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants