Commit Graph

1584 Commits

Author SHA1 Message Date
Shreyas Goenka 24be18a2c7
merge 2025-01-24 14:25:53 +01:00
Shreyas Goenka 2952a73461
rm fn 2025-01-24 14:22:55 +01:00
Shreyas Goenka fffc89c6d5
- 2025-01-24 14:22:11 +01:00
Shreyas Goenka accec7118c
remove request bits 2025-01-24 14:17:56 +01:00
Shreyas Goenka 0d14526098
move server to libs 2025-01-24 14:05:37 +01:00
Shreyas Goenka e22b015434
wip finer grained server regex 2025-01-24 14:03:15 +01:00
shreyas-goenka a47a058506
Limit test server to only accept GET on read endpoints (#2225)
## Changes
Now the test server will only match GET queries for these endpoints

## Tests
Existing tests.
2025-01-24 11:05:00 +00:00
Shreyas Goenka 09791fc16a
decouple changes 2025-01-24 12:03:11 +01:00
Denis Bilenko b4ed235104
Include EvalSymlinks in SetPath and use SetPath on all paths (#2219)
## Changes
When adding path, a few things should take care of:
- symlink expansion
- forward/backward slashes, so that tests could do sed 's/\\\\/\//g' to
make it pass on Windows (see
acceptance/bundle/syncroot/dotdot-git/script)

SetPath() function takes care of both.

This PR uses SetPath() on all paths consistently.

## Tests
Existing tests.
2025-01-24 10:18:44 +00:00
Denis Bilenko d6d9b994d4
acc: only print non-zero exit codes in errcode function (#2222)
Reduce noise in the output and matches how "Exit code" is handled for
the whole script.
2025-01-24 10:47:12 +01:00
Shreyas Goenka de326bf933
- 2025-01-23 20:13:16 +01:00
Shreyas Goenka d9685ab33c
add unit tests 2025-01-23 20:08:01 +01:00
Shreyas Goenka 6b8e1dfff2
- 2025-01-23 20:05:59 +01:00
Shreyas Goenka 07e1ba2211
- 2025-01-23 20:05:23 +01:00
Shreyas Goenka 2bcf43b761
- 2025-01-23 20:01:41 +01:00
Shreyas Goenka 07c25584d3
Add support for mocking servers in acceptance tests 2025-01-23 19:56:58 +01:00
Andrew Nester d784147e99
[Release] Release v0.239.1 (#2218)
CLI:
* Added text output templates for apps list and list-deployments
([#2175](https://github.com/databricks/cli/pull/2175)).
* Fix duplicate "apps" entry in help output
([#2191](https://github.com/databricks/cli/pull/2191)).

Bundles:
* Allow yaml-anchors in schema
([#2200](https://github.com/databricks/cli/pull/2200)).
* Show an error when non-yaml files used in include section
([#2201](https://github.com/databricks/cli/pull/2201)).
* Set WorktreeRoot to sync root outside git repo
([#2197](https://github.com/databricks/cli/pull/2197)).
* fix: Detailed message for using source-linked deployment with
file_path specified
([#2119](https://github.com/databricks/cli/pull/2119)).
* Allow using variables in enum fields
([#2199](https://github.com/databricks/cli/pull/2199)).
* Add experimental-jobs-as-code template
([#2177](https://github.com/databricks/cli/pull/2177)).
* Reading variables from file
([#2171](https://github.com/databricks/cli/pull/2171)).
* Fixed an apps message order and added output test
([#2174](https://github.com/databricks/cli/pull/2174)).
* Default to forward slash-separated paths for path translation
([#2145](https://github.com/databricks/cli/pull/2145)).
* Include a materialized copy of built-in templates
([#2146](https://github.com/databricks/cli/pull/2146)).
2025-01-23 15:54:55 +00:00
Ilya Kuznetsov 0487e816cc
Reading variables from file (#2171)
## Changes

New source of default values for variables - variable file
`.databricks/bundle/<target>/variable-overrides.json`

CLI tries to stat and read that file every time during variable
initialisation phase

<!-- Summary of your changes that are easy to understand -->

## Tests

Acceptance tests
2025-01-23 14:35:33 +00:00
Andrew Nester 8af9efaa62
Show an error when non-yaml files used in include section (#2201)
## Changes
`include` section is used only to include other bundle configuration
YAML files. If any other file type is used, raise an error and guide
users to use `sync.include` instead

## Tests
Added acceptance test

---------

Co-authored-by: Julia Crawford (Databricks) <julia.crawford@databricks.com>
2025-01-23 13:58:18 +00:00
Andrew Nester 6153423c56
Revert "Upgrade Go SDK to 0.56.0 (#2214)" (#2217)
This reverts commit 798189eb96.
2025-01-23 13:21:59 +00:00
Denis Bilenko ddd45e25ee
Pass USE_SDK_V2_{RESOURCES,DATA_SOURCES} to terraform (#2207)
## Changes
- Propagate env vars USE_SDK_V2_RESOURCES and $USE_SDK_V2_DATA_SOURCES
to terraform
- This are troubleshooting helpers for resources migrated to new plugin
framework, recommended here:
https://registry.terraform.io/providers/databricks/databricks/latest/docs/guides/troubleshooting#plugin-framework-migration-problems
- This current unblocks deploying quality monitors, see
https://github.com/databricks/terraform-provider-databricks/issues/4229#issuecomment-2520344690

## Tests
Manually testing that I can deploy quality monitor after this change
with `USE_SDK_V2_RESOURCES="databricks_quality_monitor"` set

### Main branch:
```
~/work/databricks_quality_monitor_repro % USE_SDK_V2_RESOURCES="databricks_quality_monitor" ../cli/cli-main bundle deploy
Uploading bundle files to /Workspace/Users/denis.bilenko@databricks.com/.bundle/quality_monitor_bundle/default/files...
Deploying resources...
Updating deployment state...
Deployment complete!
Error: terraform apply: exit status 1

Error: Provider produced inconsistent result after apply

When applying changes to databricks_quality_monitor.monitor_trips, provider
"provider[\"registry.terraform.io/databricks/databricks\"]" produced an
unexpected new value: .data_classification_config: block count changed from 0
to 1.

This is a bug in the provider, which should be reported in the provider's own
issue tracker.
```

### This branch:
```
~/work/databricks_quality_monitor_repro % USE_SDK_V2_RESOURCES="databricks_quality_monitor" ../cli/cli bundle deploy
Uploading bundle files to /Workspace/Users/denis.bilenko@databricks.com/.bundle/quality_monitor_bundle/default/files...
Deploying resources...
Updating deployment state...
Deployment complete!
```

### Config:
```
~/work/databricks_quality_monitor_repro % cat databricks.yml
bundle:
  name: quality_monitor_bundle

resources:
  quality_monitors:
    monitor_trips:
      table_name: main.denis-bilenko-cuj-pe34.trips_sanitized_1
      output_schema_name: main.denis-bilenko-cuj-pe34
      assets_dir: /Workspace/Users/${workspace.current_user.userName}/quality_monitor_issue
      snapshot: {}
```
2025-01-23 12:48:47 +00:00
Denis Bilenko 1f63aa0912
tests: Improve reporting in case of FS errors (#2216)
## Changes
If there are unreadable files in a directory, raise an error but
continue with further diagnostics, because the answer is in the script
output.

## Tests
Manually - I'm working on some tests that create unreadable files, the
report is much better with this change.
2025-01-23 11:46:22 +00:00
Andrew Nester 798189eb96
Upgrade Go SDK to 0.56.0 (#2214)
## Changes

Upgrade Go SDK to 0.56.0

Relevant changes:
- Support Query parameters for all HTTP operations
(https://github.com/databricks/databricks-sdk-go/pull/1124).
2025-01-23 11:17:52 +00:00
Ilya Kuznetsov f60ad32f07
Allow yaml-anchors in schema (#2200)
## Changes

Allows custom untyped fields in the root config in json-schema so it
doesn't highlight errors when using yaml-anchors.

Example use case:

```
tags: &job-tags
  environment: ${bundle.target}


resources:
  jobs:
    db1:
      tags:
        <<: *job-tags
    db1:
      tags:
        <<: *job-tags
```
  
One downside is that we don't highlight any unknown top-level properties
anymore (but they will still fail during CLI validation)

## Tests

Manually checked behavior in VSCode - it doesn't show validation error.
Also checked that other typed properties are still suggested
2025-01-23 11:11:44 +00:00
Denis Bilenko ba3a400327
Remove test-specific logic from generic test runner (#2215)
Revert changes to acceptance_test.go added in #2177 and add
test-specific fix.
2025-01-23 11:59:01 +01:00
Denis Bilenko 20c1902a45
Fix passing SingleTest to TestAccept (#2210) 2025-01-22 16:26:16 +00:00
Gleb Kanterov 3d91691f25
PythonMutator: propagate source locations (#1783)
## Changes
Add a mechanism to load Python source locations in the Python mutator.
Previously, locations pointed to generated YAML. Now, they point to
Python sources instead. Python process outputs "locations.json"
containing locations of bundle paths, examples:

```json
{"path": "resources.jobs.job_0", "file": "resources/job_0.py", "line": 3, "column": 5}
{"path": "resources.jobs.job_0.tasks[0].task_key", "file": "resources/job_0.py", "line": 10, "column": 5}
{"path": "resources.jobs.job_1", "file": "resources/job_1.py", "line": 5, "column": 7}
```

Such locations form a tree, and we assign locations of the closest
ancestor to each `dyn.Value` based on its path. For example,
`resources.jobs.job_0.tasks[0].task_key` is located at `job_0.py:10:5`
and `resources.jobs.job_0.tasks[0].email_notifications` is located at
`job_0.py:3:5`, because we use the location of the job as the most
precise approximation.

This feature is only enabled if `experimental/python` is used.

Note: for now, we don't update locations with relative paths, because it
has a side effect in changing how these paths are resolved

## Example
```
% databricks bundle validate

Warning: job_cluster_key abc is not defined
  at resources.jobs.examples.tasks[0].job_cluster_key
  in resources/example.py:10:1
```

## Tests
Unit tests and manually
2025-01-22 15:37:37 +00:00
Denis Bilenko 54a470837c
Fix context propagation in bundle/deploy/terraform (#2208)
https://github.com/databricks/cli/pull/747#discussion_r1925248116
2025-01-22 13:28:13 +00:00
Denis Bilenko 667302b61b
Refactor env forwarding function in terraform (#2206)
No functional changes, just making it easier to add variables.
2025-01-22 12:51:17 +00:00
shreyas-goenka 6c3ddbd921
Add `auth.Env` function (#2204)
## Changes
`auth.Env` is a generic function that we can use for authenticated tools
downstream to the CLI.

## Tests
Unit test.
2025-01-22 12:14:54 +00:00
Denis Bilenko 876526a19a
Use local git config in tests (#2205)
I've seen this error: could not lock config file
$TMPDIR_GPARENT/TestAccept3968313522/002/.gitconfig: File exists

This is likely the cause.
2025-01-22 12:20:49 +01:00
Denis Bilenko e9902036b8
Set WorktreeRoot to sync root outside git repo (#2197)
## Changes
If git is not detected, set default worktree root to sync root.
Otherwise NewFileSet/View raise an error about worktree root being
outside view root in acceptance/bundle/sync-paths-dotdot.

This behavior is introduced in
https://github.com/databricks/cli/pull/1945

Stacked on https://github.com/databricks/cli/pull/2202

## Tests
Existing tests.
2025-01-22 10:50:13 +00:00
Ilya Kuznetsov c224be5c1f
Allow using variables in enum fields (#2199)
## Changes

It is possible to pass variable to enum fields but json-schema doesn't
accept it. This PR adds `oneOf` for enum types that includes `${var-*}`
pattern

## Tests

Manually checked in VSCode
2025-01-22 10:30:17 +00:00
Denis Bilenko fde30ff1ab
Add a test for sync root outside of git root (#2202)
- Move acceptance/bundle/sync-paths-dotdot test to
acceptance/bundle/syncroot/dotdot-notgit
- Add new test acceptance/bundle/syncroot/dotdot-git

Fix replacer to work with this test and on Windows:
- Make PATH work on Windows by using EvalSymlinks.
- Make concatenated path match within JSON but stripping quotes.
2025-01-22 10:17:45 +00:00
Denis Bilenko 3a32c63919
Add -inprocess mode for acceptance tests (#2184)
## Changes
- If you pass -inprocess flag to acceptance tests, they will run in the
same process as test itself. This enables debugging.
- If you set singleTest variable on top of acceptance_test.go, you'll
only run that test and with inprocess mode. This is intended for
debugging in VSCode.
- (minor) Converted KeepTmp to flag -keeptmp from env var KEEP_TMP for
consistency with other flags.

## Tests
- I verified that acceptance tests pass with -inprocess mode: `go test
-inprocess < /dev/null | cat`
- I verified that debugging in VSCode works: set a test name in
singleTest variable, set breakpoints inside CLI and click "debug test"
in VSCode.
2025-01-21 21:21:12 +00:00
Denis Bilenko 34a37cf4a8
Clone ReplacementContext before passing into test (#2198)
## Changes
- Add a new method Clone() on ReplacementContext
- Use it when passing common replacements to test cases.

## Tests
Manually. I have a different branch where this bug manifested and this
change helped.
2025-01-21 12:47:34 +00:00
Denis Bilenko de5155ed0a
Add acceptance for test for sync.paths equal to two dots (#2196)
Based on integration test from @andrewnester in #2194

Manually checked that this databricks.yml passes validation on v0.235.0
but fails on v0.236.0, very like it was broken in
https://github.com/databricks/cli/pull/1945

This also adds replacements for tmpdir, it's parent and (just in case)
grand parent.
2025-01-21 11:50:28 +00:00
Denis Bilenko 33613b5d2a
Add test for #2181 /Workspace not prepended (#2188) 2025-01-21 11:27:02 +00:00
Denis Bilenko 41bbd89257
Clean up unnecessary cleanup of inferred flag (#2193)
## Changes
The SelectTarget mutator (part of Load phase) clears bundle.git.inferred
flag but it is not set until later - Initialize phase / LoadGitDetails
mutator.

## Tests
Existing tests.
2025-01-20 17:21:34 +00:00
Denis Bilenko ee4a4b4c24
Migrate quality_monitor_test.go to acceptance test (#2192) 2025-01-20 16:33:03 +00:00
Ilya Kuznetsov 84a73052d2
fix: Detailed message for using source-linked deployment with file_path specified (#2119)
## Changes

Resolves remaining comments from here
https://github.com/databricks/cli/pull/2046


[This](https://github.com/databricks/cli/pull/2046#discussion_r1907121844)
and
[this](https://github.com/databricks/cli/pull/2046#discussion_r1908928239)
are on hold until Pieter's response

## Tests
<!-- How is this tested? -->
2025-01-20 16:16:51 +00:00
Pieter Noordhuis 69f3c0a869
Fix duplicate "apps" entry in help output (#2191)
## Changes

This is not needed because the command group is already returned by
`workspace.All()`.

The additional command registration was added in #1679.

## Tests

Acceptance test.
2025-01-20 16:02:29 +00:00
Denis Bilenko 395a04a8d1
Run tests with coverage on CI (#2141)
Combine 'make cover' and 'make acc-cover' into single command. They
still write coverage into different files -- it would be useful to see
separate coverage numbers.

Note, we're not making use of coverage information yet. However, running
tests in CI with coverage will
- let us catch issues that only manifest when coverage is enabled, like
https://github.com/databricks/cli/pull/2150
- will let us know if there are any issues with running coverage on CI
before investing in additional coverage support
2025-01-20 15:41:24 +00:00
shreyas-goenka e6982d09ac
Add doc string for `bundle.uuid` (#2170)
Co-authored-by: Julia Crawford (Databricks) <julia.crawford@databricks.com>
2025-01-20 14:52:22 +00:00
shreyas-goenka 41a21af556
Refactor `bundle init` (#2074)
## Summary of changes
This PR introduces three new abstractions: 
1. `Resolver`: Resolves which reader and writer to use for a template.
2. `Writer`: Writes a template project to disk. Prompts the user if
necessary.
3. `Reader`: Reads a template specification from disk, built into the
CLI or from GitHub.

Introducing these abstractions helps decouple reading a template from
writing it. When I tried adding telemetry for the `bundle init` command,
I noticed that the code in `cmd/init.go` was getting convoluted and hard
to test. A future change could have accidentally logged PII when a user
initialised a custom template.

Hedging against that risk is important here because we use a generic
untyped `map<string, string>` representation in the backend to log
telemetry for the `databricks bundle init`. Otherwise, we risk
accidentally breaking our compliance with our centralization
requirements.

### Details

After this PR there are two classes of templates that can be
initialized:
1. A `databricks` template: This could be a builtin template or a
template outside the CLI like mlops-stacks, which is still owned and
managed by Databricks. These templates log their telemetry arguments and
template name.
2. A `custom` template: These are templates created by and managed by
the end user. In these templates we do not log the template name and
args. Instead a generic placeholder string of "custom" is logged in our
telemetry system.

NOTE: The functionality of the `databricks bundle init` command remains
the same after this PR. Only the internal abstractions used are changed.

## Tests
New unit tests. Existing golden and unit tests. Also a fair bit of
manual testing.
2025-01-20 12:09:28 +00:00
Gleb Kanterov 31c10c1b82
Add experimental-jobs-as-code template (#2177)
## Changes

Add experimental-jobs-as-code template allowing defining jobs using
Python instead of YAML through the `databricks-bundles` PyPI package.

## Tests

Manually and acceptance tests.
2025-01-20 10:15:11 +00:00
Denis Bilenko 7034793d1d
Run 'ruff format' in quiet mode (#2187)
Otherwise it prints "83 files left unchanged".
2025-01-20 10:26:29 +01:00
Denis Bilenko 64fc1c8fe7
Add NoLog option on testcli.Runner (#2183)
## Changes
Setting Verbose=false on testcli.Runner disables all logging related to
running process (stdout, stderr, error, args).

I'm using this in #2184 where I'm using testcli runner to run acceptance
tests and seeing all output is not useful.

## Tests
Manually inspecting test output in #2184
2025-01-20 09:57:48 +01:00
Denis Bilenko 26f527ef64
Fix incorrect TestingT.Errorf usage and enable linting for this (#2182)
## Changes
- Fix incorrect use Errorf on literal string. This resulted in garbage
output in tests diagnostics where % was replaced by "(MISSING)".
- Enable linter on testingT.Errorf.

Note, the autofix by the linter is wrong, it proposes `t.Errorf("%s",
string)` but it should be `t.Error(string)`. That can corrected manually
though.

## Tests
Linter was tested manually by reverting the fix on Errorf.
2025-01-20 08:07:42 +00:00
Pieter Noordhuis 50f62692ce
Include a materialized copy of built-in templates (#2146)
## Changes

Include a materialized copy of built-in templates as reference output.

This updates the output comparison logic to work against an output
directory. The `doComparison` function now always works on real files.
It can now tell apart non-existing files and empty files (e.g., the
`.gitkeep` files in templates).
2025-01-17 15:03:59 +00:00