Commit Graph

485 Commits

Author SHA1 Message Date
Shreyas Goenka a5bbd1f4f4
fix tests 2025-03-06 14:39:19 +01:00
Shreyas Goenka d1ec239dda
merge 2025-03-06 14:32:43 +01:00
Shreyas Goenka aa4e231731
update acceptance tests 2025-03-06 14:31:13 +01:00
Shreyas Goenka 5b058e0b09
- 2025-03-06 14:14:16 +01:00
shreyas-goenka 897741f55a
Store DBR version in context (#2438)
## Changes
This PR also starts storing the DBR versions in the context.

Go patch file used:
```
@@
var x expression
@@
-dbr.MockRuntime(x, true)
+dbr.MockRuntime(x, dbr.Environment{IsDbr: true, Version: "15.4"})

@@
var x expression
@@
-dbr.MockRuntime(x, false)
+dbr.MockRuntime(x, dbr.Environment{})
```

ref: https://github.com/uber-go/gopatch

## Why
This localised all DBR version accesses to `libs/dbr`. Relevant comment:
https://github.com/databricks/cli/pull/2432#discussion_r1982878616

## Tests
Exiting tests are modified.
2025-03-06 13:01:43 +00:00
Shreyas Goenka 3811d24e58
make upload and wait times a constant 2025-03-06 11:36:21 +01:00
Denis Bilenko edf37e7d0d
Add libs/patchwheel: insert dynamic version in whl (#2427)
## Changes
- New library to patch existing whl with dynamic version. The version is
based on mtime of original wheel.
- New hidden command "selftest patchwhl" (for acceptance test).

## Why
Part of the project to deprecate dynamic version in setup.py template
(#1034). This would enable switching default-python to pyproject.toml
without dependency on setuptools-specific sections.

The dynamic version is needed to ensure that wheels are picked up by the
users code when doing development.

## Tests
- New unit tests that use uv to create envs on various versions and
install (and re-install) patched wheels there.
- New acceptance test that patches prebuilt whl and records the result
fully unzipped.
- New acceptance test helper setmtime.py to set mtime with nanosecond
precision cross-platform.
2025-03-06 10:28:30 +00:00
Shreyas Goenka 0ac9a2aa97
remove 503 detection 2025-03-06 11:04:52 +01:00
Shreyas Goenka 709e8c54d2
Merge remote-tracking branch 'origin' into sync-logger 2025-03-05 16:29:35 +01:00
Shreyas Goenka 9774046825
some cleanup 2025-03-05 16:27:26 +01:00
Shreyas Goenka d80a5ec673
debug logs everywhere 2025-03-05 16:21:14 +01:00
Shreyas Goenka f227862d89
- 2025-03-05 16:09:33 +01:00
Shreyas Goenka a652b449cb
- 2025-03-05 16:00:28 +01:00
Shreyas Goenka a2825ca89a
add acceptance tests 2025-03-05 15:57:41 +01:00
Shreyas Goenka b3a479ce73
add sync logger 2025-03-05 15:21:12 +01:00
shreyas-goenka a24a7f5738
Remove omitempty tag for exit code and execution time in telemetry (#2433) 2025-03-05 14:20:59 +00:00
Pieter Noordhuis 6ae353d84b
Use schema field for pipeline in builtin template (#2347)
## Changes

The `schema` field implies the lifecycle of tables is no longer tied to
the lifecycle of the pipeline, as was the case with the `target` field.

More information about using the "catalog" and "schema" properties can
be found here:
https://docs.databricks.com/en/delta-live-tables/target-schema.html

## Tests

n/a

---------

Co-authored-by: Lennart Kats (databricks) <lennart.kats@databricks.com>
2025-03-05 14:19:33 +00:00
Shreyas Goenka f6592d9bbd
Add synchronous logger for telemetry 2025-03-05 14:54:30 +01:00
Russell Clarey 3a3076d9ea
Output deprecated annotations in the JSON schema (#2422)
## Changes
Start outputting `deprecated` and `deprecationMessage` annotations in
the JSON schema

## Why
So that deprecated fields are shown as deprecated in VSCode (and other
editors)

## Tests
- manually tested

||||
|---|---|---|
|<img width="682" alt="Screenshot 2025-03-03 at 16 04 21"
src="https://github.com/user-attachments/assets/9712aa2f-0f41-48a9-8bd0-ec92b8b75c3f"
/>|<img width="682" alt="Screenshot 2025-03-03 at 16 04 29"
src="https://github.com/user-attachments/assets/a14f3523-ad85-4fed-96d7-2a8cf3a458e5"
/>|<img width="682" alt="Screenshot 2025-03-03 at 16 06 03"
src="https://github.com/user-attachments/assets/b9ab1050-048e-4c14-b183-96d615a4fbc1"
/>|
2025-03-05 11:17:03 +00: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 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
shreyas-goenka 549b226cbc
Add the `auth.ProcessEnv` function (#2404)
## Changes
This function provides all environment variables necessary to
authenticate the downstream applications to the same credentials as the
parent process.

It's used in https://github.com/databricks/cli/pull/2278 and will also
be useful for the `databricks bundle exec` command.

## Tests
Unit test.
2025-03-04 14:47:11 +00:00
shreyas-goenka 807a37b36a
Add the `auth.EnvVars` function (#2403)
## Changes
This PR adds the auth.EnvVars function, which is a list of all
environment variables that the SDK uses to read auth configuration.

This is useful for spawning subprocesses since you can unset all auth
environment variables to clean up the environment before configuring the
auth.

It's used in #2278 today and will also be useful for the `databricks
bundle exec` command.
 
## Tests
Unit test.
2025-03-03 14:58:43 +00:00
Denis Bilenko 5c146ca57a
Synchronize logging in cmdio (#2418)
## Changes
Add mutex synchronization in cmdio logger Log() method.

## Why

Since we issue multiple calls to underlying writer, we should lock the
whole method, otherwise we can get broken messages. One that can be
easily reproduced today is

```
 hyperfine -m 100 --show-output 'go test ./acceptance -run ^TestAccept$/^bundle$/^artifacts$/^whl_multiple$ -count=1'
...
            -Uploading my_test_code-0.0.1-py3-none-any.whl...
            -Uploading my_test_code_2-0.0.1-py3-none-any.whl...
            +Uploading my_test_code-0.0.1-py3-none-any.whl...Uploading my_test_code_2-0.0.1-py3-none-any.whl...

Error: Command terminated with non-zero exit code 1 in benchmark iteration 54. Use the '-i'/'--ignore-failure' option if you want to ignore this. Alternatively, use the '--show-output' option to debug what went wrong.
```

An alternative could be to prepare a message fully in a local buffer and
write it in one call (I’m assuming underlying writer is still
synchronized). However, that’s more complicated and unclear if it’s
worth it, perf-wise.

## Tests
With this change I’m running the same hyperfine command with 1000
iterations with no failures.
2025-03-03 13:42:43 +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
Denis Bilenko c1f835f951
acc: Print full URL and request body for missing handlers (#2394)
## Tests
Manually, I have a test that fails.

Before:

```
=== NAME  TestAccept
    server.go:195:

        ----------------------------------------
        No stub found for pattern: GET /api/2.1/clusters/get

        To stub a response for this request, you can add
        the following to test.toml:
        [[Server]]
        Pattern = "GET /api/2.1/clusters/get"
        Response.Body = '''
        <response body here>
        '''
        Response.StatusCode = <response status-code here>
        ----------------------------------------
```

After:
```
    server.go:203: No handler for URL: /api/2.1/clusters/get?cluster_id=0717-132531-5opeqon1
        Body: [0 bytes]

        For acceptance tests, add this to test.toml:
        [[Server]]
        Pattern = "GET /api/2.1/clusters/get"
        Response.Body = '<response body here>'
        # Response.StatusCode = <response code if not 200>
```
2025-02-27 13:07:48 +00: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
Denis Bilenko b6bf035e7f
Skip serverless prompt in default-python (default is no) (#2388)
## Tests
Manually running 'bundle init default-python' - no question about
serverless.
2025-02-26 15:58:53 +00:00
Denis Bilenko ab3d82e32e
default-python: Swap order of yes/no in serverless template (#2386)
## Changes
Since at this moment we set default to 'no', interactively it should
also default to 'no'. However, it just uses the first option.

## Tests
Manually running `cli bundle init default-python`
2025-02-26 14:45:32 +00: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
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
shreyas-goenka 9659f91c9f
Do not pass parent pid to child daemon process (#2376)
## Changes
This PR:
1. No longer sets the `DATABRICKS_CLI_PARENT_PID` environment variable
since it was never required in the first place and was mistakenly merged
in the inital PR.
2. Performs minor cleanup based on post merge feedback in
https://github.com/databricks/cli/pull/2354.

## Tests
N/A
2025-02-26 17:39:45 +05:30
dependabot[bot] 9bacf221d7
build(deps): bump github.com/spf13/cobra from 1.8.1 to 1.9.1 (#2358)
Bumps [github.com/spf13/cobra](https://github.com/spf13/cobra) from
1.8.1 to 1.9.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/spf13/cobra/releases">github.com/spf13/cobra's
releases</a>.</em></p>
<blockquote>
<h2>v1.9.1</h2>
<h3>🐛 Fixes</h3>
<ul>
<li>Fix CompletionFunc implementation by <a
href="https://github.com/ccoVeille"><code>@​ccoVeille</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2234">spf13/cobra#2234</a></li>
<li>Revert &quot;Make detection for test-binary more universal (<a
href="https://redirect.github.com/spf13/cobra/issues/2173">#2173</a>)&quot;
by <a
href="https://github.com/marckhouzam"><code>@​marckhouzam</code></a> in
<a
href="https://redirect.github.com/spf13/cobra/pull/2235">spf13/cobra#2235</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/spf13/cobra/compare/v1.9.0...v1.9.1">https://github.com/spf13/cobra/compare/v1.9.0...v1.9.1</a></p>
<h2>v1.9.0</h2>
<h2> Features</h2>
<ul>
<li>Allow linker to perform deadcode elimination for program using Cobra
by <a href="https://github.com/aarzilli"><code>@​aarzilli</code></a> in
<a
href="https://redirect.github.com/spf13/cobra/pull/1956">spf13/cobra#1956</a></li>
<li>Add default completion command even if there are no other
sub-commands by <a
href="https://github.com/marckhouzam"><code>@​marckhouzam</code></a> in
<a
href="https://redirect.github.com/spf13/cobra/pull/1559">spf13/cobra#1559</a></li>
<li>Add CompletionWithDesc helper by <a
href="https://github.com/ccoVeille"><code>@​ccoVeille</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2231">spf13/cobra#2231</a></li>
</ul>
<h2>🐛 Fixes</h2>
<ul>
<li>Fix deprecation comment for Command.SetOutput by <a
href="https://github.com/thaJeztah"><code>@​thaJeztah</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2172">spf13/cobra#2172</a></li>
<li>Replace deprecated ioutil usage by <a
href="https://github.com/nirs"><code>@​nirs</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2181">spf13/cobra#2181</a></li>
<li>Fix --version help and output for plugins by <a
href="https://github.com/nirs"><code>@​nirs</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2180">spf13/cobra#2180</a></li>
<li>Allow to reset the templates to the default by <a
href="https://github.com/marckhouzam"><code>@​marckhouzam</code></a> in
<a
href="https://redirect.github.com/spf13/cobra/pull/2229">spf13/cobra#2229</a></li>
</ul>
<h2>🤖 Completions</h2>
<ul>
<li>Make Powershell completion work in constrained mode by <a
href="https://github.com/lstemplinger"><code>@​lstemplinger</code></a>
in <a
href="https://redirect.github.com/spf13/cobra/pull/2196">spf13/cobra#2196</a></li>
<li>Improve detection for flags that accept multiple values by <a
href="https://github.com/thaJeztah"><code>@​thaJeztah</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2210">spf13/cobra#2210</a></li>
<li>add CompletionFunc type to help with completions by <a
href="https://github.com/ccoVeille"><code>@​ccoVeille</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2220">spf13/cobra#2220</a></li>
<li>Add similar whitespace escape logic to bash v2 completions than in
other completions by <a
href="https://github.com/kangasta"><code>@​kangasta</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/1743">spf13/cobra#1743</a></li>
<li>Print ActiveHelp for bash along other completions by <a
href="https://github.com/marckhouzam"><code>@​marckhouzam</code></a> in
<a
href="https://redirect.github.com/spf13/cobra/pull/2076">spf13/cobra#2076</a></li>
<li>fix(completions): Complete map flags multiple times by <a
href="https://github.com/gabe565"><code>@​gabe565</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2174">spf13/cobra#2174</a></li>
<li>fix(bash): nounset unbound file filter variable on empty extension
by <a href="https://github.com/scop"><code>@​scop</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2228">spf13/cobra#2228</a></li>
</ul>
<h2>🧪 Testing</h2>
<ul>
<li>Test also with go 1.23 by <a
href="https://github.com/nirs"><code>@​nirs</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2182">spf13/cobra#2182</a></li>
<li>Make detection for test-binary more universal by <a
href="https://github.com/thaJeztah"><code>@​thaJeztah</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2173">spf13/cobra#2173</a></li>
</ul>
<h2>✍🏼 Documentation</h2>
<ul>
<li>docs: update README.md by <a
href="https://github.com/eltociear"><code>@​eltociear</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2197">spf13/cobra#2197</a></li>
<li>Improve site formatting by <a
href="https://github.com/nirs"><code>@​nirs</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2183">spf13/cobra#2183</a></li>
<li>doc: add Conduit by <a
href="https://github.com/raulb"><code>@​raulb</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2230">spf13/cobra#2230</a></li>
<li>doc: azion project added to the list of CLIs that use cobra by <a
href="https://github.com/maxwelbm"><code>@​maxwelbm</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2198">spf13/cobra#2198</a></li>
<li>Fix broken links in active_help.md by <a
href="https://github.com/vuil"><code>@​vuil</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2202">spf13/cobra#2202</a></li>
<li>chore: fix function name in comment by <a
href="https://github.com/zhuhaicity"><code>@​zhuhaicity</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2216">spf13/cobra#2216</a></li>
</ul>
<h2>🔧 Dependency upgrades</h2>
<ul>
<li>build(deps): bump github.com/cpuguy83/go-md2man/v2 from 2.0.5 to
2.0.6 by <a
href="https://github.com/thaJeztah"><code>@​thaJeztah</code></a> in <a
href="https://redirect.github.com/spf13/cobra/pull/2206">spf13/cobra#2206</a></li>
<li>Update to latest go-md2man by <a
href="https://github.com/mikelolasagasti"><code>@​mikelolasagasti</code></a>
in <a
href="https://redirect.github.com/spf13/cobra/pull/2201">spf13/cobra#2201</a></li>
</ul>
<!-- raw HTML omitted -->
</blockquote>
<p>... (truncated)</p>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="40b5bc1437"><code>40b5bc1</code></a>
Revert &quot;Make detection for test-binary more universal (<a
href="https://redirect.github.com/spf13/cobra/issues/2173">#2173</a>)&quot;
(<a
href="https://redirect.github.com/spf13/cobra/issues/2235">#2235</a>)</li>
<li><a
href="a97f9fd47b"><code>a97f9fd</code></a>
fix CompletionFunc implementation (<a
href="https://redirect.github.com/spf13/cobra/issues/2234">#2234</a>)</li>
<li><a
href="5f9c40898e"><code>5f9c408</code></a>
chore: Upgrade dependencies for v1.9.0 (<a
href="https://redirect.github.com/spf13/cobra/issues/2233">#2233</a>)</li>
<li><a
href="24ada7fe71"><code>24ada7f</code></a>
Remove the default &quot;completion&quot; cmd if it is alone (<a
href="https://redirect.github.com/spf13/cobra/issues/1559">#1559</a>)</li>
<li><a
href="680936a220"><code>680936a</code></a>
New logo</li>
<li><a
href="8cb30f9ca5"><code>8cb30f9</code></a>
feat: add CompletionWithDesc helper (<a
href="https://redirect.github.com/spf13/cobra/issues/2231">#2231</a>)</li>
<li><a
href="17b6dca2ff"><code>17b6dca</code></a>
doc: add Conduit (<a
href="https://redirect.github.com/spf13/cobra/issues/2230">#2230</a>)</li>
<li><a
href="ab5cadcc1b"><code>ab5cadc</code></a>
Allow to reset the templates to the default (<a
href="https://redirect.github.com/spf13/cobra/issues/2229">#2229</a>)</li>
<li><a
href="4ba5566f57"><code>4ba5566</code></a>
fix(bash): nounset unbound file filter variable on empty extension (<a
href="https://redirect.github.com/spf13/cobra/issues/2228">#2228</a>)</li>
<li><a
href="41b26ec8bb"><code>41b26ec</code></a>
Print ActiveHelp for bash along other completions (<a
href="https://redirect.github.com/spf13/cobra/issues/2076">#2076</a>)</li>
<li>Additional commits viewable in <a
href="https://github.com/spf13/cobra/compare/v1.8.1...v1.9.1">compare
view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=github.com/spf13/cobra&package-manager=go_modules&previous-version=1.8.1&new-version=1.9.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Andrew Nester <andrew.nester@databricks.com>
2025-02-25 20:26:11 +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 4881fd873b
acc: Write out.requests.txt immediately (#2368)
## Changes
- Instead of collecting requests in memory and writing them at the end
of the test, write them right away. Then test authors can do filtering
with jq in 'script' or collect individual files per different command.
- testserver is now simpler - it just calls a caller-provided function.
The logging logic is moved to acceptance_test.go.

See https://github.com/databricks/cli/pull/2359/files#r1967591173

## Tests
Existing tests.
2025-02-24 13:37:05 +00:00
Lennart Kats (databricks) f99716b0a5
Remove `run_as` from the built-in templates (#2044)
## Changes

This removes the `run-as` property from the default templates. It's a
useful property but it still only works for jobs and it makes the
default databricks.yml a bit longer. It seems like users can just learn
about it from the docs and/or vary their deployment identity.

Depends on https://github.com/databricks/cli/pull/1712.
2025-02-24 08:31:46 +00:00
shreyas-goenka ddcfac5069
Add library for spawning a daemon (#2354)
## Changes
This PR adds a library for spawning a daemon process. Our needs are
different from those of a typical daemon process in that we want to
handle being orphaned gracefully. This is because, in the vast majority
of telemetry use cases, the main CLI process (i.e., the parent process)
will exit before the telemetry process has a chance to finish uploading
the logs.

To achieve this we "detach" the child process from the parent process,
which requires different flags for UNIX vs. non-unix systems.

Here are the properties that we want to ensure for our telemetry
child/daemon processes:
1. They do not block the parent process. 
Reason: The main CLI process should not be blocked on the telemetry
child process.
2. The child can read from stdin. The parent can write to stdin. 
Reason: Telemetry logs will be passed to the child process via stdin.
3. Output logs do not leak from the child process.
    Reason: Telemetry logs should not be visible to users of the CLI.

## Tests
Unit test
2025-02-21 13:49:47 +00:00
Lennart Kats (databricks) bc30d44097
Provide instructions for testing in the default-python template (#2355)
## Changes
Adds instructions for testing to the default-python template.

## Tests
- Unit & acceptance tests.
2025-02-17 12:38:03 +00:00
Denis Bilenko 4034766c93
acc: Simplify writing handlers; support headers in responses (#2338)
## Changes

Handlers now receive testserver.Request and return any which could be
- string or []byte (returns it as is but sets content-type to json or
plain text depending on content)
- struct (encodes it as json and sets content-type to json)
- testserver.Response (full control over status and headers)

Note if testserver.Response is returned from the handler, it's Body
attribute can still be an object. In that case, it'll be serialized and
appropriate content-type header will be added.

The config is now using the same testserver.Response struct, the same
logic applies both configured responses and responses returned from
handlers.

As a result, one can set headers both in Golang handlers and in
test.toml.

This also fixes a bug with RecordRequest not seeing the body if it was
already consumed by the handler.

## Tests
- Existing rests. 
- acceptance/selftest/server is extended to set response header.
2025-02-12 13:00:57 +00:00
Denis Bilenko 5d392acbef
acc: Allow mixing custom stubs with default server impl (#2334)
## Changes
- Currently if you define [[Server]] block, you disable the default
server implementation. With this change [[Server]] block takes
precedence over default server but default server remains.
- Switched mux implementation to
[gorilla/mux](https://github.com/gorilla/mux) -- unlike built-in it does
not panic if you set two handlers on the same part (instead the earliest
one wins). It also does not have any dependencies.
- Move acceptance/selftest into acceptance/selftest/basic and added
acceptance/selftest/server that demoes server override.
- Rewrite server set up to ensure that env vars and replacements are set
up correctly. Previously replacements for DATABRICKS_HOST referred to
default server, not to the custom server.
- Avoid calling CurrentUser.Me() in the local case. This allows
overriding /api/2.0/preview/scim/v2/Me, which we use in some tests (e.g.
bundle/templates-machinery/helpers-error). Previously the test passed
because CurrentUser.Me() was calling default server which is incorrect
but it happened to make the tests pass.
- The default server is now available on DATABRICKS_DEFAULT_HOST env
var.
- Rewrite "not found" handler in local test to handle error better (do
not raise http500 when header is already written).

## Tests
New acceptance test selftest/server specifically tests that both custom
and default handlers are available in a single test.
2025-02-11 15:03:41 +00:00
Denis Bilenko 878fa80322
acc: Fix RecordRequests to support requests without body (#2333)
## Changes
Do not paste request body into output if it's not a valid JSON.

## Tests
While working on #2334 I found that if I try to record a test that calls
/api/2.0/preview/scim/v2/Me which has no request body, it crashes.
2025-02-11 10:50:52 +00:00
shreyas-goenka ddedc4272d
Return 501 status code when API stub is not implemented (#2327)
## Changes
Addresses feedback from
https://github.com/databricks/cli/pull/2292#discussion_r1946846865

## Tests
Manually, confirmed that unstubbed API calls still cause acceptance
tests to fail.
2025-02-10 13:05:12 +00:00
shreyas-goenka ee440e65fe
Serialize all header values in acceptance tests (#2311)
## Changes
Based on feedback in
https://github.com/databricks/cli/pull/2296#discussion_r1946660650.
Previously we only serialized the first value for a header in the
requests log. Now we serialise all values for a header key.

## Tests
Existing test
2025-02-10 12:18:05 +00:00
Andrew Nester f8aaa7fce3
Added support to generate Git based jobs (#2304)
## Changes
This will generate bundle YAML configuration for Git based jobs but
won't download any related files as they are in Git repo.

Fixes #1423 

## Tests
Added unit test

---------

Co-authored-by: Pieter Noordhuis <pieter.noordhuis@databricks.com>
2025-02-07 18:37:03 +00:00
Andrew Nester 5aa89230e9
Use CreatePipeline instead of PipelineSpec for resources.Pipeline struct (#2287)
## Changes
`CreatePipeline` is a more complete structure (superset of PipelineSpec
one) which enables support of additional fields such as `run_as` and
`allow_duplicate_names` in DABs configuration. Note: these fields are
subject to support in TF in order to correctly work.

## Tests
Existing tests pass + no fields are removed from JSON schema
2025-02-07 17:22:51 +00:00
shreyas-goenka f71583fbc0
Error when unknown API endpoint is used in testserver (#2292)
## Changes
This PR fails the acceptance test when an unknown endpoint (i.e. not
stubbed) is used. We want to ensure that all API endpoints used in an
acceptance test are stubbed and do not otherwise silently fail with a
404.

The logs on failure output include a configuration that developers can
simply copy-paste to `test.toml` to stub the missing API endpoint. It'll
look something like:
```
[[Server]]
Pattern = "<method> <path>"
Response.Body = '''
<response body here>
'''
Response.StatusCode = <response status-code here>
```


## Tests
Manually:

output.txt when an endpoint is not found: 
```
>>> [CLI] jobs create --json {"name":"abc"}
Error: No stub found for pattern: POST /api/2.1/jobs/create
```

How this renders in the test logs:
```
    --- FAIL: TestAccept/workspace/jobs/create (0.03s)
        server.go:46: 
            
            ----------------------------------------
            No stub found for pattern: POST /api/2.1/jobs/create
            
            To stub a response for this request, you can add
            the following to test.toml:
            [[Server]]
            Pattern = "POST /api/2.1/jobs/create"
            Response.Body = '''
            <response body here>
            '''
            Response.StatusCode = <response status-code here>
            ----------------------------------------
```

Manually checked that the debug mode still works.
2025-02-07 16:26:48 +00:00
Denis Bilenko 54e16d5f62
Always print warnings and errors; clean up format (#2213)
## Changes
- Print warnings and errors by default.
- Fix ErrAlreadyPrinted not to be logged at Error level.
- Format log messages as "Warn: message" instead of "WARN" to make it
more readable and in-line with the rest of the output.
- Only print attributes (pid, mutator, etc) and time when the overall
level is debug (so --debug output has not changed much).

## Tests
- Existing acceptance tests show how warning messages appear in various
test case.
- Added new test for `--debug` output.
- Add sort_lines.py helper to avoid dependency on 'sort' which is
locale-sensitive.
2025-02-07 11:29:40 +00:00
Gleb Kanterov 75127fe42e
Extend testserver for deployment (#2299)
## Changes
Extend testserver for bundle deployment:

- Allocate a new workspace per test case to isolate test cases from each
other
- Support jobs get/list/create
- Support creation and listing of workspace files

## Tests
Using existing acceptance tests
2025-02-07 10:26:20 +00:00
Ilya Kuznetsov 27eb0c4072
Allow 'any' examples in JSON schema (#2289)
## Changes

1. Allow `any` examples in json-schema type since we have many of them
in open api spec
2. Fix issue with missing overrides annotations when re-generating the
schema

## Tests
<!-- How is this tested? -->
2025-02-06 19:27:55 +00:00