Skip to content

feat: multi-instance registry and automatic token refresh on 401#23

Draft
harikaduyu wants to merge 1 commit into
mainfrom
feat/multi-instance-registry-token-refresh
Draft

feat: multi-instance registry and automatic token refresh on 401#23
harikaduyu wants to merge 1 commit into
mainfrom
feat/multi-instance-registry-token-refresh

Conversation

@harikaduyu

Copy link
Copy Markdown
Contributor

What did you do?

  • Added a registry config format: a single GRAFANA_CONFIG file can now define multiple named Grafana instances under an instances key
  • Single-instance format (existing) is fully backward compatible — auto-detected by the presence of url vs instances at the top level
  • Added token_command field (single-instance and registry) — a shell command run via sh -c on 401; stdout becomes the new token and the request is retried once
  • Registry supports a top-level token_command with {url} substitution applied per instance, overridable per instance
  • MCP server: registry mode adds a required instance parameter to all four tools; a per-session client cache preserves refreshed tokens across calls
  • CLI: --instance flag added to query, metrics, and instant subcommands

Why did you do it?

Two problems:

  1. Token expiry caused silent failures — the MCP server read the token once at startup; after expiry every call returned 401 with no recovery. token_command + on-401 retry makes this fully automatic.

  2. One-MCP-per-instance doesn't scale — with 6+ Grafana instances, each needing its own MCP server entry, context slots, and manual token management. The registry collapses N servers into one, with instance as a tool parameter.

Checklist

  • Tests added/updated
  • Documentation updated if needed

Add a registry config format so a single gq process (and a single MCP
server) can serve multiple Grafana instances without restart.

- config: auto-detect registry vs single-instance by presence of
  'instances' key in GRAFANA_CONFIG file
- config: Registry type with per-instance InstanceConfig; top-level
  token_command with {url} substitution, overridable per instance
- client: TokenCommand field; on 401, run token_command via sh -c,
  update in-memory token, retry once
- mcp: registry mode adds required 'instance' param to all tools;
  single clientFunc pattern eliminates handler duplication
- mcp: per-instance client cache preserves refreshed tokens across calls
- cli: --instance flag on query/metrics/instant subcommands

Co-authored-by: opencode <opencode@noreply.opencode.ai>
Co-authored-by: GitHub Copilot <copilot@noreply.github.com>
@github-actions

Copy link
Copy Markdown


Thank you for your submission, we really appreciate it. Like many open-source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution. You can sign the CLA by just posting a Pull Request Comment same as the below format.


I have read the CLA Document and I hereby sign the CLA


1 out of 2 committers have signed the CLA.
harikaduyu
@OpenCode

Warning

1 commit in this PR was authored by an email address that is not linked to any GitHub user, so we cannot tell whether the author has signed the CLA.

Unlinked author:

  • opencode <opencode@noreply.opencode.ai>

To unblock this PR, do one of the following:

  1. Link the email to your GitHub account (recommended). Add each address above at github.com/settings/emails, then push another commit (or comment recheck) so this check re-runs. See why commits are not linked to a user for details.

  2. Rewrite the commits to use an email that is already linked to your GitHub account:

    # Set the correct email locally (one-off, for this repo):
    git config user.email you@example.com
    # Rewrite every commit on this branch with the corrected identity:
    git rebase -i --root --exec 'git commit --amend --reset-author --no-edit'
    git push --force-with-lease

    After the push, comment recheck on this PR (or just re-push) to re-run the check.

    You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

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.

1 participant