lablup / lablup/backend.ai

Resolve cloud identity per provider class, at first call instead of at import

Open
#13,875 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
670
Forks
183
Avg merge
17h 7m
Merged PRs (30d)
358

Description

현재 common/identity.py는 모듈을 들여오는 순간 asyncio.run(detect_cloud())로 AWS/Azure/GCP 메타데이터를 조회하고, 결과를 INFO 두 줄로 남긴 뒤 _define_functions()로 인스턴스 조회 함수를 전역에 대입한다.

get_instance_id를 부르지 않는 호출자도 그 비용을 낸다. backend.ai mgr의 하위 명령은 config provider를 지나며 이 모듈을 들여오므로, 조회만 하는 CLI가 매번 메타데이터 프로브 세 건과 "The agent node ID is set using the hostname" 로그를 낸다. 이 문구는 매니저와 스토리지가 같이 쓰는 모듈에 맞지 않는다.

바꿀 방향: provider별 구현체로 나눈다. _define_functions()의 match case 대신 AWS, Azure, GCP, on-premise가 각각 ABC를 구현해 get_instance_id / get_instance_ip / get_instance_type / get_instance_region을 답하고, 어느 구현체를 쓸지는 첫 호출 때 한 번 정한다.

제약: manager/config/loader/legacy_etcd_loader.py가 from ai.backend.common.identity import get_instance_id로 조기 바인딩한다. 모듈 최상위 이름을 실제 def로 남기고 그 안에서 구현체를 부르는 형태여야 이 호출부가 깨지지 않는다. agent/utils.py와 agent/server.py는 모듈 속성으로 늦게 읽으므로 무관하다.

확인할 것: tests/unit/common/test_identity.py는 current_provider와 _defined를 직접 만진 뒤 _define_functions()를 다시 부르는 형태이고 전부 @pytest.mark.skip이다. 구현체를 주입하는 형태가 되면 이 테스트를 되살릴 수 있다. current_provider를 파일 밖에서 읽는 곳은 없다.

영향 범위: agent, manager, storage-proxy, installer가 모두 이 모듈을 지난다.

JIRA Issue: BA-7432

Contributor guide

Open the contributing guide

Research direction

Start with common/identity.py and trace the early import in manager/config/loader/legacy_etcd_loader.py, preserving its from-import compatibility. Review tests/unit/common/test_identity.py and the current_provider/_defined setup; done means provider selection and metadata lookup occur once at the first call, with the skipped tests made usable without import-time probing.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend, cloud
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.