Skip to content

fix: Add explicit legacy format converting for config types #4591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/ai/backend/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ class BaseSchema(BaseModel):
)


class BaseConfigModel(BaseModel):
@staticmethod
def snake_to_kebab_case(string: str) -> str:
return string.replace("_", "-")

model_config = ConfigDict(
populate_by_name=True,
from_attributes=True,
use_enum_values=True,
extra="allow",
alias_generator=snake_to_kebab_case,
)

def to_legacy_format(self) -> Mapping[str, Any]:
return self.model_dump()
Comment on lines +60 to +61
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you guarantee that this is the same as the value you received as input?
I'm not sure if it's easy to change it due to plugins.



etcd_config_iv = t.Dict({
t.Key("etcd"): t.Dict({
t.Key("namespace"): t.String,
Expand Down
4 changes: 2 additions & 2 deletions src/ai/backend/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1383,9 +1383,9 @@ def from_dict(cls, data: dict[str, Any]) -> Self:
return cls(
addr=addr,
sentinel=data.get("sentinel"),
service_name=data.get("service_name"),
service_name=data.get("service-name"),
password=data.get("password"),
redis_helper_config=data.get("redis_helper_config"),
redis_helper_config=data.get("redis-helper-config"),
override_targets=override_targets,
)

Expand Down
2 changes: 1 addition & 1 deletion src/ai/backend/manager/api/ratelimit.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ async def init(app: web.Application) -> None:
root_ctx: RootContext = app["_root.context"]
app_ctx: PrivateContext = app["ratelimit.context"]
redis_profile_target: RedisProfileTarget = RedisProfileTarget.from_dict(
root_ctx.config_provider.config.redis.model_dump()
root_ctx.config_provider.config.redis.to_legacy_format()
)
app_ctx.redis_rlim = redis_helper.get_redis_object(
redis_profile_target.profile_target(RedisRole.RATE_LIMIT),
Expand Down
2 changes: 1 addition & 1 deletion src/ai/backend/manager/cli/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ async def redis_ctx(cli_ctx: CLIContext) -> AsyncIterator[RedisConnectionSet]:
loader = LegacyEtcdLoader(etcd, config_prefix="config/redis")
raw_redis_config = await loader.load()
redis_config = RedisConfig(**raw_redis_config)
etcd_redis_config = RedisProfileTarget.from_dict(redis_config.model_dump())
etcd_redis_config = RedisProfileTarget.from_dict(redis_config.to_legacy_format())

redis_live = redis_helper.get_redis_object(
etcd_redis_config.profile_target(RedisRole.LIVE),
Expand Down
Loading
Loading