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

Đã đóng
#58 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

  • #66 của @santiagxf — đã đóng, không merge
  • #67 của @santiagxf — đã đóng, không merge

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
55/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
18
Fork
9
Merge trung bình
1 ngày 16 giờ
Pull request đã merge (30 ngày)
23

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Azure/aigateway

Tất cả issue của Azure/aigateway

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.