-
Notifications
You must be signed in to change notification settings - Fork 145
Add support for models in direct deployment #3625
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ce6fcc9
[wip] add support for models in direct deployment
shreyas-goenka 98a2cf0
merge
shreyas-goenka d7cf4b9
-
shreyas-goenka 12b9f34
complete impl
shreyas-goenka 7289b79
add acceptance test
shreyas-goenka ce2e2c7
iterate on pr
shreyas-goenka d4d96c3
cleanup
shreyas-goenka c190f00
update fields test
shreyas-goenka f456686
fixed handler
shreyas-goenka 1b90fde
make local as well
shreyas-goenka 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
|
|
||
| >>> export MODEL_NAME=original-name-[UNIQUE_NAME] | ||
|
|
||
| >>> export MODEL_DESCRIPTION=original-description-[UNIQUE_NAME] | ||
|
|
||
| === create a model | ||
| >>> [CLI] bundle plan | ||
| create models.my_model | ||
|
|
||
| Plan: 1 to add, 0 to change, 0 to delete, 0 unchanged | ||
|
|
||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-models-basic-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> [CLI] model-registry get-model original-name-[UNIQUE_NAME] | ||
| { | ||
| "name": "original-name-[UNIQUE_NAME]", | ||
| "description": "original-description-[UNIQUE_NAME]", | ||
| "tags": [ | ||
| { | ||
| "key": "key1", | ||
| "value": "value1" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| >>> export MODEL_DESCRIPTION=new-description-[UNIQUE_NAME] | ||
|
|
||
| === update the description, this should update the description remotely as well | ||
| >>> [CLI] bundle plan | ||
| update models.my_model | ||
|
|
||
| Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged | ||
|
|
||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-models-basic-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> [CLI] model-registry get-model original-name-[UNIQUE_NAME] | ||
| { | ||
| "name": "original-name-[UNIQUE_NAME]", | ||
| "description": "new-description-[UNIQUE_NAME]", | ||
| "tags": [ | ||
| { | ||
| "key": "key1", | ||
| "value": "value1" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| >>> export MODEL_NAME=new-name-[UNIQUE_NAME] | ||
|
|
||
| === update the name, this should recreate the model with the new name | ||
| >>> [CLI] bundle plan | ||
| recreate models.my_model | ||
|
|
||
| Plan: 1 to add, 0 to change, 1 to delete, 0 unchanged | ||
|
|
||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-models-basic-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> [CLI] model-registry get-model new-name-[UNIQUE_NAME] | ||
| { | ||
| "name": "new-name-[UNIQUE_NAME]", | ||
| "description": "new-description-[UNIQUE_NAME]", | ||
| "tags": [ | ||
| { | ||
| "key": "key1", | ||
| "value": "value1" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| === add a new tag, this should be a no-op | ||
| >>> [CLI] bundle plan | ||
| update models.my_model | ||
|
|
||
| Plan: 0 to add, 1 to change, 0 to delete, 0 unchanged | ||
|
|
||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/deploy-models-basic-[UNIQUE_NAME]/default/files... | ||
| Deploying resources... | ||
| Updating deployment state... | ||
| Deployment complete! | ||
|
|
||
| >>> [CLI] model-registry get-model new-name-[UNIQUE_NAME] | ||
| { | ||
| "name": "new-name-[UNIQUE_NAME]", | ||
| "description": "new-description-[UNIQUE_NAME]", | ||
| "tags": [ | ||
| { | ||
| "key": "key1", | ||
| "value": "value1" | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| >>> [CLI] bundle destroy --auto-approve | ||
| The following resources will be deleted: | ||
| delete model my_model | ||
|
|
||
| All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/deploy-models-basic-[UNIQUE_NAME]/default | ||
|
|
||
| Deleting files... | ||
| Destroy complete! | ||
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| cleanup() { | ||
| trace $CLI bundle destroy --auto-approve | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| trace export MODEL_NAME=original-name-$UNIQUE_NAME | ||
| trace export MODEL_DESCRIPTION=original-description-$UNIQUE_NAME | ||
| envsubst < templates/one_tag.tmpl > databricks.yml | ||
| title "create a model" | ||
| trace $CLI bundle plan | ||
| trace $CLI bundle deploy | ||
| trace $CLI model-registry get-model $MODEL_NAME | jq '.registered_model_databricks | {name, description, tags}' | ||
|
|
||
| trace export MODEL_DESCRIPTION=new-description-$UNIQUE_NAME | ||
| envsubst < templates/one_tag.tmpl > databricks.yml | ||
| title "update the description, this should update the description remotely as well" | ||
| trace $CLI bundle plan | ||
| trace $CLI bundle deploy | ||
| trace $CLI model-registry get-model $MODEL_NAME | jq '.registered_model_databricks | {name, description, tags}' | ||
|
|
||
| trace export MODEL_NAME=new-name-$UNIQUE_NAME | ||
| envsubst < templates/one_tag.tmpl > databricks.yml | ||
| title "update the name, this should recreate the model with the new name" | ||
| trace $CLI bundle plan | ||
| trace $CLI bundle deploy | ||
| trace $CLI model-registry get-model $MODEL_NAME | jq '.registered_model_databricks | {name, description, tags}' | ||
|
|
||
| title "add a new tag, this should be a no-op" | ||
| envsubst < templates/two_tag.tmpl > databricks.yml | ||
| trace $CLI bundle plan | ||
| trace $CLI bundle deploy | ||
| trace $CLI model-registry get-model $MODEL_NAME | jq '.registered_model_databricks | {name, description, tags}' |
11 changes: 11 additions & 0 deletions
11
acceptance/bundle/deploy/models/basic/templates/one_tag.tmpl
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 |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| bundle: | ||
| name: deploy-models-basic-$UNIQUE_NAME | ||
|
|
||
| resources: | ||
| models: | ||
| my_model: | ||
| name: $MODEL_NAME | ||
| description: $MODEL_DESCRIPTION | ||
| tags: | ||
| - key: "key1" | ||
| value: "value1" |
13 changes: 13 additions & 0 deletions
13
acceptance/bundle/deploy/models/basic/templates/two_tag.tmpl
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 |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| bundle: | ||
| name: deploy-models-basic-$UNIQUE_NAME | ||
|
|
||
| resources: | ||
| models: | ||
| my_model: | ||
| name: $MODEL_NAME | ||
| description: $MODEL_DESCRIPTION | ||
| tags: | ||
| - key: "key1" | ||
| value: "value1" | ||
| - key: "key2" | ||
| value: "value2" |
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 |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Cloud = true | ||
| Local = true |
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
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 |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package dresources | ||
|
|
||
| import ( | ||
| "context" | ||
|
|
||
| "github.com/databricks/cli/bundle/config/resources" | ||
| "github.com/databricks/cli/bundle/deployplan" | ||
| "github.com/databricks/databricks-sdk-go" | ||
| "github.com/databricks/databricks-sdk-go/service/ml" | ||
| ) | ||
|
|
||
| type ResourceMlflowModel struct { | ||
| client *databricks.WorkspaceClient | ||
| } | ||
|
|
||
| func (*ResourceMlflowModel) New(client *databricks.WorkspaceClient) *ResourceMlflowModel { | ||
| return &ResourceMlflowModel{client: client} | ||
| } | ||
|
|
||
| func (*ResourceMlflowModel) PrepareState(input *resources.MlflowModel) *ml.CreateModelRequest { | ||
| return &input.CreateModelRequest | ||
| } | ||
|
|
||
| func (*ResourceMlflowModel) RemapState(model *ml.ModelDatabricks) *ml.CreateModelRequest { | ||
| return &ml.CreateModelRequest{ | ||
| Name: model.Name, | ||
| Tags: model.Tags, | ||
| Description: model.Description, | ||
| ForceSendFields: filterFields[ml.CreateModelRequest](model.ForceSendFields), | ||
| } | ||
| } | ||
|
|
||
| func (r *ResourceMlflowModel) DoRefresh(ctx context.Context, id string) (*ml.ModelDatabricks, error) { | ||
| response, err := r.client.ModelRegistry.GetModel(ctx, ml.GetModelRequest{ | ||
| Name: id, | ||
| }) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return response.RegisteredModelDatabricks, nil | ||
| } | ||
|
|
||
| func (r *ResourceMlflowModel) DoCreate(ctx context.Context, config *ml.CreateModelRequest) (string, *ml.ModelDatabricks, error) { | ||
| response, err := r.client.ModelRegistry.CreateModel(ctx, *config) | ||
| if err != nil { | ||
| return "", nil, err | ||
| } | ||
| // Create API call returns [ml.Model] while DoRefresh returns [ml.ModelDatabricks]. | ||
| // Thus we need to convert the response to the expected type. | ||
| modelDatabricks := &ml.ModelDatabricks{ | ||
| Name: response.RegisteredModel.Name, | ||
| Description: response.RegisteredModel.Description, | ||
| Tags: response.RegisteredModel.Tags, | ||
| ForceSendFields: filterFields[ml.ModelDatabricks](response.RegisteredModel.ForceSendFields, "CreationTimestamp", "Id", "LastUpdatedTimestamp", "LatestVersions", "PermissionLevel", "UserId"), | ||
|
|
||
| // Coping the fields only to satisfy the linter. These fields are not | ||
| // part of the configuration tree so they don't need to be copied. | ||
| // The linter works as a safeguard to ensure we add new fields to the bundle config tree | ||
| // to the mapping logic here as well. | ||
| CreationTimestamp: 0, | ||
| Id: "", | ||
| LastUpdatedTimestamp: 0, | ||
| LatestVersions: nil, | ||
| PermissionLevel: "", | ||
| UserId: "", | ||
| } | ||
| return response.RegisteredModel.Name, modelDatabricks, nil | ||
| } | ||
|
|
||
| func (r *ResourceMlflowModel) DoUpdate(ctx context.Context, id string, config *ml.CreateModelRequest) (*ml.ModelDatabricks, error) { | ||
| updateRequest := ml.UpdateModelRequest{ | ||
| Name: id, | ||
| Description: config.Description, | ||
| ForceSendFields: filterFields[ml.UpdateModelRequest](config.ForceSendFields), | ||
| } | ||
|
|
||
| response, err := r.client.ModelRegistry.UpdateModel(ctx, updateRequest) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| // Update API call returns [ml.Model] while DoRefresh returns [ml.ModelDatabricks]. | ||
| // Thus we need to convert the response to the expected type. | ||
| modelDatabricks := &ml.ModelDatabricks{ | ||
| Name: response.RegisteredModel.Name, | ||
| Description: response.RegisteredModel.Description, | ||
| Tags: response.RegisteredModel.Tags, | ||
| ForceSendFields: filterFields[ml.ModelDatabricks](response.RegisteredModel.ForceSendFields, "CreationTimestamp", "Id", "LastUpdatedTimestamp", "LatestVersions", "PermissionLevel", "UserId"), | ||
|
|
||
| // Coping the fields only to satisfy the linter. These fields are not | ||
| // part of the configuration tree so they don't need to be copied. | ||
| // The linter works as a safeguard to ensure we add new fields to the bundle config tree | ||
| // to the mapping logic here as well. | ||
| CreationTimestamp: 0, | ||
| Id: "", | ||
| LastUpdatedTimestamp: 0, | ||
| LatestVersions: nil, | ||
| PermissionLevel: "", | ||
| UserId: "", | ||
| } | ||
| return modelDatabricks, nil | ||
| } | ||
|
|
||
| func (r *ResourceMlflowModel) DoDelete(ctx context.Context, id string) error { | ||
| return r.client.ModelRegistry.DeleteModel(ctx, ml.DeleteModelRequest{ | ||
| Name: id, | ||
| }) | ||
| } | ||
|
|
||
| func (*ResourceMlflowModel) FieldTriggers() map[string]deployplan.ActionType { | ||
| return map[string]deployplan.ActionType{ | ||
| // Recreate matches current behavior of Terraform. It is possible to rename without recreate | ||
| // but that would require dynamic select of the method during update since | ||
| // the [ml.RenameModel] needs to be called instead of [ml.UpdateModel]. | ||
| // | ||
| // We might reasonably choose to never fix this because this is a legacy resource. | ||
| "name": deployplan.ActionTypeRecreate, | ||
|
|
||
| // Allowing updates for tags requires dynamic selection of the method since | ||
| // tags can only be updated by calling [ml.SetModelTag] or [ml.DeleteModelTag] methods. | ||
| // | ||
| // Skip annotation matches the current behavior of Terraform where tags changes are showed | ||
| // in plan but are just ignored / not applied. Since this is a legacy resource we might | ||
| // reasonably choose to not fix it here as well. | ||
| "tags": deployplan.ActionTypeSkip, | ||
| } | ||
| } |
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.
the comments says "this should be a no-op" but the plan shows an update.
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.
We show a change even though field is annotated as skip right? I observed the same behaviour in models.
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.
Discussed offline - TF does make a call but the call does not have "tags" in the request, so the request is essentially noop.
Direct should not make a request at all since the field is marked as 'skip', it's a bug that it does. Fixed in #3636
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.
The json plan makes it more clear -- the field shows up but it's marked as skip and the whole resource is marked as skip.