Skip to content

fix(clients): cache GetPublicClientConfig response to avoid redundant API calls - #7054

Open
mvanhorn wants to merge 2 commits into
flyteorg:masterfrom
mvanhorn:osc/6868-cache-public-client-config
Open

mvanhorn wants to merge 2 commits into
flyteorg:masterfrom
mvanhorn:osc/6868-cache-public-client-config

Conversation

@mvanhorn

Copy link
Copy Markdown

Tracking issue

Closes #6868

Why are the changes needed?

GetPublicClientConfig is called up to 4 times during client initialization (token_source_provider.go:64, client.go:100, auth_interceptor.go:142, oauth/config.go:22). The response contains static server configuration (client ID, redirect URI, scopes, audience, authorization metadata key) that does not change at runtime.

As noted in the issue, this shows up as unnecessary API call volume on monitoring dashboards. The success criteria from the issue is reducing these calls to 0 after the first fetch.

What changes were proposed in this pull request?

Added a cachedMetadataClient decorator in flyteidl/clients/go/admin/cached_metadata_client.go that wraps AuthMetadataServiceClient and caches the GetPublicClientConfig response using sync.Once. The first call makes the RPC; subsequent calls return the cached result.

The decorator is applied in InitializeAuthMetadataClient (client.go:124), which is the single point where the auth metadata client is created. All 4 downstream call sites automatically benefit from caching without any changes.

GetOAuth2Metadata is not cached in this PR since it's called less frequently and serves a different purpose, but the same pattern could be applied if needed.

How was this patch tested?

  • go fmt ./... and go vet ./clients/go/admin/... pass clean
  • The sync.Once pattern is well-established for this use case. The cached value is immutable after first write, so there are no concurrency concerns.

This contribution was developed with AI assistance (Claude Code + Codex).

Labels

  • changed: Caches previously redundant API calls.

… API calls

The GetPublicClientConfig gRPC call returns static server configuration
(client ID, redirect URI, scopes, audience, auth metadata key) that does
not change at runtime. It was being called up to 4 times during client
initialization.

This wraps the AuthMetadataServiceClient returned by
InitializeAuthMetadataClient with a sync.Once-based caching decorator
so the RPC is made at most once per client lifetime.

Closes flyteorg#6868

Signed-off-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
@codecov

codecov Bot commented Mar 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.95%. Comparing base (f3ab1b7) to head (fade50d).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7054   +/-   ##
=======================================
  Coverage   56.95%   56.95%           
=======================================
  Files         931      932    +1     
  Lines       58188    58195    +7     
=======================================
+ Hits        33141    33147    +6     
- Misses      22005    22006    +1     
  Partials     3042     3042           
Flag Coverage Δ
unittests-datacatalog 53.51% <ø> (ø)
unittests-flyteadmin 53.14% <ø> (ø)
unittests-flytecopilot 43.06% <ø> (ø)
unittests-flytectl 64.02% <ø> (ø)
unittests-flyteidl 75.82% <100.00%> (+0.11%) ⬆️
unittests-flyteplugins 60.15% <ø> (ø)
unittests-flytepropeller 53.65% <ø> (ø)
unittests-flytestdlib 63.00% <ø> (-0.03%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI 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.

Pull request overview

This PR reduces redundant Flyte Admin RPC traffic during client initialization by caching the AuthMetadataServiceClient.GetPublicClientConfig response, since it represents static server-side configuration.

Changes:

  • Added a cachedMetadataClient decorator that memoizes GetPublicClientConfig results.
  • Wrapped the auth metadata client created by InitializeAuthMetadataClient with the caching decorator.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
flyteidl/clients/go/admin/client.go Wraps the created auth metadata client with the caching decorator so downstream callers automatically benefit.
flyteidl/clients/go/admin/cached_metadata_client.go Implements the caching decorator using sync.Once to avoid redundant GetPublicClientConfig RPCs.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

A failed GetPublicClientConfig call (transient RPC error, cancelled
context) was cached forever by sync.Once. Guard the cache with a mutex
and store only successful responses so later calls retry. Add tests for
concurrent callers and retry after errors.

Signed-off-by: Matt Van Horn <mvanhorn@gmail.com>
@github-actions github-actions Bot added the flyte label Oct 29, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid unnecessary calls for static data in client config

2 participants