Skip to content
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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 6 additions & 0 deletions bundle/config/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ func (r *Resources) FindResourceByConfigKey(key string) (ConfigResource, error)
}
}

for k := range r.Experiments {
Copy link
Contributor

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 support bind/unbind

Copy link
Contributor Author

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 type

Copy link
Contributor

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?

Copy link
Contributor

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.

if k == key {
found = append(found, r.Experiments[k])
}
}

if len(found) == 0 {
return nil, fmt.Errorf("no such resource: %s", key)
}
Expand Down
62 changes: 62 additions & 0 deletions integration/bundle/bind_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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)

Expand Down
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'"
}
}
}
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