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 probes cache #1401

Merged
merged 2 commits into from
Nov 9, 2021
Merged

Conversation

pierDipi
Copy link
Member

@pierDipi pierDipi commented Nov 3, 2021

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

  • Add probes cache

Release Note

None

Docs

None

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>
@google-cla google-cla bot added the cla: yes Indicates the PR's author has signed the CLA. label Nov 3, 2021
@knative-prow-robot knative-prow-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. area/control-plane labels Nov 3, 2021
@codecov
Copy link

codecov bot commented Nov 3, 2021

Codecov Report

Merging #1401 (ef9684e) into main (c73237e) will decrease coverage by 4.90%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             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     
Flag Coverage Δ
java-unittests 82.28% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
control-plane/pkg/prober/cache.go 100.00% <100.00%> (ø)
control-plane/pkg/reconciler/source/controller.go 72.34% <0.00%> (-27.66%) ⬇️
control-plane/pkg/reconciler/kafka/topic.go 97.67% <0.00%> (-2.33%) ⬇️
control-plane/pkg/core/config/resource.go 100.00% <0.00%> (ø)
control-plane/pkg/reconciler/sink/kafka_sink.go 67.83% <0.00%> (ø)
...lane/pkg/reconciler/base/receiver_condition_set.go 0.00% <0.00%> (ø)
control-plane/pkg/config/env_config.go
control-plane/pkg/reconciler/channel/controller.go 85.71% <0.00%> (ø)
control-plane/pkg/reconciler/channel/channel.go 0.00% <0.00%> (ø)
control-plane/pkg/reconciler/broker/broker.go 70.44% <0.00%> (+0.14%) ⬆️
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c73237e...ef9684e. Read the comment docs.

@aliok
Copy link
Member

aliok commented Nov 8, 2021

Looks good, but where's this gonna be used? Like, there's no integration right now

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)
Copy link
Contributor

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 ? 😄

Copy link
Member Author

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

Copy link
Member Author

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.

onExpired ExpiredFunc
}

func NewInMemoryLocalCache(ctx context.Context, expireDuration time.Duration) Cache {
Copy link
Contributor

Choose a reason for hiding this comment

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

expireDuration -> expiration ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

// This allows fast deletion of expired entries.
entries *list.List

expireDuration time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

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

expireDuration -> expiration ?

Copy link
Contributor

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 ?

Copy link
Contributor

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)

Copy link
Member Author

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.

}

// ExpiredFunc is a callback called once an entry in the cache is expired.
type ExpiredFunc func(key string, arg interface{})
Copy link
Contributor

Choose a reason for hiding this comment

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

ExpirationFunc?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!

// ExpiredFunc is a callback called once an entry in the cache is expired.
type ExpiredFunc func(key string, arg interface{})

type inMemoryLocalCache struct {
Copy link
Contributor

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 ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done, localExpiringCache

@pierDipi
Copy link
Member Author

pierDipi commented Nov 9, 2021

Looks good, but where's this gonna be used? Like, there's no integration right now

Integration in a separate PR.

This cache will be added as a reconciler field and used in ReconcilerKind and FinalizeKind.

Signed-off-by: Pierangelo Di Pilato <pdipilat@redhat.com>
@knative-metrics-robot
Copy link

The following is the coverage report on the affected files.
Say /test pull-knative-sandbox-eventing-kafka-broker-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
control-plane/pkg/prober/cache.go Do not exist 96.9%

@pierDipi pierDipi requested a review from matzew November 9, 2021 07:43
Copy link
Contributor

@matzew matzew left a 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 :-)

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Nov 9, 2021
@knative-prow-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@knative-prow-robot knative-prow-robot merged commit 67f0993 into knative-extensions:main Nov 9, 2021
@pierDipi pierDipi deleted the SRVKE-957 branch November 10, 2021 10:51
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. area/control-plane cla: yes Indicates the PR's author has signed the CLA. lgtm Indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants