Visitar URL original
perf(tool/looker): cache LookmlModelExplore metadata responses by juanpiRiv · Pull Request #4226 · googleapis/mcp-toolbox · GitHub
Skip to content

perf(tool/looker): cache LookmlModelExplore metadata responses - #4226

Open
juanpiRiv wants to merge 3 commits into
googleapis:mainfrom
juanpiRiv:fix/looker-explore-cache
Open

juanpiRiv wants to merge 3 commits into
googleapis:mainfrom
juanpiRiv:fix/looker-explore-cache

Conversation

@juanpiRiv

@juanpiRiv juanpiRiv commented Oct 6, 2026 •

Copy link
Copy Markdown

Description

Each Looker metadata tool (get_explore, get_dimensions, get_measures, get_filters, get_parameters) issues its own LookmlModelExplore API call for the same (model_name, explore_name) pair. An agent discovery loop inspecting N explores therefore burns ~5 API calls per explore of redundant traffic — significant against Looker's finite per-edition monthly API quotas (e.g. 1,000 admin calls/month on Google Cloud core Standard).

This PR adds a short-TTL (5 min) cache for LookmlModelExplore responses on the Looker Source, deduplicated with singleflight, following the same pattern as the existing Source.GetHostURL cache. The five tools now route through Source.GetLookmlModelExplore.

Cache key: model + explore + fields + add_drills_metadata + sha256(accessToken)[:16]. Keying by caller identity guarantees per-user field-level permissions are never served across users; service-account mode shares one identity, which is correct. Errors are never cached. The returned struct is a shallow copy shared across hits — documented on the method as read-only, matching what all five callers already do.

The cache is bounded: entries are purged on write once the map reaches exploreCacheMaxEntries (512), so long-running servers don't accumulate stale keys (e.g. rotated access tokens or many users).

Expected effect: 5 metadata calls per explore collapse to 1 per TTL window; concurrent fan-out collapses to a single upstream request.

PR Checklist

  • Make sure to open an issue as a bug/issue before writing your code! Fixes perf(tool/looker): cache LookmlModelExplore responses across metadata tools #4225
  • Ensure you have manually reviewed the entire diff before requesting a review
  • Ensure the tests and linter pass
  • Code coverage does not decrease (new TestGetLookmlModelExploreCache covers hit, identity-miss, and concurrent singleflight paths)
  • Appropriate docs were updated (if necessary) — no user-visible parameter or behavior change

Issue Reference

Fixes #4225

@juanpiRiv
juanpiRiv requested review from a team as code owners October 6, 2026 16:00
@google-cla

google-cla Bot commented Oct 6, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a short-TTL (5-minute) cache and request deduplication using singleflight.Group for Looker's LookmlModelExplore API calls, updating several Looker tools to utilize this cached method. Feedback on the changes highlights a potential memory leak due to the cache growing indefinitely without eviction, and a risk of cache corruption or data races because returning the SDK struct by value only performs a shallow copy of nested pointers and slices.

Comment thread internal/sources/looker/looker.go
Comment thread internal/sources/looker/looker.go
@juanpiRiv
juanpiRiv force-pushed the fix/looker-explore-cache branch from 316c015 to 7b1d5c0 Compare October 6, 2026 16:02
@juanpiRiv
juanpiRiv force-pushed the fix/looker-explore-cache branch from 7b1d5c0 to cbf41a6 Compare October 6, 2026 16:03

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(tool/looker): cache LookmlModelExplore responses across metadata tools

2 participants