Commit Graph

243 Commits

Author SHA1 Message Date
Shreyas Goenka dab957d05e
- 2025-03-05 13:58:14 +01:00
Shreyas Goenka 9e29462562
use proper loggers 2025-03-05 13:56:16 +01:00
Shreyas Goenka d854660f77
added debug log test 2025-03-05 13:45:51 +01:00
Shreyas Goenka bd35ac956e
implement the command in cobra 2025-03-05 13:43:46 +01:00
Shreyas Goenka 217d4e7be2
add comment for failure 2025-03-05 13:25:29 +01:00
Shreyas Goenka fbc657d48c
Merge remote-tracking branch 'origin' into async-logger-clean 2025-03-05 13:19:08 +01:00
Denis Bilenko a26461c5a3
Do not modify/create .gitignore in bundle root (#2429)
## Changes
- Do not modify or edit .gitignore in bundle root.
- Instead create .databricks/.gitignore with content set to "*"

## Why
Merging our changes into existing .gitignore is complicated and adding
.gitignore where it's not expected adds to the noise. Other tools also
use the approach in this PR (e.g. ruff creates .ruff_cache/.gitignore).

## Tests
- Modified templates/default-sql to capture this new file.
2025-03-05 10:57:05 +00:00
Andrew Nester 4dba35dff4
Upgrade TF provider to 1.68.0 (#2426)
## Changes
Upgrade TF provider to 1.68.0

- Added support for Volumes as a destination for Cluster log conf
2025-03-05 10:20:55 +00:00
Andrew Nester 294db2ecca
Upgrade Go SDK to 0.59.0 (#2425)
## Changes
- Added `service-principal-secrets` command
- Added `budget-policy-id` for apps
- `experiments.log-inputs` now requires `ID` parameter as an input
- Added `genie.get-space` command
- Added `providers.list-provider-share-assets` command

For the whole list of SDK changes see:
https://github.com/databricks/databricks-sdk-go/releases/tag/v0.59.0
2025-03-05 10:20:51 +00:00
Andrew Nester 41961226be
Switch to use GET workspaces-files/{name} instead of workspace/export for state files (#2423)
## Changes
Switch to use GET workspaces-files/{name} instead of workspace/export
for state files.

## Why
`/api/2.0./workspaces-files/{name}` has a higher limit which allows to
export state files larger than 10 MBs (which is the current limit for
`workspace/export`). We don't use the same API for read in other places
and fully replacing existing Filer because it doesn't correct get the
file content for notebooks and returns "File Not Found" error instead.

## Tests
All existing tests pass
2025-03-04 15:03:51 +00:00
Andrew Nester 010f88f84e
Added a warning when `config` section is used in apps (#2416)
## Changes
Added a warning when `config` section is used in apps

## Why
To avoid the confusion between using apps in DABs and outside of DABs,
we want to provide only one way of configuring apps runtime
configuration - by using `app.yml` file in the root of the app.

## Tests
Added acceptance tests
2025-03-03 16:40:28 +00:00
Denis Bilenko e4cd782852
Remove bundle.{Parallel,ReadOnlyBundle} (#2414)
## Changes
- Remove bundle.Parallel & bundle.ReadOnlyBundle.
- Add bundle.ApplyParallel, as a helper to migrate from bundle.Parallel.
- Keep ReadOnlyMutator as a separate type but it's now a subtype of
Mutator so it works on regular *Bundle. Having it as a separate type
prevents non-readonly mutators being passed to ApplyParallel
- validate.Validate becomes a function (was Mutator).

## Why
This a follow up to #2390 where we removed most of the tools to
construct chains of mutators. Same motivation applies here.

When it comes to read-only bundles, it's a leaky abstraction -- since
it's a shallow copy, it does not actually guarantee or enforce readonly
access to bundle. A better approach would be to run parallel operations
on independent narrowly-focused deep-copied structs, with just enough
information to carry out the task (this is not implemented here, but the
eventual goal). Now that we can just write regular code in phases and
not limited to mutator interface, we can switch to that approach.

## Tests
Existing tests.

---------

Co-authored-by: shreyas-goenka <88374338+shreyas-goenka@users.noreply.github.com>
2025-03-03 13:35:36 +00:00
Denis Bilenko 2c5b61538d
acc: Prevent regex in test.toml from consuming too much (#2417)
The original regex can consume both lines and sometimes it does.
2025-03-03 12:55:52 +00:00
Denis Bilenko 8f8f24c3a9
Convert python wheel tests to acceptance (#2396)
## Changes

Rewrite bundle/tests/python_wheel_test.go into acceptance tests. The
same configs are used, but the test now runs 'bundle deploy' and in
addition to checking the files on the file system, also checks that the
files were uploaded and records jobs/create request.

There is a new test helper bin/find.py which filters out paths based on
regex, asserts on number of expected results. I've added it because
'find' on Windows behaves differently, so this helps avoid
cross-platform differences.
2025-03-03 11:09:25 +00:00
shreyas-goenka 03e4bb2575
Update warning for includes outside root to only mention databricks.yml (#2411)
## Why
Addresses feedback from this thread:
https://github.com/databricks/cli/pull/2389#discussion_r1975760462.
2025-03-03 09:21:39 +00:00
Shreyas Goenka efdb977470
better debug logs 2025-03-02 17:36:10 +01:00
Shreyas Goenka 5a2dcbbfc8
incremental improvements 2025-03-02 17:31:11 +01:00
Shreyas Goenka da7e9e23ca
add debug logs 2025-03-02 17:18:03 +01:00
Shreyas Goenka 0e300c6a40
lint 2025-03-02 17:06:24 +01:00
Shreyas Goenka 8213c4fa22
make wait script more robust 2025-03-02 16:48:01 +01:00
Shreyas Goenka f249a1ac3b
consolidate test configuration 2025-03-02 15:33:45 +01:00
Shreyas Goenka db4fc698ea
rename environment variables 2025-03-02 15:27:45 +01:00
Shreyas Goenka 7f7165158b
better retrying logic 2025-03-02 15:25:03 +01:00
Shreyas Goenka e500bcb456
remove the -f flag 2025-02-28 17:58:10 +01:00
Shreyas Goenka 476b8bbf21
address comments 2025-02-28 17:52:47 +01:00
Denis Bilenko 211ec62a70
acc: add Ignore setting to config (#2405)
Ignore output files using gitignore syntax.

## Changes
New Ignore setting in test.toml that will ignore specified files (syntax
is gitignore).

## Why

I'm using it in #2396 to ignore virtual env. It includes a lot of files.
The regular 'rm -fr .venv' approach only works if script get to that
point, but due to errors it might abort early. In that cases test runner
prints all unexpected files, polluting output. Ignoring those files at
test runner level ensure you never see them.

## Tests
Updated selftest/basic.
2025-02-28 14:23:50 +00:00
Shreyas Goenka eb2b18721d
lint 2025-02-28 12:57:12 +01:00
Shreyas Goenka c898aafbed
- 2025-02-28 12:55:03 +01:00
Shreyas Goenka 362a93b555
remove todo 2025-02-28 12:53:16 +01:00
Shreyas Goenka fec9c4efae
move wait_pid to python 2025-02-28 12:49:29 +01:00
Andrew Nester 6a07e05e9b
Raise an error when there are multiple local libraries with the same basename used (#2382)
## Changes
It could happen that there are multiple artifacts defined in the bundle
which build and therefore deploy wheel packages with the same name. This
leads to conflict between these packages, they will overwrite each other
and therefore they should have different names instead

Fixes https://github.com/databricks/cli/issues/1674

Previous attempt (https://github.com/databricks/cli/pull/2297 +
https://github.com/databricks/cli/pull/2341) led to the breakage, this
PR fixes both issues.

## Tests
Added acceptance test
2025-02-27 16:32:50 +00:00
shreyas-goenka bc299cafb8
Add warning when variable interpolation is used for auth fields (#2399)
## Changes
This PR adds a warning which gives users clear guidance when they try to
use variable interpolation for an auth field.

## Tests
Modify existing acceptance test.
2025-02-27 15:58:48 +00:00
shreyas-goenka eb57dbd844
Add warning when include is used in config files other than databricks.yml (#2389)
## Changes
Defining an include section in config files other than the main
`databricks.yml` file fails silently. With this PR users will get a
warning when they try this.

## Tests
Acceptance test.
2025-02-27 14:59:00 +00:00
shreyas-goenka bf2aded8e9
Recover from panic gracefully (#2353)
## Changes
This PR adds a recovery function for panics. This indicates to all users
running into a panic that it's a bug and they should report it to
Databricks.

## Tests
Manually and acceptance test.

Before:
```
.venv➜  cli git:(panic-r) ✗ ./cli selftest panic                                                
panic: the databricks selftest panic command always panics

goroutine 1 [running]:
github.com/databricks/cli/cmd/selftest.New.newPanic.func1(0x1400016f208?, {0x1016ca925?, 0x4?, 0x1016ca929?})
        /Users/shreyas.goenka/cli2/cli/cmd/selftest/panic.go:9 +0x2c
github.com/spf13/cobra.(*Command).execute(0x1400016f208, {0x10279bc40, 0x0, 0x0})
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:989 +0x81c
github.com/spf13/cobra.(*Command).ExecuteC(0x14000428908)
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:1050
github.com/databricks/cli/cmd/root.Execute({0x101d60440?, 0x10279bc40?}, 0x10266dd78?)
        /Users/shreyas.goenka/cli2/cli/cmd/root/root.go:101 +0x58
main.main()
        /Users/shreyas.goenka/cli2/cli/main.go:13 +0x44
```

After:
```
.venv➜  cli git:(panic-r) ./cli selftest panic
The Databricks CLI unexpectedly had a fatal error.
Please report this issue to Databricks in the form of a GitHub issue at:
https://github.com/databricks/cli

CLI Version: 0.0.0-dev+aae7ced52d36

Panic Payload: the databricks selftest panic command always panics

Stack Trace:
goroutine 1 [running]:
runtime/debug.Stack()
        /Users/shreyas.goenka/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.darwin-arm64/src/runtime/debug/stack.go:26 +0x64
github.com/databricks/cli/cmd/root.Execute.func1()
        /Users/shreyas.goenka/cli2/cli/cmd/root/root.go:110 +0xa4
panic({0x10368b5e0?, 0x1039d6d70?})
        /Users/shreyas.goenka/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.4.darwin-arm64/src/runtime/panic.go:785 +0x124
github.com/databricks/cli/cmd/selftest.New.newPanic.func1(0x14000145208?, {0x103356be5?, 0x4?, 0x103356be9?})
        /Users/shreyas.goenka/cli2/cli/cmd/selftest/panic.go:9 +0x2c
github.com/spf13/cobra.(*Command).execute(0x14000145208, {0x104427c40, 0x0, 0x0})
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:989 +0x81c
github.com/spf13/cobra.(*Command).ExecuteC(0x14000400c08)
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).ExecuteContextC(...)
        /Users/shreyas.goenka/cli2/cli/vendor/github.com/spf13/cobra/command.go:1050
github.com/databricks/cli/cmd/root.Execute({0x1039ec440?, 0x104427c40?}, 0x14000400c08)
        /Users/shreyas.goenka/cli2/cli/cmd/root/root.go:128 +0x94
main.main()
        /Users/shreyas.goenka/cli2/cli/main.go:13 +0x44
```
2025-02-27 13:27:36 +00:00
Shreyas Goenka da0e08d72c
log to stdout / stderr 2025-02-27 12:47:26 +01:00
Shreyas Goenka a407a5462d
fix test toml 2025-02-27 12:42:40 +01:00
Denis Bilenko e2db0cd0e2
Remove bundle.{Seq,If,Defer,newPhase,logString}, switch to regular functions (#2390)
## Changes
- Instead of constructing chains of mutators and then executing them,
execute them directly.
- Remove functionality related to chain-building: Seq, If, Defer,
newPhase, logString.
- Phases become functions that apply the changes directly rather than
construct mutator chains that will be called later.
- Add a helper ApplySeq to call multiple mutators, use it where
Apply+Seq were used before.

This is intended to be a refactoring without functional changes, but
there are a few behaviour changes:
- Since defer() is used to call unlock instead of bundle.Defer()
unlocking will now happen even in case of panics.
- In --debug, the phase names are are still logged once before start of
the phase but each entry no longer has 'seq' or phase name in it.
- The message "Deployment complete!" was printed even if
terraform.Apply() mutator had an error. It no longer does that.

## Motivation

The use of the chains was necessary when mutators were returning a list
of other mutators instead of calling them directly. But that has since
been removed, so now the chain machinery have no purpose anymore.

Use of direct functions simplifies the logic and makes bugs more
apparent and easy to fix.

Other improvements that this unlocks:
- Simpler stacktraces/debugging (breakpoints).
- Use of functions with narrowly scoped API: instead of mutators that
receive full bundle config, we can use focused functions that only deal
with sections they care about prepareGitSettings(currentGitSection) ->
updatedGitSection. This makes the data flow more apparent.
- Parallel computations across mutators (within phase): launch
goroutines fetching data from APIs at the beggining, process them once
they are ready.

## Tests
Existing tests.
2025-02-27 11:41:58 +00:00
Shreyas Goenka a556d51164
Merge remote-tracking branch 'origin' into async-logger-clean 2025-02-27 11:47:34 +01:00
Denis Bilenko 13ac52391d
acc: Include full output for default-python/classic (#2391)
## Tests
Include full output of default-python/classic so it can be used as a
base for diffs in cloud tests #2383
2025-02-27 10:16:06 +00:00
Denis Bilenko 81606cfcbc
acc: replace LocalOnly option with Local & Cloud (#2387)
## Changes
Instead of LocalOnly with non-composable semantics there are two
composable options:
- Local - enable test locally
- Cloud - enable test on the cloud

By default Cloud is switched off except in bundle (but not in
bundle/variables and bundle/help).

## Tests
Using this in #2383 to have test that runs on cloud but not locally.
2025-02-26 16:01:49 +00:00
Denis Bilenko 6d27c7e69d
acc: Support multiline patterns in diff.py (#2384)
## Changes
Fix diff.py to apply replacements that have newlines in them.

## Tests
Existing tests.
2025-02-26 14:25:39 +01:00
Denis Bilenko 03f2ff5a39
Support serverless mode in default-python template (explicit prompt) (#2377)
## Changes

- Add 'serverless' prompt to default-python template (default is
currently set to "no").
- This is a simplified version of
https://github.com/databricks/cli/pull/2348 with 'auto' functionality
removed.

## Tests
- Split default-python into default-python/classic,
default-python/serverless, default-python/serverless-customcatalog.
- Manually check that "bundle init default-python" with serverless=yes
can be deployed and run on dogfood and test env.
2025-02-26 14:07:30 +01:00
Andrew Nester df001dcdfe
Do not load host from bundle for CLI commands when profile flag is used (#2335)
## Changes
Now when `profile` flag is used we won't pick up host from bundle
anymore and use the one provided by -p flag

Previous behaviour in the context of bundle
```
databricks current-user me -p profile_name
Error: cannot resolve bundle auth configuration: config host mismatch: profile uses host https://non-existing-subdomain.databricks.com, but CLI configured to use https://foo.com
```

New behaviour (make an api call)
```
databricks current-user me -p profile_name
{
  email: "foo@bar.com"
  ...
}
```

We still load bundle configuration when `-t` flag provide because we
want to load host information from the target.

Fixes #1358 

## Tests
Added acceptance test
2025-02-26 12:30:38 +00:00
Anton Nekipelov 428e730c9e
Set default data_security_mode to "SINGLE_USER" in bundle templates (#2372)
## Changes
1. Change the **default-python** bundle template to set
`data_security_mode` of a cluster to SINGLE_USER
2. Change the **experimental-jobs-as-code** bundle template to set
`data_security_mode` of a cluster to SINGLE_USER

## Why
Explicitly adding this field saves experienced users from confusion onto
what security mode is applied to the cluster

## Tests
Changed existing unit and integration tests to pass with this change
2025-02-26 13:19:38 +01:00
Andrew Nester fa79d04980
acc: Added tests for deploying PyPi and Maven libraries (#2359)
## Changes
Added PyPi and Maven libraries tests

Needed for this PR since we don't currently have any coverage for PyPi
or Maven libraries
https://github.com/databricks/cli/pull/2382
2025-02-26 13:05:38 +01:00
Andrew Nester cdea775bd2
Fixed spark version check for clusters defined in the same bundle (#2374)
## Changes
Previously using python wheel tasks in the tasks with compute referering
to interactive cluster defied in the same bundle would produce a warning
like below

```
GET /api/2.1/clusters/get?cluster_id=${resources.clusters.development_cluster.id}
< HTTP/2.0 400 Bad Request
< {
<   "error_code": "INVALID_PARAMETER_VALUE",
<   "message": "Cluster ${resources.clusters.development_cluster.id} does not exist"
< } pid=14465 mutator=seq mutator=initialize mutator=seq mutator=PythonWrapperWarning sdk=true
```

This PR fixes it by making sure that we check spark version for such
clusters based on its bundle configuration and don't make API calls

## Tests
Added acceptance test
2025-02-26 13:04:45 +01:00
Andrew Nester 28e094c207
Fixed accessing required path parameters in CLI generation when --json flag (#2373)
## Changes
CLI generation template was using RequiredPathField from incorrect
request entity (body field from request and not request itself). Thus
for some of the commands required path parameters were not required when
--json was specified.

## Tests
Regenerated commands work correctly
2025-02-25 20:20:06 +00:00
Ilya Kuznetsov 25a701be92
Add missing `.gitignore` to dbt-sql and default-sql templates (#2356)
## Changes

Added missing .gitignore files to templates

## Tests

There were some incorrect snapshots of gitignore files in acceptance
tests, probably generated by testing infra. Updated them to new files

---------

Co-authored-by: Lennart Kats (databricks) <lennart.kats@databricks.com>
2025-02-25 09:42:02 +00:00
Denis Bilenko ccdbb1aeba
acc: fix override of settings with null values (#2369)
## Changes
Previously, one could not set `LocalOnly=true` in parent directory and
then override it with `LocalOnly=false` in child directory. This is
because, `false` is considered empty value by mergo.

In order to distinguish between 'explicitly set to false' and 'not set',
I've changed all simple variables in config to be pointers. Now, one can
always override those, because non-nil pointers are not null (with
mergo.WithoutDereference option).

## Tests
Manually:

```
~/work/cli/acceptance/bundle/templates/default-python % cat test.toml   # add this new file 
LocalOnly = false

~/work/cli/acceptance/bundle/templates/default-python % CLOUD_ENV=aws go test ../../.. -run ^TestAccept$/^bundle$/^templates$/^default-python$ -v
(the test is no longer skipped)
```
2025-02-25 08:53:46 +00:00
Shreyas Goenka 33a7f7151e
- 2025-02-24 18:31:43 +01:00