Repository navigation
[ROB-3577] Multi instance toolset base #2114
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
Changes from all commits
5362a72
e6e0f59
e5fd49f
267933e
c2241aa
ce9e872
2d08a53
b35b039
f3fb2e8
50669d6
d8c24e2
904e97e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,8 @@ | |
| import re | ||
| import uuid | ||
|
|
||
| import yaml # type: ignore | ||
|
|
||
| ROBUSTA_REGIONS = (("US", ""), ("EU", "eu"), ("AP", "ap")) | ||
| ROBUSTA_DOMAIN_RE = re.compile(r"\b(api|platform)\.robusta\.dev\b") | ||
| MARKDOWN_LINK_RE = re.compile(r"^\[([^\]]+)\]\(([^)\s]+)\)(\{[^}]*\})?$") | ||
|
|
@@ -215,3 +217,87 @@ def robusta_region_fence_format(source, language, css_class, options, md, **kwar | |
| f'<div class="tabbed-content">\n{blocks_html}</div>\n' | ||
| "</div>" | ||
| ) | ||
|
|
||
|
|
||
| # Central page that documents how multi-instance toolsets work. Linked from every | ||
| # rendered ``multi-instance`` block so each toolset page doesn't repeat the prose. | ||
| MULTI_INSTANCE_DOC_URL = "/data-sources/multi-instance-toolsets/" | ||
|
|
||
|
|
||
| def _reindent(text: str, spaces: int) -> str: | ||
| """Dedent ``text`` to its common leading whitespace, then indent every | ||
| non-empty line by ``spaces``. Used to nest a flat config example under | ||
| ``instances:`` at the correct YAML depth.""" | ||
| lines = text.strip("\n").split("\n") | ||
| nonempty = [ln for ln in lines if ln.strip()] | ||
| base = min((len(ln) - len(ln.lstrip()) for ln in nonempty), default=0) | ||
| pad = " " * spaces | ||
| return "\n".join(pad + ln[base:] if ln.strip() else "" for ln in lines) | ||
|
|
||
|
|
||
| def multi_instance_fence_format(source, language, css_class, options, md, **kwargs): | ||
| """Render the standard "Multiple Instances" section for a toolset. | ||
|
|
||
| The fence body is YAML with three keys: | ||
|
|
||
| ```multi-instance | ||
| toolset: grafana/dashboards # the toolset key used in config examples | ||
| name: Grafana # human-readable name (optional; derived from toolset) | ||
| config: | # a single-instance config example for this toolset | ||
| api_url: <your grafana url> | ||
| api_key: <your api key> | ||
| ``` | ||
|
|
||
| It emits a note admonition that: | ||
| - explains the toolset can connect to several instances via ``instances:``; | ||
| - shows the supplied config example nested under ``instances:`` (two entries); | ||
| - notes the auto-injected ``instance`` parameter and ``<toolset>_list_instances`` | ||
| tool that appear when more than one instance is configured; | ||
| - links to the central Multiple Instances page for the full behaviour. | ||
|
|
||
| The same component renders identically for every toolset, so each page imports | ||
| it in one fenced block instead of repeating the prose. | ||
| """ | ||
| spec = yaml.safe_load(source) or {} | ||
| toolset = str(spec.get("toolset", "")).strip() | ||
| name = str(spec.get("name") or toolset or "this").strip() | ||
| config = str(spec.get("config", "")).strip() | ||
| if not toolset or not config: | ||
|
Comment on lines
+261
to
+265
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
python - <<'PY'
import yaml
source = """
toolset: grafana/dashboards
config:
api_url: https://prod-grafana.example.com
api_key: token
"""
spec = yaml.safe_load(source)
print(type(spec).__name__)
print(type(spec["config"]).__name__)
print(str(spec["config"]))
PYRepository: HolmesGPT/holmesgpt Length of output: 141 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Show the relevant section around the reported line numbers
nl -ba docs/custom_fences.py | sed -n '230,310p'
# Find where _reindent is defined/used and whether config is inserted into a YAML snippet
rg -n "_reindent\(" -S docs/custom_fences.py || true
rg -n "config" docs/custom_fences.py | head -n 80Repository: HolmesGPT/holmesgpt Length of output: 106 🏁 Script executed: #!/bin/bash
set -euo pipefail
# Display the referenced section with line numbers (using cat -n instead of nl)
cat -n docs/custom_fences.py | sed -n '230,310p'
# Trace how config is used/rendered
rg -n "config" docs/custom_fences.py | head -n 200
# Trace for reindent helper usage
rg -n "_reindent\(" docs/custom_fences.py || true
rg -n "def _reindent" -n docs/custom_fences.py || trueRepository: HolmesGPT/holmesgpt Length of output: 6112 🏁 Script executed: #!/bin/bash
set -euo pipefail
python - <<'PY'
import yaml
def _reindent(text: str, spaces: int) -> str:
lines = text.strip("\n").split("\n")
nonempty = [ln for ln in lines if ln.strip()]
base = min((len(ln) - len(ln.lstrip()) for ln in nonempty), default=0)
pad = " " * spaces
return "\n".join(pad + ln[base:] if ln.strip() else "" for ln in lines)
def render(source: str):
spec = yaml.safe_load(source) or {}
toolset = str(spec.get("toolset", "")).strip()
config = str(spec.get("config", "")).strip()
fields = _reindent(config, 10)
yaml_example = (
"toolsets:\n"
f" {toolset}:\n"
" enabled: true\n"
" config:\n"
" instances:\n"
f" - name: prod\n{fields}\n"
f" - name: staging\n{fields}\n"
)
return yaml_example
# config provided as a YAML mapping (not a block scalar)
source = """
toolset: grafana/dashboards
config:
api_url: https://prod-grafana.example.com
api_key: token
"""
y = render(source)
print("=== rendered ===")
print(y)
print("=== safe_load result ===")
try:
obj = yaml.safe_load(y)
print("parsed:", type(obj).__name__)
except Exception as e:
print("parse_error:", type(e).__name__, str(e)[:200])
PYRepository: HolmesGPT/holmesgpt Length of output: 613 🏁 Script executed: #!/bin/bash
set -euo pipefail
python - <<'PY'
import yaml
def _reindent(text: str, spaces: int) -> str:
lines = text.strip("\n").split("\n")
nonempty = [ln for ln in lines if ln.strip()]
base = min((len(ln) - len(ln.lstrip()) for ln in nonempty), default=0)
pad = " " * spaces
return "\n".join(pad + ln[base:] if ln.strip() else "" for ln in lines)
def render_with_fix(source: str):
spec = yaml.safe_load(source) or {}
if not isinstance(spec, dict):
raise ValueError("multi-instance fence body must be a YAML mapping")
toolset = str(spec.get("toolset", "")).strip()
name = str(spec.get("name") or toolset or "this").strip()
raw_config = spec.get("config", "")
if isinstance(raw_config, str):
config = raw_config.strip()
elif raw_config:
config = yaml.safe_dump(raw_config, sort_keys=False).rstrip()
else:
config = ""
if not toolset or not config:
raise ValueError("multi-instance fence requires 'toolset' and 'config' keys in its YAML body")
fields = _reindent(config, 10)
yaml_example = (
"toolsets:\n"
f" {toolset}:\n"
" enabled: true\n"
" config:\n"
" instances:\n"
f" - name: prod\n{fields}\n"
f" - name: staging\n{fields}\n"
)
return yaml_example
source = """
toolset: grafana/dashboards
config:
api_url: https://prod-grafana.example.com
api_key: token
"""
rendered = render_with_fix(source)
print(rendered)
yaml.safe_load(rendered)
print("safe_load: OK")
PYRepository: HolmesGPT/holmesgpt Length of output: 356 Fix invalid YAML when
Possible fix- spec = yaml.safe_load(source) or {}
- toolset = str(spec.get("toolset", "")).strip()
- name = str(spec.get("name") or toolset or "this").strip()
- config = str(spec.get("config", "")).strip()
+ spec = yaml.safe_load(source) or {}
+ if not isinstance(spec, dict):
+ raise ValueError("multi-instance fence body must be a YAML mapping")
+
+ toolset = str(spec.get("toolset", "")).strip()
+ name = str(spec.get("name") or toolset or "this").strip()
+
+ raw_config = spec.get("config", "")
+ if isinstance(raw_config, str):
+ config = raw_config.strip()
+ elif raw_config:
+ config = yaml.safe_dump(raw_config, sort_keys=False).rstrip()
+ else:
+ config = ""🤖 Prompt for AI Agents |
||
| raise ValueError( | ||
| "multi-instance fence requires 'toolset' and 'config' keys in its YAML body" | ||
| ) | ||
|
|
||
| # The wrapper names the discovery tool by replacing '/' with '_' in the toolset name. | ||
| list_tool = spec.get("list_tool") or (toolset.replace("/", "_") + "_list_instances") | ||
|
|
||
| fields = _reindent(config, 10) | ||
| yaml_example = ( | ||
| "toolsets:\n" | ||
| f" {toolset}:\n" | ||
| " enabled: true\n" | ||
| " config:\n" | ||
| " instances:\n" | ||
| f" - name: prod\n{fields}\n" | ||
| f" - name: staging\n{fields}\n" | ||
| ) | ||
|
|
||
| name_e = html.escape(name) | ||
| list_tool_e = html.escape(str(list_tool)) | ||
| return ( | ||
| '<div class="admonition note">\n' | ||
| '<p class="admonition-title">Multiple Instances</p>\n' | ||
| f"<p>The {name_e} toolset can connect to more than one {name_e} instance. " | ||
| "List each one under <code>instances:</code> with a unique <code>name</code>. " | ||
| "Any config field set outside <code>instances:</code> becomes a default that " | ||
| "every instance inherits, so shared settings only need to be written once.</p>\n" | ||
| f'<pre><code class="language-yaml">{html.escape(yaml_example)}</code></pre>\n' | ||
| "<p>When more than one instance is configured, HolmesGPT automatically adds an " | ||
| f"<code>instance</code> parameter to every {name_e} tool (so it can pick which " | ||
| f"instance to query) and a <code>{list_tool_e}</code> tool to list the configured " | ||
| "instances. With a single instance — including the flat config without " | ||
| "<code>instances:</code> — the tools are unchanged and fully backwards " | ||
| "compatible.</p>\n" | ||
| f'<p>See <a href="{MULTI_INSTANCE_DOC_URL}">Multiple Instances</a> for the full ' | ||
| "behaviour, including global defaults and health reporting.</p>\n" | ||
| "</div>" | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make this link version-relative.
Hard-coding
/data-sources/multi-instance-toolsets/drops the current docs path prefix, so pages rendered under a versioned docs URL will jump to the site root/latest instead of staying on the same version.🤖 Prompt for AI Agents