Skip to content

Add metric for the number of elements in a cache #1782

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 1 commit into from
Aug 1, 2023

Conversation

StephenButtolph
Copy link
Contributor

Why this should be merged

As we convert some of our caches to be size based, the length of the cache is a useful metric.

How this works

Adds Len to the cache interface and tracks it in the metercacher

How this was tested

CI

Comment on lines +99 to +101
if c.elements == nil {
return 0
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: if resize() hasn't been called yet - c.elements may be nil

@@ -110,6 +117,10 @@ func (c *sizedLRU[K, V]) flush() {
c.currentSize = 0
}

func (c *sizedLRU[_, _]) len() int {
return c.elements.Len()
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need the nil check here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

no - elements is initialized in NewSizedLRU here

@StephenButtolph StephenButtolph merged commit 9ba776f into dev Aug 1, 2023
@StephenButtolph StephenButtolph deleted the add-cache-len-metrics branch August 1, 2023 00:54
@StephenButtolph StephenButtolph added this to the v1.10.6 milestone Aug 1, 2023
@StephenButtolph StephenButtolph added the monitoring This primarily focuses on logs, metrics, and/or tracing label Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
monitoring This primarily focuses on logs, metrics, and/or tracing
Projects
No open projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants