-
Notifications
You must be signed in to change notification settings - Fork 215
job_runs: add lifecycle.triggers.on_bundle_deploy #6231
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
124e03b
job_runs: add lifecycle.triggers.on_bundle_deploy
radakam a4e4a8e
job_runs: drop unsupported on_file_change and on_value_change triggers
radakam 0dd4c7d
job_runs: phrase on_bundle_deploy comments positively
radakam 47325b2
job_runs: drop OverrideChangeDesc skip when removing on_bundle_deploy
radakam 9d04655
job_runs: reject on_bundle_deploy together with prevent_destroy
radakam 9e15dba
job_runs: refresh acceptance goldens after main merge
radakam b2abedf
job_runs: validate lifecycle.triggers during initialize
radakam 499040c
job_runs: keep on_bundle_deploy removal drift-free and nest state und…
radakam 1d3830a
job_runs: refresh on_bundle_deploy golden for deploy summary
radakam 6c86193
chore: retrigger CI
radakam 71143cb
job_runs: cover on_bundle_deploy with a plan saved to disk
radakam e5ce657
job_runs: drop unused JobRun.GetLifecycle
radakam c2f0507
job_runs: clear removed trigger fingerprints with a state-only update
radakam 8811a06
job_runs: record on_bundle_deploy plan changes in acceptance
radakam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| direct: `resources.job_runs` can set `lifecycle.triggers.on_bundle_deploy: true` to re-fire the run on every bundle deploy. Removing the trigger does not recreate the existing run. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
acceptance/bundle/resources/job_runs/interrupted_run/test.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,3 @@ | ||
| # job_runs is a direct-engine-only resource; the Terraform provider has no | ||
| # equivalent, so restrict the matrix to direct. | ||
| EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] | ||
|
|
||
| # The interruption is staged by injecting a fault into the testserver, so this | ||
| # stays off cloud. | ||
| RecordRequests = true | ||
| Ignore = ["tmp.plan.json"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
acceptance/bundle/resources/job_runs/job_parameters/test.toml
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
acceptance/bundle/resources/job_runs/on_bundle_deploy/databricks.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| bundle: | ||
| name: job-runs-on-bundle-deploy | ||
|
|
||
| resources: | ||
| jobs: | ||
| my_job: | ||
| name: my-job | ||
| tasks: | ||
| - task_key: main | ||
| notebook_task: | ||
| notebook_path: /Workspace/test | ||
|
|
||
| job_runs: | ||
| my_run: | ||
| job_id: ${resources.jobs.my_job.id} | ||
| lifecycle: | ||
| triggers: | ||
| - on_bundle_deploy: true |
3 changes: 3 additions & 0 deletions
3
acceptance/bundle/resources/job_runs/on_bundle_deploy/out.test.toml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
145 changes: 145 additions & 0 deletions
145
acceptance/bundle/resources/job_runs/on_bundle_deploy/output.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
|
|
||
| === first deploy triggers a run | ||
| >>> [CLI] bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/job-runs-on-bundle-deploy/default/files... | ||
| job run [MY_RUN_ID]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID]?o=[NUMID] | ||
| job run [MY_RUN_ID]: SUCCESS | ||
| Created job_runs.my_run | ||
| Created jobs.my_job | ||
| Files: 5 uploaded, 0 deleted | ||
| Resources: 2 created, 0 changed, 0 deleted, 0 unchanged | ||
|
|
||
| >>> read_id.py my_job | ||
| [MY_JOB_ID] | ||
|
|
||
| >>> print_requests.py //jobs/run-now | ||
| { | ||
| "method": "POST", | ||
| "path": "/api/2.2/jobs/run-now", | ||
| "body": { | ||
| "idempotency_token": "[UUID]", | ||
| "job_id": [MY_JOB_ID] | ||
| } | ||
| } | ||
|
|
||
| === redeploy re-fires with unchanged config | ||
| >>> [CLI] bundle plan | ||
| recreate job_runs.my_run | ||
|
|
||
| Plan: 1 to add, 0 to change, 1 to delete, 1 unchanged | ||
|
|
||
| >>> jq .plan["resources.job_runs.my_run"].changes tmp.plan.json | ||
| { | ||
| "lifecycle": { | ||
| "action": "recreate", | ||
| "reason": "immutable", | ||
| "old": { | ||
| "triggers": { | ||
| "on_bundle_deploy": "[UUID]" | ||
| } | ||
| }, | ||
| "new": { | ||
| "triggers": { | ||
| "on_bundle_deploy": "[UUID]" | ||
| } | ||
| } | ||
| }, | ||
| "lifecycle.triggers.on_bundle_deploy": { | ||
| "action": "recreate", | ||
| "reason": "immutable", | ||
| "old": "[UUID]", | ||
| "new": "[UUID]" | ||
| }, | ||
| "result_state": { | ||
| "action": "skip", | ||
| "reason": "remote_already_set", | ||
| "new": "SUCCESS", | ||
| "remote": "SUCCESS" | ||
| } | ||
| } | ||
|
|
||
| === bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/job-runs-on-bundle-deploy/default/files... | ||
| job run [MY_RUN_ID_2]: Run URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID_2]?o=[NUMID] | ||
| job run [MY_RUN_ID_2]: SUCCESS | ||
| Recreated job_runs.my_run | ||
| Files: 3 uploaded, 0 deleted | ||
| Resources: 1 created, 0 changed, 1 deleted, 1 unchanged | ||
|
|
||
| >>> [CLI] bundle summary | ||
| Name: job-runs-on-bundle-deploy | ||
| Target: default | ||
| Workspace: | ||
| User: [USERNAME] | ||
| Path: /Workspace/Users/[USERNAME]/.bundle/job-runs-on-bundle-deploy/default | ||
| Resources: | ||
| Job Runs: | ||
| my_run: | ||
| Name: | ||
| URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]/runs/[MY_RUN_ID_2]?w=[NUMID] | ||
| Jobs: | ||
| my_job: | ||
| Name: my-job | ||
| URL: [DATABRICKS_URL]/jobs/[MY_JOB_ID]?w=[NUMID] | ||
|
|
||
| === second run-now after recreate | ||
| >>> print_requests.py --keep //jobs/runs/delete | ||
| { | ||
| "method": "POST", | ||
| "path": "/api/2.2/jobs/runs/delete", | ||
| "body": { | ||
| "run_id": [MY_RUN_ID] | ||
| } | ||
| } | ||
|
|
||
| >>> print_requests.py //jobs/run-now | ||
| { | ||
| "method": "POST", | ||
| "path": "/api/2.2/jobs/run-now", | ||
| "body": { | ||
| "idempotency_token": "[UUID]", | ||
| "job_id": [MY_JOB_ID] | ||
| } | ||
| } | ||
|
|
||
| === removing on_bundle_deploy rewrites state without a run | ||
| >>> [CLI] bundle plan | ||
| update job_runs.my_run | ||
|
|
||
| Plan: 0 to add, 1 to change, 0 to delete, 1 unchanged | ||
|
|
||
| >>> jq .plan["resources.job_runs.my_run"].changes tmp.plan.json | ||
| { | ||
| "lifecycle": { | ||
| "action": "update", | ||
| "reason": "trigger removed", | ||
| "old": { | ||
| "triggers": { | ||
| "on_bundle_deploy": "[UUID]" | ||
| } | ||
| } | ||
| }, | ||
| "result_state": { | ||
| "action": "skip", | ||
| "reason": "remote_already_set", | ||
| "new": "SUCCESS", | ||
| "remote": "SUCCESS" | ||
| } | ||
| } | ||
|
|
||
| === bundle deploy | ||
| Uploading bundle files to /Workspace/Users/[USERNAME]/.bundle/job-runs-on-bundle-deploy/default/files... | ||
| Updated job_runs.my_run | ||
| Files: 4 uploaded, 0 deleted | ||
| Resources: 0 created, 1 changed, 0 deleted, 1 unchanged | ||
|
|
||
| >>> print_requests.py //jobs/run-now | ||
|
|
||
| >>> [CLI] bundle destroy --auto-approve | ||
| The following resources will be deleted: | ||
| delete resources.job_runs.my_run | ||
| delete resources.jobs.my_job | ||
|
|
||
| All files and directories at the following location will be deleted: /Workspace/Users/[USERNAME]/.bundle/job-runs-on-bundle-deploy/default | ||
|
|
||
| Destroy: 2 deleted | ||
41 changes: 41 additions & 0 deletions
41
acceptance/bundle/resources/job_runs/on_bundle_deploy/script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| cleanup() { | ||
| trace $CLI bundle destroy --auto-approve | ||
| rm -f out.requests.txt | ||
| } | ||
| trap cleanup EXIT | ||
|
|
||
| title "first deploy triggers a run" | ||
| trace $CLI bundle deploy | ||
| trace read_id.py my_job | ||
| # Name the first run so the second becomes [MY_RUN_ID_2]. | ||
| read_id.py my_run > /dev/null | ||
| trace print_requests.py //jobs/run-now | ||
|
|
||
| title "redeploy re-fires with unchanged config" | ||
| trace $CLI bundle plan | ||
|
radakam marked this conversation as resolved.
|
||
| # Save the plan so the READPLAN=1 variant deploys the fingerprint minted here. | ||
| # The deploys are not traced: readplanarg makes the command line differ per variant. | ||
| $CLI bundle plan -o json > tmp.plan.json | ||
|
radakam marked this conversation as resolved.
|
||
| trace jq '.plan["resources.job_runs.my_run"].changes' tmp.plan.json | ||
| title "bundle deploy\n" | ||
| $CLI bundle deploy $(readplanarg tmp.plan.json) | ||
| read_id.py my_run > /dev/null | ||
| trace $CLI bundle summary | ||
|
|
||
| title "second run-now after recreate" | ||
| trace print_requests.py --keep //jobs/runs/delete | ||
| trace print_requests.py //jobs/run-now | ||
|
|
||
| title "removing on_bundle_deploy rewrites state without a run" | ||
| # Drop the lifecycle block so the next plan compares a nil fingerprint against | ||
| # the UUID left in state: a state-only update that clears it, never a recreate. | ||
| update_file.py databricks.yml " lifecycle: | ||
| triggers: | ||
| - on_bundle_deploy: true | ||
| " "" | ||
| trace $CLI bundle plan | ||
| $CLI bundle plan -o json > tmp.plan.json | ||
| trace jq '.plan["resources.job_runs.my_run"].changes' tmp.plan.json | ||
| title "bundle deploy\n" | ||
| $CLI bundle deploy $(readplanarg tmp.plan.json) | ||
| trace print_requests.py //jobs/run-now | ||
6 changes: 6 additions & 0 deletions
6
acceptance/bundle/resources/job_runs/on_bundle_deploy/test.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Deploy both by re-planning and from a plan saved on disk, so the fingerprint | ||
| # minted during planning is exercised across plan serialization. | ||
| EnvMatrix.READPLAN = ["", "1"] | ||
|
|
||
| # The saved plan embeds a fresh fingerprint on every run. | ||
| Ignore = ["tmp.plan.json"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
acceptance/bundle/resources/job_runs/retried_run_now/test.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
...bundle/resources/job_runs/basic/test.toml → ...tance/bundle/resources/job_runs/test.toml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| # job_runs is a direct-engine-only resource; the Terraform provider has no | ||
| # equivalent, so restrict the matrix to direct. | ||
| EnvMatrix.DATABRICKS_BUNDLE_ENGINE = ["direct"] | ||
| RecordRequests = true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package mutator | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/databricks/cli/bundle" | ||
| "github.com/databricks/cli/libs/diag" | ||
| ) | ||
|
|
||
| type validateJobRunTriggers struct{} | ||
|
|
||
| // ValidateJobRunTriggers rejects invalid lifecycle.triggers on job_runs. | ||
| func ValidateJobRunTriggers() bundle.Mutator { | ||
| return &validateJobRunTriggers{} | ||
| } | ||
|
|
||
| func (*validateJobRunTriggers) Name() string { | ||
| return "ValidateJobRunTriggers" | ||
| } | ||
|
|
||
| func (*validateJobRunTriggers) Apply(_ context.Context, b *bundle.Bundle) diag.Diagnostics { | ||
| var diags diag.Diagnostics | ||
| for name, jr := range b.Config.Resources.JobRuns { | ||
| if jr == nil || jr.Lifecycle == nil { | ||
| continue | ||
| } | ||
| // Recreate-every-deploy cannot coexist with prevent_destroy. | ||
| if jr.HasOnBundleDeploy() && jr.Lifecycle.PreventDestroy { | ||
| diags = diags.Append(diag.Diagnostic{ | ||
| Severity: diag.Error, | ||
| Summary: "lifecycle.triggers.on_bundle_deploy is incompatible with lifecycle.prevent_destroy", | ||
| Locations: b.Config.GetLocations(fmt.Sprintf("resources.job_runs.%s.lifecycle", name)), | ||
| }) | ||
| } | ||
| for i, t := range jr.Lifecycle.Triggers { | ||
| path := fmt.Sprintf("resources.job_runs.%s.lifecycle.triggers[%d]", name, i) | ||
| if t.OnBundleDeploy == nil { | ||
| diags = diags.Append(diag.Diagnostic{ | ||
| Severity: diag.Error, | ||
| Summary: "lifecycle.triggers entry must set on_bundle_deploy: true", | ||
| Locations: b.Config.GetLocations(path), | ||
| }) | ||
| continue | ||
| } | ||
| if !*t.OnBundleDeploy { | ||
| diags = diags.Append(diag.Diagnostic{ | ||
| Severity: diag.Error, | ||
| Summary: "lifecycle.triggers.on_bundle_deploy must be true when set", | ||
| Locations: b.Config.GetLocations(path + ".on_bundle_deploy"), | ||
| }) | ||
| } | ||
| } | ||
| } | ||
| return diags | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.