{%- if faults -%} {%- set fault_list = faults -%} {%- else -%} {%- set fault_list = [{'id':'F01','title':'诊断故障','role':'primary','status':'confirmed','severity':'P2','confidence':conclusion.confidence,'affected_scope':conclusion.affected_scope_desc,'conclusion':conclusion,'root_cause':root_cause,'propagation':propagation,'evidence_traces':evidence_traces,'knowledge_matches':knowledge_matches,'solution':solution,'source_code':source_code}] -%} {%- endif -%} {%- set is_multi = fault_list | length > 1 -%} {%- set f0 = fault_list[0] -%} {%- set pns = namespace(p=f0) -%} {%- for _f in fault_list %}{% if incident_summary and _f.id == incident_summary.primary_fault_id %}{% set pns.p = _f %}{% endif %}{% endfor -%} {%- if incident_summary -%} {%- set inc = incident_summary -%} {%- else -%} {%- set inc = {'one_line_conclusion':conclusion.one_line_conclusion,'fault_count':1,'primary_fault_id':'F01','secondary_fault_count':0,'independent_fault_count':0,'overall_impact':conclusion.affected_scope_desc,'confidence':conclusion.confidence} -%} {%- endif -%} {%- set rels = fault_relations if fault_relations else [] -%} {%- set acts = action_plan if action_plan else [] -%} {%- set sec_ns = namespace(n=0) -%}
Witty-UB · Intelligent Operations

{{ report.title }}

报告编号 {{ report.report_id }} 生成时间 {{ report.generated_at }} 诊断对象 {{ basic_info.kb_name }}
{% if is_multi %}识别 {{ inc.fault_count }} 个故障{% elif f0.root_cause and f0.root_cause.confirmed_root_cause %}根因已定位{% else %}分析进行中{% endif %} {% if basic_info.diagnosis_ok %}诊断完成{% endif %}
EXECUTIVE DIAGNOSIS
{{ inc.one_line_conclusion }}
{% if is_multi %}
识别故障
{{ inc.fault_count }} 个
主故障
{{ inc.primary_fault_id }}
次生 / 独立
{{ inc.secondary_fault_count }} / {{ inc.independent_fault_count }}
综合置信度
{{ inc.confidence }}
{% else %}
故障域
{{ f0.conclusion.fault_domain }}
故障组件
{{ f0.conclusion.fault_component }}
影响范围
{{ f0.conclusion.affected_scope_pct }}%
诊断置信度
{{ f0.conclusion.confidence }}
{% endif %}
{# ================= Fault-scoped block macros ================= #} {% macro m_conclusion(c) %} {% if c %}
{{ c.one_line_conclusion }}
{% if c.fault_domain or c.fault_component %}
故障域
{{ c.fault_domain }}
故障组件
{{ c.fault_component }}
影响范围
{% if c.affected_scope_pct %}{{ c.affected_scope_pct }}%{% else %}—{% endif %}
{% if c.affected_scope_desc %}
{{ c.affected_scope_desc }}
{% endif %}
置信度
{{ c.confidence or '—' }}
{% endif %} {% if c.fault_function %}
故障函数 {{ c.fault_function }} {% if c.fault_function_loc %}{{ c.fault_function_loc }}{% endif %}
{% endif %} {% if c.key_findings %}

关键发现

    {% for finding in c.key_findings %}
  • {{ finding }}
  • {% endfor %}
{% endif %}
{% endif %} {% endmacro %} {# ---- Latency block: metric strip + per-stage attribution (P99 / baseline / ratio / share) ---- #} {% macro m_latency(lat) %} {% if lat %} {% if lat.metrics %}
{% for m in lat.metrics %}
{{ m.label }}
{{ m.value }}
{% if m.sub %}
{{ m.sub }}
{% endif %}
{% endfor %}
{% endif %} {% if lat.stages %}
阶段P99 时延基线放大耗时占比状态
{% for st in lat.stages %}
{{ st.name }} {{ st.p99 }} {% if st.baseline %}{{ st.baseline }}{% else %}{% endif %} {% if st.ratio %}{{ st.ratio }}{% else %}{% endif %} {% if st.share %}{{ st.share }}{% else %}{% endif %} {% if st.status == 'bottleneck' %}瓶颈{% elif st.status == 'warn' %}异常{% else %}正常{% endif %} {% if st.detail %}{{ st.detail }}{% endif %}
{% endfor %}
{% endif %} {% if lat.conclusion %}
{{ lat.conclusion }}
{% endif %} {% endif %} {% endmacro %} {% macro m_solution(s) %} {% if s.short_term %}

短期措施(立即执行)

{% endif %} {% if s.long_term %}

长期措施(预防复发)

{% endif %} {% if s.verification %}

验证方法

{% endif %} {% endmacro %} {% macro m_root_cause(rc) %} {% for step in rc.reasoning_chain %}
{{ step.step_label }}: {{ step.title }}
{{ step.description }}
{% if step.evidence %} {{ step.evidence }} {% endif %}
{% endfor %} {% if rc.confirmed_root_cause %}
确认根因: {{ rc.confirmed_root_cause }} {% if rc.supporting_knowledge %}
知识库支撑: {{ rc.supporting_knowledge }}
{% endif %}
{% endif %} {% endmacro %} {% macro m_evidence_traces(traces) %}
{% endmacro %} {% macro m_propagation(p) %}
{% set ns = namespace(order=0, bo=0) %} {% for node in p.chain %} {% set ns.order = ns.order + 1 %}
{{ ns.order }} {{ node.label }} {% if node.detail %}{{ node.detail }}{% endif %} {% if node.tag %}{{ node.tag }}{% elif node.type == 'origin' %}故障源头{% elif node.type == 'impact' %}业务影响{% else %}传播环节{% endif %}
{% if node.branches %}
{% if node.transition %}{{ node.transition }}{% endif %}
{% for branch in node.branches %} {% set b = branch if branch is mapping else {'nodes': branch} %}
{% if b.label %}{{ b.label }}{% endif %} {% for sub in b.nodes %} {% set ns.bo = ns.bo + 1 %}
{{ ['a','b','c','d','e','f','g','h'][ns.bo - 1] }} {{ sub.label }} {% if sub.detail %}{{ sub.detail }}{% endif %} {% if sub.tag %}{{ sub.tag }}{% elif sub.type == 'origin' %}故障源头{% elif sub.type == 'impact' %}业务影响{% else %}传播环节{% endif %}
{% if not loop.last %}
{% if sub.transition %}{{ sub.transition }}{% endif %}
{% endif %} {% endfor %}
{% endfor %}
{% elif not loop.last %}
{% if node.transition %}{{ node.transition }}{% endif %}
{% endif %} {% endfor %}
{% if p.impact_scope %}
影响范围: {% for scope in p.impact_scope %} {{ scope }}{% if not loop.last %};{% endif %} {% endfor %}
{% endif %} {% endmacro %} {% macro m_knowledge(matches, fid) %} {% if matches %} {% for match in matches %}
{{ match.rank }} {{ match.id }} {{ match.stars }} {% if fid %}支撑 {{ fid }}{% endif %}
匹配逻辑{{ match.match_logic }}
现象{{ match.symptom }}
原因{{ match.root_cause }}
{% if match.solution %}
方案{{ match.solution }}
{% endif %} {% if match.phenomenon_fit or match.log_fit or match.rc_consistency or match.env_diff or match.adaptation %}
{% if match.phenomenon_fit %}
现象契合{{ match.phenomenon_fit }}
{% endif %} {% if match.log_fit %}
日志/栈契合{{ match.log_fit }}
{% endif %} {% if match.rc_consistency %}
根因一致{{ match.rc_consistency }}
{% endif %} {% if match.env_diff %}
环境/版本差异{{ match.env_diff }}
{% endif %} {% if match.adaptation %}
适配修改{{ match.adaptation }}
{% endif %}
{% endif %}
{% if match.applicability %} {% if match.applicability == 'direct' %}可直接采用{% elif match.applicability == 'adjust' %}调整后采用{% elif match.applicability == 'reference' %}仅供参考{% elif match.applicability == 'not_recommended' %}不建议采用{% else %}{{ match.applicability }}{% endif %} {% elif match.adoption_label %} {{ match.adoption_label }} {% endif %}
{% endfor %} {% else %}

无匹配的知识库条目。

{% endif %} {% endmacro %} {% macro m_source(sc) %} {% if sc %}
组件: {{ sc.component }}
{% if sc.call_chain %}
调用链: {{ sc.call_chain | length }} 层
{% else %}
文件: {{ sc.filename }}
函数: {{ sc.function_name }}
{% if sc.line_range %}
行号: {{ sc.line_range }}
{% endif %} {% endif %} {% if sc.failure_mode_id %}
关联故障模式: {{ sc.failure_mode_id }}
{% endif %}
{% if sc.call_chain %}
{% for node in sc.call_chain %} {%- set nxt = sc.call_chain[loop.index] if not loop.last else none -%} {%- set cs_str = node.call_site if node.call_site else '' -%} {%- set cs_num = (cs_str.split(':')[-1] | int) if ((':' in cs_str) and (cs_str.split(':')[-1] | int)) else 0 -%} {%- set cs_hit = (node.code | selectattr('num', 'equalto', cs_num) | first) if cs_num else none -%}
{{ loop.index }} {{ node.function }} {{ node.file }}{% if node.line %}:{{ node.line }}{% endif %} {% if node.role_label %}{{ node.role_label }}{% endif %}
{% if node.code %}
源码片段{% if node.line %} · {{ node.file }}:{{ node.line }}{% endif %}
{%- for line in node.code -%}
{% if line.ellipsis %}{{ line.text }}{% else %}{% if line.highlight %}{% endif %}{{ line.num }}{{ line.text }}{% if line.highlight %}{% endif %}{% endif %}
{%- endfor -%}
{% endif %} {% if not loop.last %}
调用点{% if cs_str %} · {{ cs_str }}{% endif %} → {{ nxt.function }}
{%- if cs_hit -%}
{{ cs_hit.num }}{{ cs_hit.text }}
{%- else -%}
?// 调用 {{ nxt.function }}{{ ' @ ' ~ cs_str if cs_str }}
{%- endif -%}
{% endif %} {% if node.analysis %}
{% if node.role == 'fault-point' %}故障点分析{% else %}描述{% endif %}
{{ node.analysis }}
{% endif %}
{% endfor %}
{% if sc.root_cause or sc.fix_suggestion %}
{% if sc.root_cause %}
根因锁定
{{ sc.root_cause }}
{% endif %} {% if sc.fix_suggestion %}
修复建议
{{ sc.fix_suggestion }}
{% endif %}
{% endif %} {% else %} {% if sc.code_snippet %}
{{ sc.filename }} {{ sc.line_range }}
{%- for line in sc.code_snippet -%}
{% if line.ellipsis %}{{ line.text }}{% else %}{% if line.highlight %}{% endif %}{{ line.num }}{{ line.text }}{% if line.highlight %}{% endif %}{% endif %}
{%- endfor -%}
{% endif %} {% if sc.analysis %}
{% for para in sc.analysis %}

{{ para }}

{% endfor %}
{% endif %} {% if sc.root_cause or sc.fix_suggestion %}
{% if sc.root_cause %}
根因锁定
{{ sc.root_cause }}
{% endif %} {% if sc.fix_suggestion %}
修复建议
{{ sc.fix_suggestion }}
{% endif %}
{% endif %} {% endif %} {% else %}

未获取到相关源码。可能原因:组件源码未拉取,或故障模式未关联源码文件。

{% endif %} {% endmacro %} {# ---- Donut chart macro: pure CSS conic-gradient pie, auto-completes remainder as "其他" ---- #} {% macro donut_chart(items, total='', total_label='') -%} {%- set palette = ['#4f7cff', '#37c7b5', '#8fb0ff', '#F59E0B', '#E5484D', '#8B5CF6', '#0EA5E9', '#EC4899'] -%} {%- set gray = '#C3CBD4' -%} {%- set ns = namespace(grad='', start=0.0) -%} {%- for item in items -%} {%- set end = ns.start + (item.pct | float) -%} {%- set ns.grad = ns.grad ~ palette[loop.index0 % (palette | length)] ~ ' ' ~ (ns.start | round(2)) ~ '% ' ~ (end | round(2)) ~ '%' -%} {%- if not loop.last %}{%- set ns.grad = ns.grad ~ ', ' -%}{% endif -%} {%- set ns.start = end -%} {%- endfor -%} {%- set remainder = (100 - ns.start) | round(2) -%} {%- if remainder > 0.5 -%}{%- set ns.grad = ns.grad ~ ', ' ~ gray ~ ' ' ~ (ns.start | round(2)) ~ '% 100%' -%}{%- endif -%}
{% if total %}
{{ total }}
{{ total_label }}
{% endif %}
{%- endmacro %}
{% set sec_ns.n = sec_ns.n + 1 %}{{ '%02d' % sec_ns.n }} 日志基本信息
知识库 {{ basic_info.kb_name }}
KB ID {{ basic_info.kb_id }}
日志文件 {{ basic_info.log_file }}
操作类型 {{ basic_info.operation }}
时间范围 {{ basic_info.time_range_start }} ~ {{ basic_info.time_range_end }}
总 Trace 数 {{ basic_info.total_trace_cnt }}
故障 Trace {{ basic_info.fault_trace_cnt }} ({{ basic_info.fault_ratio }}%)
任务状态 {% if basic_info.parse_ok %} 解析完成 {% else %} 解析异常 {% endif %} {% if basic_info.diagnosis_ok %} 诊断完成 {% else %} 诊断未完成 {% endif %}
{% set sec_ns.n = sec_ns.n + 1 %}{{ '%02d' % sec_ns.n }} 事件诊断摘要
{{ inc.one_line_conclusion }}
{% if is_multi %}
识别故障
{{ inc.fault_count }} 个
主故障 1 · 次生 {{ inc.secondary_fault_count }} · 独立 {{ inc.independent_fault_count }}
主故障
{{ inc.primary_fault_id }}
{{ pns.p.title }}
总体影响范围
{{ inc.overall_impact or '—' }}
综合置信度
{{ inc.confidence or '—' }}
{% else %}
故障域
{{ f0.conclusion.fault_domain }}
故障组件
{{ f0.conclusion.fault_component }}
影响范围
{{ f0.conclusion.affected_scope_pct }}%
{{ f0.conclusion.affected_scope_desc }}
置信度
{{ f0.conclusion.confidence }}
{% if f0.conclusion.fault_function %}
故障函数 {{ f0.conclusion.fault_function }} {% if f0.conclusion.fault_function_loc %}{{ f0.conclusion.fault_function_loc }}{% endif %}
{% endif %} {% if f0.conclusion.key_findings %}

关键发现

    {% for finding in f0.conclusion.key_findings %}
  • {{ finding }}
  • {% endfor %}
{% endif %} {% endif %}
{% if is_multi %}
{% set sec_ns.n = sec_ns.n + 1 %}{{ '%02d' % sec_ns.n }} 故障清单与关系
{% for f in fault_list %} {% endfor %}
编号故障名称角色确认状态严重级别影响范围置信度
{{ f.id }} {{ f.title }} {% if f.role == 'primary' %}主故障{% elif f.role == 'secondary' %}次生故障{% else %}独立故障{% endif %} {% if f.status == 'confirmed' %}已确认{% elif f.status == 'suspected' %}疑似{% elif f.status == 'excluded' %}已排除{% else %}{{ f.status }}{% endif %} {% if f.severity %}{{ f.severity }}{% else %}{% endif %} {{ f.affected_scope or '—' }} {% if f.confidence is number %}{{ f.confidence }}%{% else %}{{ f.confidence or '—' }}{% endif %}
{% if rels %}

故障关系

{% for r in rels %}
{{ r.from }} {% if r.type == 'causes' %}导致{% elif r.type == 'common_cause' %}同根因{% elif r.type == 'independent' %}相互独立{% elif r.type == 'correlated' %}时间相关{% else %}{{ r.type }}{% endif %} {% if r.confidence is number %}置信 {{ (r.confidence * 100) | round | int }}%{% else %}置信 {{ r.confidence }}{% endif %} {{ r.to }} {{ r.evidence }}
{% endfor %}
因果(A 导致 B) 同根因 相互独立 仅时间相关(不作为因果)
{% endif %}
{% endif %} {% if acts %}
{% set sec_ns.n = sec_ns.n + 1 %}{{ '%02d' % sec_ns.n }} 综合处置计划
{% for a in acts %} {% endfor %}
优先级关联故障处置操作前置依赖预期效果验证标准
{{ a.priority }} {% for fid in a.fault_ids %}{% set fr = namespace(role='independent') %}{% for ff in fault_list %}{% if ff.id == fid %}{% set fr.role = ff.role %}{% endif %}{% endfor %}{{ fid }} {% endfor %} {{ a.action }} {{ a.depends_on or '—' }} {{ a.expected_effect or '—' }} {{ a.verify or '—' }}
{% endif %}
{% set sec_ns.n = sec_ns.n + 1 %}{{ '%02d' % sec_ns.n }} 统计分析
{% set sbs = statistics.stage_breakdowns if statistics.stage_breakdowns else ([statistics.stage_breakdown] if statistics.stage_breakdown else []) %} {% for sb in sbs %}

阶段分解(按请求流程阶段) — 操作: {{ sb.operation }} · 总时延 P99: {{ sb.total_p99_ms }}

{% if sb.share_bar %}
{% for seg in sb.share_bar %}
{% if seg.pct | float > 8 %}{{ seg.pct }}%{% endif %}
{% endfor %}
{% for seg in sb.share_bar %}
{{ seg.name }} {{ seg.pct }}%
{% endfor %}
{% endif %}
阶段P99 时延时延异常率失败占比状态
{% for st in sb.stages %} {% set st_role = (fault_list | selectattr('id', 'equalto', st.fault) | map(attribute='role') | first) or 'independent' %}
{{ st.name }}{% if st.fault %} {{ st.fault }}{% endif %} {{ st.p99 }} {{ st.anomaly_rate }} {% if st.fail_share %}{{ st.fail_share }}{% else %}{% endif %} {% if st.status == 'bottleneck' %}瓶颈{% elif st.status == 'warn' %}异常{% else %}正常{% endif %} {% if st.detail %}{{ st.detail }}{% endif %}
{% endfor %}
{% if sb.conclusion %}
{{ sb.conclusion }}
{% endif %}
{% endfor %} {% if statistics.top_error_codes or statistics.top_failure_domains or statistics.top_pods or statistics.top_hosts %}
{% if statistics.top_error_codes %}

错误码分布 (Top 5)

{{ donut_chart(statistics.top_error_codes, statistics.dist_total or '', '故障 Trace') }}
{% endif %} {% if statistics.top_failure_domains %}

故障域分布

{{ donut_chart(statistics.top_failure_domains, statistics.dist_total or '', '故障 Trace') }}
{% endif %} {% if statistics.top_pods %}

故障 Pod 分布 (Top 5)

{{ donut_chart(statistics.top_pods, statistics.dist_total or '', '故障 Trace') }}
{% endif %} {% if statistics.top_hosts %}

故障 Host 分布 (Top 5)

{{ donut_chart(statistics.top_hosts, statistics.dist_total or '', '故障 Trace') }}
{% endif %}
{% endif %} {% if statistics.time_heatmap %}

时间热点分布{% if statistics.heatmap_metric == 'latency' %} — 各时段 P99 时延{% endif %}

{% for slot in statistics.time_heatmap %}
{% if slot.spike %}尖峰{% else %}{% endif %} {% if slot.lat_ms %}{{ slot.lat_ms }}ms{% else %}{{ slot.pct }}%{% endif %}
{{ slot.time }}
{% endfor %}
无故障 尖峰/爆发
{% endif %}
{% set sec_ns.n = sec_ns.n + 1 %}{{ '%02d' % sec_ns.n }} 故障档案
{% for f in fault_list %}
{{ f.id }} {{ f.title }} {% if f.category %}{% if f.category == 'latency' %}时延类{% elif f.category == 'mixed' %}时延+错误{% else %}错误类{% endif %}{% endif %} {% if f.role == 'primary' %}主故障{% elif f.role == 'secondary' %}次生故障{% else %}独立故障{% endif %} {% if f.status == 'confirmed' %}已确认{% elif f.status == 'suspected' %}疑似{% elif f.status == 'excluded' %}已排除{% else %}{{ f.status }}{% endif %} {% if f.severity %}{{ f.severity }}{% endif %} {% if f.confidence %}置信 {% if f.confidence is number %}{{ f.confidence }}%{% else %}{{ f.confidence }}{% endif %}{% endif %} {% if f.conclusion and f.conclusion.one_line_conclusion %}{{ f.conclusion.one_line_conclusion }}{% endif %}
{% if f.role == 'secondary' %}
本故障为 {{ f.upstream or inc.primary_fault_id }} 的次生故障,已由上游传播链解释;{% if f.need_independent_fix %}影响面独立,需按下方方案独立修复。{% else %}上游修复后可自动恢复,无需独立修复。{% endif %}
{% endif %} {% if f.status == 'suspected' %}
本故障为候选假设,根因尚未确认,下列结论与证据仅供参考,不能直接认定。
{% endif %} {% if f.conclusion %}

故障结论

{{ m_conclusion(f.conclusion) }}{% endif %} {% if f.latency %}

时延阶段定位

{{ m_latency(f.latency) }}{% endif %} {% if not f.simplified %} {% if f.root_cause %}

根因推理链

{{ m_root_cause(f.root_cause) }}{% endif %} {% if f.evidence_traces %}

证据锚点

{{ m_evidence_traces(f.evidence_traces) }}{% endif %} {% if f.propagation %}

故障传播链

{{ m_propagation(f.propagation) }}{% endif %} {% if f.knowledge_matches %}

知识库匹配

{{ m_knowledge(f.knowledge_matches, f.id) }}{% endif %} {% if f.solution %}

解决方案

{{ m_solution(f.solution) }}{% endif %} {% if f.source_code %}

源码分析

{{ m_source(f.source_code) }}{% endif %} {% elif f.solution and f.need_independent_fix %}

解决方案

{{ m_solution(f.solution) }} {% endif %}
{% endfor %}
{% set sec_ns.n = sec_ns.n + 1 %}{{ '%02d' % sec_ns.n }} 诊断工作追踪
{{ workflow.session_id }}
Session
{{ workflow.total_steps }}
Steps
{{ workflow.api_calls }}
API Calls
{{ workflow.duration }}
耗时
{% for step in workflow.steps %}
{{ step.title }}
{% if step.api_calls %}
{% for call in step.api_calls %} → {{ call }}
{% endfor %}
{% endif %} {% if step.result %}
{{ step.result }}
{% endif %}
{% endfor %}