Skip to content

[CRE] Refactor caching (fka fallback) OrgResolver - #2342

Merged
bolekk merged 3 commits into
mainfrom
org_cache_2
Sep 3, 2026
Merged

[CRE] Refactor caching (fka fallback) OrgResolver#2342
bolekk merged 3 commits into
mainfrom
org_cache_2

Conversation

@bolekk

@bolekk bolekk commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Change the behavior to always depend on the cached value (if available) to reduce the volume of calls. Only refresh periodically in the background (to recover from potential bad data).

Core counterpart: smartcontractkit/chainlink#23485

@github-actions

github-actions Bot commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

✅ API Diff Results - github.com/smartcontractkit/chainlink-common

✅ Compatible Changes (7)

pkg/services/orgresolver (7)
  • Cache — ➕ Added

  • CacheEntry — ➕ Added

  • CachingResolver — ➕ Added

  • CachingResolverConfig — ➕ Added

  • InMemoryCache — ➕ Added

  • NewCachingResolver — ➕ Added

  • NewInMemoryCache — ➕ Added


📄 View full apidiff report

@bolekk
bolekk force-pushed the org_cache_2 branch 2 times, most recently from 0fea694 to 036c1a8 Compare August 26, 2026 02:26
@bolekk bolekk changed the title [CRE] Caching OrgResolver [CRE] Refactor caching (fka fallback) OrgResolver Aug 26, 2026
@bolekk
bolekk force-pushed the org_cache_2 branch 2 times, most recently from cea4809 to 61a290e Compare August 26, 2026 02:54
@bolekk
bolekk marked this pull request as ready for review August 26, 2026 03:11
@bolekk
bolekk requested a review from a team as a code owner August 26, 2026 03:11
@bolekk
bolekk requested a review from jmank88 August 26, 2026 04:43
@jmank88

jmank88 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Can we find a way to evolve without breaking the API?

⚠️ Breaking Changes (2)
pkg/services/orgresolver (2)

  • NewOrgResolverWithFallback — 🗑️ Removed

  • OrgResolverFallback — 🗑️ Removed

Comment thread pkg/services/orgresolver/caching.go Outdated
Comment thread pkg/services/orgresolver/caching.go
Comment thread pkg/services/orgresolver/caching.go Outdated
Comment thread pkg/services/orgresolver/caching.go Outdated
Comment thread pkg/services/orgresolver/caching.go Outdated
Comment thread pkg/services/orgresolver/caching.go Outdated
@bolekk

bolekk commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@jmank88 I don't think it makes sense to keep old APIs since I renamed the file and types. It's not "fallback" any more.

@jmank88

jmank88 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@jmank88 I don't think it makes sense to keep old APIs since I renamed the file and types. It's not "fallback" any more.

Compilation compatibility trumps undesirable naming though. It doesn't make sense to arbitrarily break unrelated things because the names don't make sense.

@bolekk

bolekk commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@jmank88 I disagree. It's only used in a single place in core and the old name is now confusing. NewOrgResolverWithFallback - there's no fallback, cached values are the new source of truth.

@jmank88

jmank88 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

@jmank88 I disagree. It's only used in a single place in core and the old name is now confusing. NewOrgResolverWithFallback - there's no fallback, cached values are the new source of truth.

Having one callsite from one module does not mean that there is only one thing to worry about. There are multiple versions of core that may need patch releases that could encounter this. There are also manys modules that import core and could be affected by this. Coincidentally, I am currently blocked from acting on basic dependabot security alerts in Aptos, because a trivial dependency bump is not possible, since we deleted a bunch of API that is superficially not related.

@bolekk

bolekk commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@jmank88 to me this tradeoff is not worth it. But to move this PR forward, I brought back the old fallback resolver and marked it as deprecated - is that OK?

Comment thread pkg/services/orgresolver/fallback.go Outdated
select {
case <-ctx.Done():
return
case <-time.After(refreshOwnerDelay):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this be i*refreshOwnerDelay? if not, why have refreshOwnerDelay? the refreshLoop already waits for the refreshInterval.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Every 10 mins we cycle over all owners with 100ms gaps between them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is to smooth out the spike in traffic on eery refreshInterval. It will go away with batching anyway.


// The loop must outlive the Start call, so it gets its own context,
// cancelled explicitly by Close rather than inherited from ctx.
loopCtx, cancel := context.WithCancel(context.Background())

@patrickhuie19 patrickhuie19 Sep 3, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

/nit i believe you could use the stopCh context helper here instead of a raw context.Background()

@patrickhuie19 patrickhuie19 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

mostly lgtm with one q on owner specific delay

@bolekk
bolekk added this pull request to the merge queue Sep 3, 2026
Merged via the queue into main with commit 85b2080 Sep 3, 2026
32 of 33 checks passed
@bolekk
bolekk deleted the org_cache_2 branch September 3, 2026 15:32
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.

3 participants