diff --git a/atlasbot/engine/answerer.py b/atlasbot/engine/answerer.py index 399cbf8..fa3d470 100644 --- a/atlasbot/engine/answerer.py +++ b/atlasbot/engine/answerer.py @@ -583,38 +583,47 @@ class AnswerEngine: if note: reply = f"{reply}\n\n{note}" - if hotspot_request and hotspot_line: + if hotspot_request: namespace_line = None - if "namespace" in lowered_q: - hotspot_node = None + hotspot_node = None + if hotspot_line: match = re.search(r"(titan-[a-z0-9]+)", hotspot_line) if match: hotspot_node = match.group(1) - if hotspot_node: + if not hotspot_node: + for fact in metric_facts: + match = re.search(r"hottest_\w+_node: (?P[^\s\[]+)", fact) + if match: + hotspot_node = match.group("node") + break + if "namespace" in lowered_q and hotspot_node: + for line in summary_lines: + if line.startswith("node_namespaces_top:") and f"{hotspot_node} " in line: + namespace_line = line + break + if not namespace_line: for line in summary_lines: - if line.startswith("node_namespaces_top:") and f"{hotspot_node} " in line: + if line.startswith("node_pods_top:") and hotspot_node in line: namespace_line = line break - if not namespace_line: - for line in summary_lines: - if line.startswith("node_pods_top:") and hotspot_node in line: - namespace_line = line - break + if "namespace" in lowered_q and not namespace_line: + for fact in metric_facts: + if fact.startswith("node_namespaces_top:"): + namespace_line = fact + break if not namespace_line: for fact in metric_facts: - if fact.startswith("node_namespaces_top:"): + if fact.startswith("node_pods_top:"): namespace_line = fact break - if not namespace_line: - for fact in metric_facts: - if fact.startswith("node_pods_top:"): - namespace_line = fact - break - if namespace_line: - reply = f"Current hotspots: {hotspot_line}. {namespace_line}." - else: + if hotspot_line: reply = f"Current hotspots: {hotspot_line}." - hotspot_override = True + elif hotspot_node: + reply = f"Hotspot node: {hotspot_node}." + if namespace_line and reply: + reply = f"{reply} {namespace_line}." + if reply: + hotspot_override = True if classify.get("question_type") in {"metric", "diagnostic"} and metric_facts and not hotspot_override: reply = _metric_fact_guard(reply, metric_facts, keyword_tokens)