-
Notifications
You must be signed in to change notification settings - Fork 109
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 probes cache #1401
Add probes cache #1401
Conversation
This patch adds a probe cache that allows to associate a `Status` to a given key. The cache prunes expired entries and calls a callback when an entry is expired, so that controllers can re-queue associated resources. Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>
Codecov Report
@@ Coverage Diff @@
## main #1401 +/- ##
============================================
- Coverage 76.57% 71.66% -4.91%
Complexity 584 584
============================================
Files 99 101 +2
Lines 3607 3999 +392
Branches 165 166 +1
============================================
+ Hits 2762 2866 +104
- Misses 635 915 +280
- Partials 210 218 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Looks good, but where's this gonna be used? Like, there's no integration right now |
control-plane/pkg/prober/cache.go
Outdated
GetStatus(key string) Status | ||
// UpsertStatus add or updates the status associated with the given key. | ||
// Once the given key expires the onExpired callback will be called passing the arg parameter. | ||
UpsertStatus(key string, status Status, arg interface{}, onExpired ExpiredFunc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about something like PutIfAbsent
? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be just put
?
This is doing a replace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PutStatus
works for me, even though I think UpsertStatus
conveys better the idea of adding or replacing something.
control-plane/pkg/prober/cache.go
Outdated
onExpired ExpiredFunc | ||
} | ||
|
||
func NewInMemoryLocalCache(ctx context.Context, expireDuration time.Duration) Cache { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expireDuration
-> expiration
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
control-plane/pkg/prober/cache.go
Outdated
// This allows fast deletion of expired entries. | ||
entries *list.List | ||
|
||
expireDuration time.Duration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expireDuration -> expiration ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't that typically called ttl
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not typically. I like expiration
over ttl
. I think expiring is stronger than ttl
(heavily biased based on heavy usage of a sweet library like https://github.com/jhalterman/expiringmap - which this PR is bascially also trying to do)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using expiration, for now, I think we all get the meaning of this variable with that name.
control-plane/pkg/prober/cache.go
Outdated
} | ||
|
||
// ExpiredFunc is a callback called once an entry in the cache is expired. | ||
type ExpiredFunc func(key string, arg interface{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExpirationFunc
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
control-plane/pkg/prober/cache.go
Outdated
// ExpiredFunc is a callback called once an entry in the cache is expired. | ||
type ExpiredFunc func(key string, arg interface{}) | ||
|
||
type inMemoryLocalCache struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd call that different, and express that the cache has some built-in expiration
localExpiringCache
?
Do we really need the "inMemory" in the name? If so: inMemoryLocalExpiringCache
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, localExpiringCache
Integration in a separate PR. This cache will be added as a reconciler field and used in |
Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>
The following is the coverage report on the affected files.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
/approve
thanks for addressing the comments.
Perhaps even worth to extract as a lib :-)
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: matzew, pierDipi 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 |
This patch adds a probe cache that allows to associate a
Status
to a given key.
The cache prunes expired entries and calls a callback when
an entry is expired, so that controllers can re-queue associated
resources.
This is part of our work to reduce e2e tests' flakiness.
Proposed Changes
Release Note
Docs