对比两个命名场景的决策指标,返回差值分析报告。 查询参数: ``a=<场景名称A>``(必填) ``b=<场景名称B>``(必填) 响应示例:: {"code": 0, "data": { "scenario_a": {"name": "基准", "saved_at": "...", "is_baseline": true}, "scenario_b": {"name": "扩容", "saved_at": "...", "is_baseline": false},
()
| 1116 | |
| 1117 | @app.route('/api/scenario/compare', methods=['GET']) |
| 1118 | def scenario_compare(): |
| 1119 | """对比两个命名场景的决策指标,返回差值分析报告。 |
| 1120 | |
| 1121 | 查询参数: |
| 1122 | ``a=<场景名称A>``(必填) |
| 1123 | ``b=<场景名称B>``(必填) |
| 1124 | |
| 1125 | 响应示例:: |
| 1126 | |
| 1127 | {"code": 0, "data": { |
| 1128 | "scenario_a": {"name": "基准", "saved_at": "...", "is_baseline": true}, |
| 1129 | "scenario_b": {"name": "扩容", "saved_at": "...", "is_baseline": false}, |
| 1130 | "resource_diff": {"gs_count": {"a": 10, "b": 15, "delta": 5}, ...}, |
| 1131 | "metrics": { |
| 1132 | "acceptance_rate": {"label": "接受率", "a": 0.8, "b": 0.9, |
| 1133 | "delta": 0.1, "delta_pct": 12.5}, |
| 1134 | ... |
| 1135 | }, |
| 1136 | "summary": "场景 '扩容' 相对 '基准' 整体性能提升" |
| 1137 | }} |
| 1138 | """ |
| 1139 | name_a = (request.args.get("a") or "").strip() |
| 1140 | name_b = (request.args.get("b") or "").strip() |
| 1141 | if not name_a or not name_b: |
| 1142 | return error_response("VALIDATION_ERROR", "必须通过查询参数 a 和 b 指定两个场景名称") |
| 1143 | try: |
| 1144 | report = _scenario_store.compare(name_a, name_b) |
| 1145 | except KeyError as ke: |
| 1146 | return error_response("NOT_FOUND", str(ke)) |
| 1147 | except Exception: |
| 1148 | logger.exception("场景对比失败") |
| 1149 | return error_response("INTERNAL_ERROR") |
| 1150 | return ok(report) |
| 1151 | |
| 1152 | |
| 1153 | # ========================================== |
nothing calls this directly
no test coverage detected