-
Notifications
You must be signed in to change notification settings - Fork 74
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
Add support for experiments in deployment bind/unbind commands #2434
Open
anton-107
wants to merge
2
commits into
main
Choose a base branch
from
anton-107/bind-experiment
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.
+92
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -17,8 +17,70 @@ import ( | |
"github.com/stretchr/testify/require" | ||
|
||
"github.com/databricks/databricks-sdk-go/service/catalog" | ||
"github.com/databricks/databricks-sdk-go/service/ml" | ||
) | ||
|
||
func TestBindExperimentToExistingExperiment(t *testing.T) { | ||
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. I know that existing tests for bind are integration tests but have you explored making new ones acceptance tests instead? |
||
ctx, wt := acc.UcWorkspaceTest(t) | ||
|
||
currentUser, err := wt.W.CurrentUser.Me(ctx) | ||
require.NoError(t, err) | ||
|
||
// create a pre-defined experiment: | ||
uniqueId := uuid.New().String() | ||
experimentName := "/Workspace/Users/" + currentUser.UserName + "/test-experiment" + uniqueId | ||
predefinedExperiment, err := wt.W.Experiments.CreateExperiment(ctx, ml.CreateExperiment{ | ||
Name: experimentName, | ||
ArtifactLocation: "s3://test-location", | ||
}) | ||
require.NoError(t, err) | ||
t.Cleanup(func() { | ||
err := wt.W.Experiments.DeleteExperiment(ctx, ml.DeleteExperiment{ExperimentId: predefinedExperiment.ExperimentId}) | ||
require.NoError(t, err) | ||
}) | ||
|
||
// setup the bundle: | ||
bundleRoot := initTestTemplate(t, ctx, "ml_experiment", map[string]any{ | ||
"unique_id": uniqueId, | ||
"experiment_name": experimentName, | ||
}) | ||
ctx = env.Set(ctx, "BUNDLE_ROOT", bundleRoot) | ||
|
||
// run the bind command: | ||
c := testcli.NewRunner(t, ctx, "bundle", "deployment", "bind", "experiment1", predefinedExperiment.ExperimentId, "--auto-approve") | ||
_, _, err = c.Run() | ||
require.NoError(t, err) | ||
|
||
// deploy the bundle: | ||
deployBundle(t, ctx, bundleRoot) | ||
|
||
// check that the predefinedExperiment was not re-created / deleted (it is still active): | ||
w, err := databricks.NewWorkspaceClient() | ||
require.NoError(t, err) | ||
|
||
updatedExperiment, err := w.Experiments.GetExperiment(ctx, ml.GetExperimentRequest{ | ||
ExperimentId: predefinedExperiment.ExperimentId, | ||
}) | ||
require.NoError(t, err) | ||
|
||
require.Equal(t, "active", updatedExperiment.Experiment.LifecycleStage) | ||
|
||
// unbind the experiment: | ||
c = testcli.NewRunner(t, ctx, "bundle", "deployment", "unbind", "experiment1") | ||
_, _, err = c.Run() | ||
require.NoError(t, err) | ||
|
||
// destroy the bundle: | ||
destroyBundle(t, ctx, bundleRoot) | ||
|
||
// Check that experiment is unbound and exists after bundle is destroyed | ||
postDestroyExperiment, err := w.Experiments.GetExperiment(ctx, ml.GetExperimentRequest{ | ||
ExperimentId: predefinedExperiment.ExperimentId, | ||
}) | ||
require.NoError(t, err) | ||
require.Equal(t, "active", postDestroyExperiment.Experiment.LifecycleStage) | ||
} | ||
|
||
func TestBindSchemaToExistingSchema(t *testing.T) { | ||
ctx, wt := acc.UcWorkspaceTest(t) | ||
|
||
|
12 changes: 12 additions & 0 deletions
12
integration/bundle/bundles/ml_experiment/databricks_template_schema.json
This file contains 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,12 @@ | ||
{ | ||
"properties": { | ||
"unique_id": { | ||
"type": "string", | ||
"description": "Unique ID for the experiment name" | ||
}, | ||
"experiment_name": { | ||
"type": "string", | ||
"description": "Experiment name. An experiment name must be an absolute path within the Databricks workspace, e.g. '/Users/<some-username>/my-experiment'" | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
integration/bundle/bundles/ml_experiment/template/databricks.yml.tmpl
This file contains 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,12 @@ | ||
bundle: | ||
name: ml-experiment | ||
|
||
workspace: | ||
root_path: "~/.bundle/{{.unique_id}}" | ||
|
||
resources: | ||
experiments: | ||
experiment1: | ||
name: {{.experiment_name}} | ||
artifact_location: s3://test-location | ||
|
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.
Shall we just extend it to all supported resources instead of doing 1 by 1? You can rewrite this code to use
lib/dyn
to iterate over all existing resources and find the ones matching. So later when new resources are added they will automatically supportbind/unbind
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.
I'd propose to do it after all resources are enabled in
bind/unbind
- the PRs still require individual integration tests to be introduced for each resource typeThere 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.
That's fine too unless you have any ideas how maybe we can test bind for all the supported resources instead of writing individual tests?
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.
FWIW, I think doing it case by case is fine here. It forces thinking about the semantics for bind/unbind for specific resources. For example, I think that for dashboards it might not be as clear cut because of the workspace path / ID duality.