Repository navigation
air: Skip purged runs in air list --all-status #7523
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
Open
abdulkareem-db
wants to merge
2
commits into
main
Choose a base branch
from
abdulkareem/air-list-skip-purged-runs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 @@ | ||
| * `air list --all-status` no longer fails when a listed run has been purged. ([#7523](https://github.com/databricks/cli/pull/7523)) |
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 |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import ( | |
| "net/http/httptest" | ||
| "testing" | ||
|
|
||
| "github.com/databricks/databricks-sdk-go/service/jobs" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
@@ -45,3 +46,76 @@ func TestFetchJobRunParsesAiRuntimeTask(t *testing.T) { | |
| assert.Equal(t, "GPU_1xA10", gpuType) | ||
| assert.Equal(t, 1, count) | ||
| } | ||
|
|
||
| type runGetResponse struct { | ||
| status int | ||
| body string | ||
| } | ||
|
|
||
| // runGetByIDServer serves runs/get per run_id and a stub for the SDK config | ||
| // probe; ids missing from responses return a run with that id. | ||
| func runGetByIDServer(t *testing.T, responses map[string]runGetResponse) *httptest.Server { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. list_index_test.go already has indexAndGetServer with per-id forbidden/missing maps and TestIndexStrategyDropsForbiddenAndMissing. Can the purged case extend those instead of a second per-id runs/get fake? |
||
| t.Helper() | ||
| srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
| if r.URL.Path != "/api/2.2/jobs/runs/get" { | ||
| _, _ = w.Write([]byte(`{}`)) | ||
| return | ||
| } | ||
| id := r.URL.Query().Get("run_id") | ||
| resp, ok := responses[id] | ||
| if !ok { | ||
| resp = runGetResponse{status: http.StatusOK, body: `{"run_id": ` + id + `}`} | ||
| } | ||
| w.WriteHeader(resp.status) | ||
| _, _ = w.Write([]byte(resp.body)) | ||
| })) | ||
| t.Cleanup(srv.Close) | ||
| return srv | ||
| } | ||
|
|
||
| func runIDs(runs []*jobs.Run) []int64 { | ||
| ids := make([]int64, len(runs)) | ||
| for i, r := range runs { | ||
| ids[i] = r.RunId | ||
| } | ||
| return ids | ||
| } | ||
|
|
||
| func TestHydrateJobRunsDropsUnviewableAndPurgedRuns(t *testing.T) { | ||
| srv := runGetByIDServer(t, map[string]runGetResponse{ | ||
| "2": {http.StatusBadRequest, `{"error_code": "INVALID_PARAMETER_VALUE", "message": "Run 2 does not exist."}`}, | ||
| "4": {http.StatusForbidden, `{"error_code": "PERMISSION_DENIED", "message": "denied"}`}, | ||
| "5": {http.StatusNotFound, `{"error_code": "NOT_FOUND", "message": "not found"}`}, | ||
| }) | ||
|
|
||
| runs, err := hydrateJobRuns(t.Context(), newTestWorkspaceClient(t, srv.URL), []int64{1, 2, 3, 4, 5, 6}) | ||
| require.NoError(t, err) | ||
| assert.Equal(t, []int64{1, 3, 6}, runIDs(runs)) | ||
| } | ||
|
|
||
| func TestHydrateJobRunsFailsOnOtherErrors(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| resp runGetResponse | ||
| wantErr string | ||
| }{ | ||
| { | ||
| name: "internal error", | ||
| resp: runGetResponse{http.StatusInternalServerError, `{"error_code": "INTERNAL_ERROR", "message": "boom"}`}, | ||
| wantErr: "failed to get run 2: boom", | ||
| }, | ||
| { | ||
| name: "other invalid parameter", | ||
| resp: runGetResponse{http.StatusBadRequest, `{"error_code": "INVALID_PARAMETER_VALUE", "message": "run_id must be positive"}`}, | ||
| wantErr: "failed to get run 2: run_id must be positive", | ||
| }, | ||
| } | ||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| srv := runGetByIDServer(t, map[string]runGetResponse{"2": tt.resp}) | ||
|
|
||
| _, err := hydrateJobRuns(t.Context(), newTestWorkspaceClient(t, srv.URL), []int64{1, 2, 3}) | ||
| assert.EqualError(t, err, tt.wantErr) | ||
| }) | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ErrResourceDoesNotExist inherits ErrNotFound, and a plain 404 maps to ErrNotFound too, so
errors.Is(err, apierr.ErrNotFound) || errors.Is(err, apierr.ErrPermissionDenied)would replace both branches (precedent: libs/apps/prompt/prompt.go:861). Worth collapsing, or not worth it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correction: APIError.Unwrap resolves error_code before HTTP status, so collapsing to errors.Is would stop dropping a 403/404 that carries a mapped code. Keep the two branches.