migrate-apim: a policy in a fragment is attributed to no API, strands its target object, and aborts the policies phase

クローズ
#58 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

  • #66 @santiagxf による — マージされずにクローズ
  • #67 @santiagxf による — マージされずにクローズ

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

Read tools/migrate-apim/migrate_apim/plan.py around _apis_in_scope() and _per_model_objects(), then trace how fragmentRefs or policyRefs.fragments are recorded in collect.py. Start with tests/test_plan.py and add coverage for a fragment included by APIs that register models. Done means the fragment policy is attributed to its including APIs and no longer strands an object or stops the policies phase.

索引モデルが issue の本文から書いたものです。

説明

bug

Summary

_policies() iterates inventory["policies"], which holds one document per scope — and a policy fragment is one of those documents, with scope.level == "fragment". Its elements are therefore classified once, as the fragment, and never attributed to the APIs that include it.

_apis_in_scope() (tools/migrate-apim/migrate_apim/plan.py:1387-1406) handles global/service/None, api, workspace, and product, and returns set() for everything else. fragment falls into that final return set(), so _registrations_in_scope() finds no models and _per_model_objects() emits a stranded object (plan.py:1277-1290):

configurationComplete: false
incompleteReason: "No model registration in this plan falls under fragment '<name>',
                   so there is nothing to carry the policy."

At apply time, _model_policy_set() raises ApplyError on the missing modelName (apply.py:1021-1025), _run_object turns that into status: failed, and run_phase breaks out of the step loop (apply.py:581-583). Every remaining policy step in that phase is skipped.

Impact

Factoring one llm-token-limit into a shared fragment and including it from several APIs is a normal APIM pattern — arguably the recommended one. Today it classifies as native, appears in the plan as ready, provisions nothing, and stops the policies phase.

The failure's remedy — "re-plan from a current inventory" — cannot fix it: a re-plan produces the same stranded object.

The incompleteReason is also wrong in this case, as distinct from merely unhelpful. For a fragment there is something to carry the policy; the planner just has no path from the fragment to the including APIs.

Contract mismatch

capabilities/rules.json gives policyFragments the verdict handled with the rationale "Resolved into the including policy before mapping."

That is not what happens in _policies(). The routine that does resolve fragments — _flatten() at collect.py:1636-1680 — builds a separate flattened view used for backend-auth determination, and never feeds the planner. The stated contract and the behavior disagree.

Scope of the defect

Baseline policies are unaffected: _baseline_object() doesn't consult API scope, so a fragment-scoped rate-limit-by-key or ip-filter still collapses into the gateway-wide baseline correctly. Only per-model targets (capabilityId == "model.policy") strand.

Suggested fix

Expand fragment-document elements into one batch member per including scope, using the fragmentRefs / policyRefs.fragments links collect already records (collect.py:2248), so a fragment included by four APIs contributes four members and the existing per-model expansion and batchOn dedup handle the rest.

A narrower alternative is to teach _apis_in_scope() to resolve fragment to the union of APIs whose documents reference it.

Test gap

tests/test_plan.py:1025 (test_a_scope_with_no_models_says_so_instead_of_vanishing) covers the stranded path for an api scope that registers no model — a genuinely empty scope. The fragment case is structurally different, because the including APIs do register models, and is untested.


Found while documenting the migration flow. Derived from reading the source and the existing tests; not reproduced against a live APIM instance.

主要言語
Python
スター
18
フォーク
9
平均マージ
1日 16時間
マージ済み PR(30日)
23

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

Azure/aigateway のほかの issue

Azure/aigateway の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。