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 databricks labs command group #914

Merged
merged 8 commits into from
Nov 17, 2023
Merged

Add databricks labs command group #914

merged 8 commits into from
Nov 17, 2023

Conversation

nfx
Copy link
Contributor

@nfx nfx commented Oct 24, 2023

@nfx nfx requested a review from pietern October 24, 2023 19:41
@nfx
Copy link
Contributor Author

nfx commented Oct 24, 2023

Downstream command router can be really trivial:

import logging
import sys, json

from databricks.sdk import WorkspaceClient

from databricks.labs.ucx.install import WorkspaceInstaller


def jobs():
    ws = WorkspaceClient()
    installer = WorkspaceInstaller(ws)
    for step, job_id in installer.deployed_steps().items():
        print(step, job_id)


def me():
    ws = WorkspaceClient()
    my_user = ws.current_user.me()
    print(my_user.user_name)


MAPPING = {
    'jobs': jobs,
    'me': me,
}


def main(raw):
    payload = json.loads(raw)
    command = payload['command']
    if command not in MAPPING:
        raise KeyError(f'cannot find command: {command}')
    flags = payload['flags']
    log_level = flags.pop('log_level')
    if log_level != 'disabled':
        databricks_logger = logging.getLogger("databricks")
        databricks_logger.setLevel(log_level.upper())

    kwargs = {k.replace('-', '_'): v for k,v in flags.items()}
    MAPPING[command](**kwargs)


if __name__ == "__main__":
    main(*sys.argv[1:])

@nfx
Copy link
Contributor Author

nfx commented Oct 27, 2023

#927 make snapshot in a separate PR

@nfx nfx marked this pull request as ready for review October 27, 2023 10:47
cmd/labs/list_test.go Show resolved Hide resolved
cmd/labs/installable/repositories.go Outdated Show resolved Hide resolved
cmd/labs/installable/repositories.go Outdated Show resolved Hide resolved
cmd/labs/localcache/jsonfile.go Show resolved Hide resolved
cmd/labs/localcache/jsonfile_test.go Outdated Show resolved Hide resolved
cmd/labs/project/project.go Outdated Show resolved Hide resolved
cmd/labs/project/project.go Outdated Show resolved Hide resolved
cmd/labs/project/project.go Outdated Show resolved Hide resolved
cmd/labs/localcache/jsonfile.go Outdated Show resolved Hide resolved
cmd/labs/releases/releases.go Outdated Show resolved Hide resolved
@nfx
Copy link
Contributor Author

nfx commented Nov 8, 2023

installing this branch

brew install golang
git@github.com:databricks/cli.git
cd cli
git checkout feat/labs
make snapshot

and the binary will be in .databricks/databricks file

github-merge-queue bot pushed a commit that referenced this pull request Nov 8, 2023
## Changes
`os.Getenv(..)` is not friendly with `libs/env`. This PR makes the
relevant changes to places where we need to read user home directory.

## Tests
Mainly done in #914
github-merge-queue bot pushed a commit that referenced this pull request Nov 9, 2023
)

## Changes

This PR makes unit testing with subprocesses fast.

```
	ctx := context.Background()
	ctx, stub := process.WithStub(ctx)
	stub.WithDefaultOutput("meeee")

	ctx = env.Set(ctx, "FOO", "bar")

	out, err := process.Background(ctx, []string{"/usr/local/bin/meeecho", "1", "--foo", "bar"})
	require.NoError(t, err)
	require.Equal(t, "meeee", out)
	require.Equal(t, 1, stub.Len())
	require.Equal(t, []string{"meeecho 1 --foo bar"}, stub.Commands())

	allEnv := stub.CombinedEnvironment()
	require.Equal(t, "bar", allEnv["FOO"])
	require.Equal(t, "bar", stub.LookupEnv("FOO"))
```

This should make further iterations of
#914 easier

## Tests

`make test`
github-merge-queue bot pushed a commit that referenced this pull request Nov 9, 2023
… flow by displaying cluster type and runtime version (#956)

This PR adds selectors for Databricks-connect compatible clusters and
SQL warehouses

Tested in #914
..

Add folder

list installed works

stdin forwarding

fixed some tests

tests pass

fetching versions

added installer, still WIP

fixed tests for UNIX

added debug logging

..

installer tests

..

run on windows

xx

fixed

added uninstall

..

work on windows

..

..

work with more CUJs

pick up configuration when auth.json is not found

..

Added spinners

added cluster prompts

..

...

..

support for dbconnect lib install

..

..

..

fixed dev libDIr logic

starting tests for dev installs

+10% coverage

,,

..

..

..
@alexott
Copy link
Contributor

alexott commented Nov 10, 2023

Got error on the clean install

Error: save cache: open /Users/alexey.ott/.databricks/labs/databrickslabs-repositories.json: no such file or directory

@alexott
Copy link
Contributor

alexott commented Nov 10, 2023

Another bug

$ databricks labs sandbox ip-access-list-analyzer --profile=az-alexott
Error: cannot find Python 3.8. Please re-run: databricks labs install ip-access-list-analyzer

@alexott
Copy link
Contributor

alexott commented Nov 10, 2023

>databricks labs install . --debug
time=2023-11-10T11:12:49.984+01:00 level=INFO source="root.go 55}" msg=start pid=51984 version=0.0.0-dev+5819644739e8 args="databricks, labs, install, ., --debug"
Installing sandbox in development mode from /Users/.../work/samples/dbl-sandbox

cmd/labs/clear_cache.go Show resolved Hide resolved
cmd/labs/github/github.go Outdated Show resolved Hide resolved
cmd/labs/github/releases.go Show resolved Hide resolved
cmd/labs/github/releases_test.go Outdated Show resolved Hide resolved
cmd/labs/labs.go Outdated Show resolved Hide resolved
cmd/labs/project/entrypoint.go Show resolved Hide resolved
cmd/labs/project/entrypoint.go Show resolved Hide resolved
cmd/labs/project/proxy.go Show resolved Hide resolved
cmd/labs/uninstall.go Outdated Show resolved Hide resolved
@nfx nfx requested a review from pietern November 17, 2023 09:56
@nfx
Copy link
Contributor Author

nfx commented Nov 17, 2023

#914 (comment) - fixed

these two are related to dev mode, that we'll fix by talking with dev - #914 (comment) #914 (comment)

@pietern
Copy link
Contributor

pietern commented Nov 17, 2023

This change LGTM and acknowledge there will be follop-ups on the UX.

Would appreciate a second pair of eyes before a stamp.

// cleanup auth profile and config file location,
// so that we don't confuse SDKs
cfg.Profile = ""
cfg.ConfigFile = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

These won't be cleared in the environment because they are zero. That means they are not returned from e.environmentFromConfig below and are not cleared for the subprocess, which could confuse downstream programs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@pietern the only case possible when we have --profile (DATABRICKS_CONFIG_PROFILE) is the local dev machine. Github actions (and likes) won't have the DATABRICKS_CONFIG_PROFILE / DATABRICKS_CONFIG_FILE envs set, but rather direct ones, like client ids or hosts. there are tests that verify this to work from github actions-like environments

Copy link
Contributor

@mgyucht mgyucht left a comment

Choose a reason for hiding this comment

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

@pietern and I reviewed this together this afternoon and feel generally good about it. Let's get labs on the road!

@nfx nfx added this pull request to the merge queue Nov 17, 2023
@pietern pietern removed this pull request from the merge queue due to a manual request Nov 17, 2023
@pietern
Copy link
Contributor

pietern commented Nov 17, 2023

Removed from the merge queue if you want to take a look at the issue above.

@nfx
Copy link
Contributor Author

nfx commented Nov 17, 2023

@pietern that permutation of configuration flags is very unlikely to happen and has unit tests already. going ahead with the merge :)

@nfx nfx added this pull request to the merge queue Nov 17, 2023
Merged via the queue into main with commit 1b7558c Nov 17, 2023
4 checks passed
@nfx nfx deleted the feat/labs branch November 17, 2023 12:52
pietern added a commit that referenced this pull request Nov 29, 2023
This release includes the new `databricks labs` command to install, manage, and run Databricks Labs projects.

CLI:
 * Add `--debug` as shortcut for `--log-level debug` ([#964](#964)).
 * Improved usability of `databricks auth login ... --configure-cluster` ([#956](#956)).
 * Make `databricks configure` save only explicit fields ([#973](#973)).
 * Add `databricks labs` command group ([#914](#914)).
 * Tolerate missing .databrickscfg file during `databricks auth login` ([#1003](#1003)).
 * Add `--configure-cluster` flag to configure command ([#1005](#1005)).
 * Fix bug where the account or workspace client could be `nil` ([#1020](#1020)).

Bundles:
 * Do not allow empty descriptions for bundle template inputs ([#967](#967)).
 * Added support for top-level permissions ([#928](#928)).
 * Allow jobs to be manually unpaused in development mode ([#885](#885)).
 * Fix template initialization from current working directory ([#976](#976)).
 * Add `--tag` and `--branch` options to bundle init command ([#975](#975)).
 * Work around DLT issue with `$PYTHONPATH` not being set correctly ([#999](#999)).
 * Enable `spark_jar_task` with local JAR libraries ([#993](#993)).
 * Pass `USERPROFILE` environment variable to Terraform ([#1001](#1001)).
 * Improve error message when path is not a bundle template ([#985](#985)).
 * Correctly overwrite local state if remote state is newer ([#1008](#1008)).
 * Add mlops-stacks to the default `databricks bundle init` prompt ([#988](#988)).
 * Do not add wheel content hash in uploaded Python wheel path ([#1015](#1015)).
 * Do not replace pipeline libraries if there are no matches for pattern ([#1021](#1021)).

Internal:
 * Update CLI version in the VS Code extension during release ([#1014](#1014)).

API Changes:
 * Changed `databricks functions create` command . New request type is .
 * Changed `databricks metastores create` command with new required argument order.
 * Removed `databricks metastores enable-optimization` command.
 * Removed `databricks account o-auth-enrollment` command group.
 * Removed `databricks apps delete` command.
 * Removed `databricks apps get` command.
 * Added `databricks apps delete-app` command.
 * Added `databricks apps get-app` command.
 * Added `databricks apps get-app-deployment-status` command.
 * Added `databricks apps get-apps` command.
 * Added `databricks apps get-events` command.
 * Added `databricks account network-connectivity` command group.

OpenAPI commit 22f09783eb8a84d52026f856be3b2068f9498db3 (2023-11-23)

Dependency updates:
 * Bump golang.org/x/term from 0.13.0 to 0.14.0 ([#981](#981)).
 * Bump github.com/hashicorp/terraform-json from 0.17.1 to 0.18.0 ([#979](#979)).
 * Bump golang.org/x/oauth2 from 0.13.0 to 0.14.0 ([#982](#982)).
 * Bump github.com/databricks/databricks-sdk-go from 0.24.0 to 0.25.0 ([#980](#980)).
 * Bump github.com/databricks/databricks-sdk-go from 0.25.0 to 0.26.0 ([#1019](#1019)).
@pietern pietern mentioned this pull request Nov 29, 2023
github-merge-queue bot pushed a commit that referenced this pull request Nov 29, 2023
This release includes the new `databricks labs` command to install,
manage, and run Databricks Labs projects.

CLI:
* Add `--debug` as shortcut for `--log-level debug`
([#964](#964)).
* Improved usability of `databricks auth login ... --configure-cluster`
([#956](#956)).
* Make `databricks configure` save only explicit fields
([#973](#973)).
* Add `databricks labs` command group
([#914](#914)).
* Tolerate missing .databrickscfg file during `databricks auth login`
([#1003](#1003)).
* Add `--configure-cluster` flag to configure command
([#1005](#1005)).
* Fix bug where the account or workspace client could be `nil`
([#1020](#1020)).

Bundles:
* Do not allow empty descriptions for bundle template inputs
([#967](#967)).
* Added support for top-level permissions
([#928](#928)).
* Allow jobs to be manually unpaused in development mode
([#885](#885)).
* Fix template initialization from current working directory
([#976](#976)).
* Add `--tag` and `--branch` options to bundle init command
([#975](#975)).
* Work around DLT issue with `$PYTHONPATH` not being set correctly
([#999](#999)).
* Enable `spark_jar_task` with local JAR libraries
([#993](#993)).
* Pass `USERPROFILE` environment variable to Terraform
([#1001](#1001)).
* Improve error message when path is not a bundle template
([#985](#985)).
* Correctly overwrite local state if remote state is newer
([#1008](#1008)).
* Add mlops-stacks to the default `databricks bundle init` prompt
([#988](#988)).
* Do not add wheel content hash in uploaded Python wheel path
([#1015](#1015)).
* Do not replace pipeline libraries if there are no matches for pattern
([#1021](#1021)).

Internal:
* Update CLI version in the VS Code extension during release
([#1014](#1014)).

API Changes:
 * Changed `databricks functions create` command.
* Changed `databricks metastores create` command with new required
argument order.
 * Removed `databricks metastores enable-optimization` command.
 * Removed `databricks account o-auth-enrollment` command group.
 * Removed `databricks apps delete` command.
 * Removed `databricks apps get` command.
 * Added `databricks apps delete-app` command.
 * Added `databricks apps get-app` command.
 * Added `databricks apps get-app-deployment-status` command.
 * Added `databricks apps get-apps` command.
 * Added `databricks apps get-events` command.
 * Added `databricks account network-connectivity` command group.

OpenAPI commit 22f09783eb8a84d52026f856be3b2068f9498db3 (2023-11-23)

Dependency updates:
* Bump golang.org/x/term from 0.13.0 to 0.14.0
([#981](#981)).
* Bump github.com/hashicorp/terraform-json from 0.17.1 to 0.18.0
([#979](#979)).
* Bump golang.org/x/oauth2 from 0.13.0 to 0.14.0
([#982](#982)).
* Bump github.com/databricks/databricks-sdk-go from 0.24.0 to 0.25.0
([#980](#980)).
* Bump github.com/databricks/databricks-sdk-go from 0.25.0 to 0.26.0
([#1019](#1019)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLI CLI related issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants