Skip to content

feat: bounded cache for informers #1718

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 27 commits into from
Feb 21, 2023
Merged

feat: bounded cache for informers #1718

merged 27 commits into from
Feb 21, 2023

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Jan 13, 2023

No description provided.

@csviri csviri self-assigned this Jan 13, 2023
@csviri csviri force-pushed the bounded-cache-item-store branch from c4ffb56 to 1dbe752 Compare January 19, 2023 09:23
@csviri csviri force-pushed the next branch 2 times, most recently from 5aefd80 to 4af2cc5 Compare January 30, 2023 14:38
@csviri csviri force-pushed the bounded-cache-item-store branch from a35083d to fd65df4 Compare January 31, 2023 12:57
@csviri csviri force-pushed the next branch 3 times, most recently from fe820ca to 55f5d0b Compare February 8, 2023 13:50
@csviri csviri force-pushed the bounded-cache-item-store branch from fd65df4 to dba990f Compare February 10, 2023 08:31
@csviri csviri changed the title feat: bounded cache (variant 2) feat: bounded cache for informers Feb 13, 2023
@csviri csviri force-pushed the bounded-cache-item-store branch from c03cd5a to 63c30ed Compare February 15, 2023 08:25
@csviri csviri marked this pull request as ready for review February 15, 2023 13:25
@csviri csviri requested a review from metacosm February 15, 2023 13:26
@@ -72,6 +72,7 @@
<directory-maven-plugin.version>1.0</directory-maven-plugin.version>
<impsort-maven-plugin.version>1.8.0</impsort-maven-plugin.version>
<okhttp.version>4.10.0</okhttp.version>
<caffein.version>3.1.3</caffein.version>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Everything caffeine-related should be named appropriately i.e. caffeine (with an e at the end)

@@ -122,4 +123,23 @@ default Set<String> getEffectiveNamespaces() {
}
return targetNamespaces;
}

/**
* See <a href=
Copy link
Collaborator

Choose a reason for hiding this comment

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

This needs a better documentation, especially considering that the link doesn't actually provide any information.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated.

synchronized (this) {
log.debug("Fetched resource: {}", newRes);
if (newRes == null) {
existingMinimalResources.remove(key);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't we also remove the associated object from the cache?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

will revisit this, came to my mind that there an case, where the current impl might be a problem of this method

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

made an update for this, to be absolutely safe

}

/**
* This would not be needed
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you elaborate, please?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this was a leftover, removed.

@metacosm metacosm force-pushed the bounded-cache-item-store branch from 8c801ae to c4647a1 Compare February 20, 2023 20:11
// If received we just return. Since the resource from informer should be always leading,
// even if the fetched resource is null, this will be eventually received as an event.
if (actual == null) {
existingMinimalResources.remove(key);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I still think that actual should be removed from cache as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why?
its checked 2 lines above if it's there, and that operation is synchronized with other operation for that cache. It is not possible to put that item into the cache meanwhile.

@csviri csviri force-pushed the bounded-cache-item-store branch from 08caef2 to 226be1e Compare February 21, 2023 12:24
@csviri csviri force-pushed the bounded-cache-item-store branch from 226be1e to 50e351a Compare February 21, 2023 14:08
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 6 Code Smells

38.9% 38.9% Coverage
0.0% 0.0% Duplication

@csviri csviri merged commit 19b91a5 into next Feb 21, 2023
@csviri csviri deleted the bounded-cache-item-store branch February 21, 2023 15:31
@csviri csviri linked an issue Feb 21, 2023 that may be closed by this pull request
csviri added a commit that referenced this pull request Feb 23, 2023
csviri added a commit that referenced this pull request Feb 28, 2023
csviri added a commit that referenced this pull request Mar 3, 2023
csviri added a commit that referenced this pull request Mar 10, 2023
csviri added a commit that referenced this pull request Mar 14, 2023
csviri added a commit that referenced this pull request Mar 15, 2023
metacosm pushed a commit that referenced this pull request Mar 22, 2023
metacosm pushed a commit that referenced this pull request Mar 27, 2023
metacosm pushed a commit that referenced this pull request Mar 27, 2023
csviri added a commit that referenced this pull request Mar 27, 2023
metacosm pushed a commit that referenced this pull request Mar 27, 2023
metacosm pushed a commit that referenced this pull request Mar 27, 2023
metacosm added a commit that referenced this pull request Mar 27, 2023
* feat: bounded cache for informers (#1718)

* fix: typo caffein -> caffeine (#1795)

* feat: now possible to only output non-resource related metrics

Fixes #1812.

* refactor: extract abstract test fixture to add tests with variations

* fix: add missing annotation

* tests: add more test variations

* fix: make operator non-static so it's registered once per test subclass

* feat: introduce builder for MicrometerMetrics, fix test

* fix: exclude more tags when not collecting per resource

* fix: registry should be per-instance to ensure test independence

* fix: make sure we wait a little to ensure event is properly processed

* fix: make things work on Java 11, format

* fix: also clean metrics on finalizer removal

This is needed because the finalizer will trigger a reconciliation that
adds a resource-specific metric.

* fix: format

* refactor: extract common tags

Co-authored-by: Sébastien CROCQUESEL <88554524+scrocquesel@users.noreply.github.com>

* feat: make per-resource collecting finer-grained

We now still collect GVK information when per-resource collection is
switched off.

* fix: do not create tag for group if not present

* fix: remove unreliable no-delay implementation, defaulting to 1s delay

* refactor: renamed & documented factory methods to make things clearer

* docs: updated metrics section for code changes

* feat: avoid emitting tag on empty value

* docs: update

* fix: format

[skip ci]

* refactor: use Tag more directly, avoid unneeded work, use constants

* fix: change will happen instead of might

* docs: add missing timer

Co-authored-by: Sébastien CROCQUESEL <88554524+scrocquesel@users.noreply.github.com>

* docs: fix wrong & missing information

* refactor: add constants

* fix: wording

[skip ci]

Co-authored-by: Attila Mészáros <csviri@gmail.com>

---------

Co-authored-by: Attila Mészáros <csviri@gmail.com>
Co-authored-by: Sébastien CROCQUESEL <88554524+scrocquesel@users.noreply.github.com>
csviri added a commit that referenced this pull request Mar 28, 2023
csviri added a commit that referenced this pull request Mar 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Limited Cache Sizes
2 participants