atlasbot: refine role and hardware filters
This commit is contained in:
parent
159c9cfe68
commit
70feb1ef85
@ -16,7 +16,7 @@ spec:
|
|||||||
labels:
|
labels:
|
||||||
app: atlasbot
|
app: atlasbot
|
||||||
annotations:
|
annotations:
|
||||||
checksum/atlasbot-configmap: manual-atlasbot-37
|
checksum/atlasbot-configmap: manual-atlasbot-38
|
||||||
vault.hashicorp.com/agent-inject: "true"
|
vault.hashicorp.com/agent-inject: "true"
|
||||||
vault.hashicorp.com/role: "comms"
|
vault.hashicorp.com/role: "comms"
|
||||||
vault.hashicorp.com/agent-inject-secret-turn-secret: "kv/data/atlas/comms/turn-shared-secret"
|
vault.hashicorp.com/agent-inject-secret-turn-secret: "kv/data/atlas/comms/turn-shared-secret"
|
||||||
|
|||||||
@ -432,7 +432,10 @@ def _detect_metric(q: str) -> str | None:
|
|||||||
def _detect_hardware_filters(q: str) -> tuple[set[str], set[str]]:
|
def _detect_hardware_filters(q: str) -> tuple[set[str], set[str]]:
|
||||||
include: set[str] = set()
|
include: set[str] = set()
|
||||||
exclude: set[str] = set()
|
exclude: set[str] = set()
|
||||||
|
rpi_specific = "rpi4" in q or "rpi5" in q
|
||||||
for hardware, phrases in HARDWARE_HINTS.items():
|
for hardware, phrases in HARDWARE_HINTS.items():
|
||||||
|
if hardware == "rpi" and rpi_specific:
|
||||||
|
continue
|
||||||
for phrase in phrases:
|
for phrase in phrases:
|
||||||
if f"non {phrase}" in q or f"non-{phrase}" in q or f"not {phrase}" in q:
|
if f"non {phrase}" in q or f"non-{phrase}" in q or f"not {phrase}" in q:
|
||||||
exclude.add(hardware)
|
exclude.add(hardware)
|
||||||
@ -440,6 +443,17 @@ def _detect_hardware_filters(q: str) -> tuple[set[str], set[str]]:
|
|||||||
include.add(hardware)
|
include.add(hardware)
|
||||||
return include, exclude
|
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:
|
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):
|
if "node" in q or "nodes" in q or "worker" in q or TITAN_NODE_RE.search(q):
|
||||||
return "node"
|
return "node"
|
||||||
@ -1125,6 +1139,7 @@ def structured_answer(
|
|||||||
include_hw, exclude_hw = _detect_hardware_filters(q)
|
include_hw, exclude_hw = _detect_hardware_filters(q)
|
||||||
nodes_in_query = _extract_titan_nodes(q)
|
nodes_in_query = _extract_titan_nodes(q)
|
||||||
only_workers = "worker" in q or "workers" in q
|
only_workers = "worker" in q or "workers" in q
|
||||||
|
role_filters = _detect_role_filters(q)
|
||||||
only_ready: bool | None = None
|
only_ready: bool | None = None
|
||||||
if "not ready" in q or "unready" in q or "down" in q or "missing" in q:
|
if "not ready" in q or "unready" in q or "down" in q or "missing" in q:
|
||||||
only_ready = False
|
only_ready = False
|
||||||
@ -1201,6 +1216,12 @@ def structured_answer(
|
|||||||
only_ready=only_ready if op in ("status", "count") else None,
|
only_ready=only_ready if op in ("status", "count") else None,
|
||||||
nodes_in_query=nodes_in_query,
|
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]
|
names = [node["name"] for node in filtered]
|
||||||
|
|
||||||
if op == "status":
|
if op == "status":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user