Repository navigation
fix(proxy): surface DB deployments dropped at load instead of a WARNING log #41280
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
Open
devin-ai-integration
wants to merge
5
commits into
main
Choose a base branch
from
litellm_surface_dropped_db_deployments
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+261
−19
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1f98f90
fix(proxy): surface dropped DB deployments at load
devin-ai-integration[bot] bd33f68
fix(proxy): keep live model groups routable when a sibling deployment…
devin-ai-integration[bot] 47f56ff
test(proxy): include created timestamps in DB row fixtures
devin-ai-integration[bot] 4c23d0d
test(proxy): update DB row fixtures for created timestamps
devin-ai-integration[bot] 4a6b7d0
test(router): cover dropped deployment cleanup
devin-ai-integration[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ | |
| MutableMapping, | ||
| Sequence, | ||
| ) | ||
| from dataclasses import asdict | ||
| from datetime import datetime, timedelta, timezone | ||
| from types import MappingProxyType, UnionType | ||
| from typing import ( | ||
|
|
@@ -6510,7 +6511,7 @@ def _add_deployment(self, db_models: list) -> int: | |
|
|
||
| added_models = 0 | ||
| ## ADD MODEL LOGIC | ||
| for m in db_models: | ||
| for m in sorted(db_models, key=lambda m: (m.created_at or datetime.min, m.model_id)): | ||
| _litellm_params = m.litellm_params | ||
| if isinstance(_litellm_params, dict): | ||
| # decrypt values | ||
|
|
@@ -15046,9 +15047,15 @@ def _get_proxy_model_info(model: dict) -> dict: | |
| return _translate_model_name_for_response(model) | ||
|
|
||
|
|
||
| def _model_info_json_response(data: Sequence[Mapping[str, object]] | Mapping[str, object]) -> Response: | ||
| def _model_info_json_response( | ||
| data: Sequence[Mapping[str, object]] | Mapping[str, object], | ||
| dropped_deployments: Sequence[Mapping[str, object]] | None = None, | ||
| ) -> Response: | ||
| response_data: Final = ( | ||
| {"data": data} if dropped_deployments is None else {"data": data, "dropped_deployments": dropped_deployments} | ||
| ) | ||
| return Response( | ||
| content=orjson.dumps({"data": data}, default=jsonable_encoder, option=orjson.OPT_NON_STR_KEYS), | ||
| content=orjson.dumps(response_data, default=jsonable_encoder, option=orjson.OPT_NON_STR_KEYS), | ||
| media_type="application/json", | ||
| ) | ||
|
|
||
|
|
@@ -15267,7 +15274,12 @@ async def model_info_v1( | |
| visible_models: Final = [model for model in all_models if model.get("model_name") not in hidden_names] | ||
|
|
||
| verbose_proxy_logger.debug("all_models: %s", visible_models) | ||
| return _model_info_json_response(visible_models) | ||
| dropped_deployments: Final = ( | ||
| [asdict(dropped_deployment) for dropped_deployment in llm_router.dropped_deployments.values()] | ||
| if _user_has_admin_view(user_api_key_dict) | ||
| else None | ||
| ) | ||
|
Comment on lines
+15277
to
+15281
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| return _model_info_json_response(visible_models, dropped_deployments=dropped_deployments) | ||
|
|
||
|
|
||
| @router.get( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -234,6 +234,7 @@ | |
| Deployment, | ||
| DeploymentModelListingInfo, | ||
| DeploymentTypedDict, | ||
| DroppedDeployment, | ||
| FallbackAccessCheck, | ||
| GuardrailTypedDict, | ||
| LiteLLM_Params, | ||
|
|
@@ -908,6 +909,7 @@ def __init__( | |
| self.complexity_routers: dict[str, list[TaggedPreRoutingStrategy[ComplexityRouter]]] = {} | ||
| self.adaptive_routers: dict[str, list[TaggedPreRoutingStrategy[AdaptiveRouter]]] = {} | ||
| self.quality_routers: dict[str, list[TaggedPreRoutingStrategy[QualityRouter]]] = {} | ||
| self.dropped_deployments: Mapping[str, DroppedDeployment] = MappingProxyType({}) | ||
| self.routing_plugins: list[RoutingPlugin] = list(plugins) if plugins else [] | ||
|
|
||
| # Initialize model_group_alias early since it's used in set_model_list | ||
|
|
@@ -8950,6 +8952,16 @@ def _create_deployment( | |
| verbose_router_logger.exception( | ||
| "Error creating deployment: %s, ignoring and continuing with other deployments.", e | ||
| ) | ||
| self.dropped_deployments = MappingProxyType( | ||
| { | ||
| **self.dropped_deployments, | ||
| str(_model_info.get("id") or ""): DroppedDeployment( | ||
| model_name=_model_name, | ||
| model_id=str(_model_info.get("id") or ""), | ||
| error=str(e), | ||
| ), | ||
| } | ||
| ) | ||
| return None | ||
| else: | ||
| raise e | ||
|
|
@@ -9884,15 +9896,33 @@ def upsert_deployment(self, deployment: Deployment) -> Deployment | None: | |
| ) | ||
| ): | ||
| self._finalize_adaptive_router_if_configured() | ||
| if _deployment_model_id in self.dropped_deployments: | ||
| self.dropped_deployments = MappingProxyType( | ||
| { | ||
| model_id: dropped | ||
| for model_id, dropped in self.dropped_deployments.items() | ||
| if model_id != _deployment_model_id | ||
| } | ||
| ) | ||
| return deployment | ||
| except Exception as e: | ||
| if self.ignore_invalid_deployments: | ||
| verbose_router_logger.warning( | ||
| verbose_router_logger.error( | ||
| "Error upserting deployment %s (id=%s): %s. Dropping it and continuing with other deployments.", | ||
| deployment.model_name, | ||
| deployment.model_info.id, | ||
| e, | ||
| ) | ||
| self.dropped_deployments = MappingProxyType( | ||
| { | ||
| **self.dropped_deployments, | ||
| _deployment_model_id: DroppedDeployment( | ||
| model_name=deployment.model_name, | ||
| model_id=_deployment_model_id, | ||
| error=str(e), | ||
| ), | ||
| } | ||
| ) | ||
| self._restore_deployment_after_failed_upsert( | ||
| previous_deployment=_deployment_on_router, model_id=_deployment_model_id | ||
| ) | ||
|
|
@@ -10079,6 +10109,10 @@ def delete_deployment(self, id: str) -> Deployment | None: | |
| - The deleted deployment | ||
| - OR None (if deleted deployment not found) | ||
| """ | ||
| if id in self.dropped_deployments: | ||
| self.dropped_deployments = MappingProxyType( | ||
|
Comment on lines
10109
to
+10113
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| {model_id: dropped for model_id, dropped in self.dropped_deployments.items() if model_id != id} | ||
| ) | ||
| deployment_idx = None | ||
| if id in self.model_id_to_deployment_index_map: | ||
| deployment_idx = self.model_id_to_deployment_index_map[id] | ||
|
|
@@ -10109,6 +10143,16 @@ def delete_deployment(self, id: str) -> Deployment | None: | |
| except Exception: | ||
| return None | ||
|
|
||
| def dropped_deployment_for_model_name(self, model_name: str) -> DroppedDeployment | None: | ||
| return next( | ||
| ( | ||
| dropped_deployment | ||
| for dropped_deployment in self.dropped_deployments.values() | ||
| if dropped_deployment.model_name == model_name | ||
| ), | ||
| None, | ||
| ) | ||
|
|
||
| def _get_router_deployment_budget_limiter( | ||
| self, | ||
| ) -> RouterBudgetLimiting | None: | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorting reads
created_atbefore processing, so existing row-like callers without that attribute raise immediately and no deployments are loadedKnowledge Base Used: Proxy configuration and deployment