atlasbot: refine role and hardware filters

This commit is contained in:
Brad Stein 2026-01-27 13:02:23 -03:00
parent 159c9cfe68
commit 70feb1ef85
2 changed files with 22 additions and 1 deletions

View File

@ -16,7 +16,7 @@ spec:
labels:
app: atlasbot
annotations:
checksum/atlasbot-configmap: manual-atlasbot-37
checksum/atlasbot-configmap: manual-atlasbot-38
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "comms"
vault.hashicorp.com/agent-inject-secret-turn-secret: "kv/data/atlas/comms/turn-shared-secret"

View File

@ -432,7 +432,10 @@ def _detect_metric(q: str) -> str | None:
def _detect_hardware_filters(q: str) -> tuple[set[str], set[str]]:
include: set[str] = set()
exclude: set[str] = set()
rpi_specific = "rpi4" in q or "rpi5" in q
for hardware, phrases in HARDWARE_HINTS.items():
if hardware == "rpi" and rpi_specific:
continue
for phrase in phrases:
if f"non {phrase}" in q or f"non-{phrase}" in q or f"not {phrase}" in q:
exclude.add(hardware)
@ -440,6 +443,17 @@ def _detect_hardware_filters(q: str) -> tuple[set[str], set[str]]:
include.add(hardware)
return include, exclude
def _detect_role_filters(q: str) -> set[str]:
roles: set[str] = set()
if "control-plane" in q or "control plane" in q:
roles.add("control-plane")
if "master" in q:
roles.add("master")
if "accelerator" in q:
roles.add("accelerator")
return roles
def _detect_entity(q: str) -> str | None:
if "node" in q or "nodes" in q or "worker" in q or TITAN_NODE_RE.search(q):
return "node"
@ -1125,6 +1139,7 @@ def structured_answer(
include_hw, exclude_hw = _detect_hardware_filters(q)
nodes_in_query = _extract_titan_nodes(q)
only_workers = "worker" in q or "workers" in q
role_filters = _detect_role_filters(q)
only_ready: bool | None = None
if "not ready" in q or "unready" in q or "down" in q or "missing" in q:
only_ready = False
@ -1201,6 +1216,12 @@ def structured_answer(
only_ready=only_ready if op in ("status", "count") else None,
nodes_in_query=nodes_in_query,
)
if role_filters:
filtered = [
node
for node in filtered
if role_filters.intersection(set(node.get("roles") or []))
]
names = [node["name"] for node in filtered]
if op == "status":