Repository navigation
Add bundle auto-deploy get and list - #7941
atreyadbrx wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Automated review at bbaf04d. Each finding was verified against the code.
No blocking issues found. 3 non-blocking comment(s) below.
This PR adds bundle auto-deploy get and list. Both call ListWebhookTriggers with an AIP-160 filter, and the fake server learns to handle that filter and to return one trigger per page. The paging and filter code look correct. Two things need fixing: list is still tied to the one selected target, which doesn't match its help text, and the "Deploy as" rendering and its comments disagree with what create --deploy-as accepts. A smaller point: the fake filter parser has a fallback for unquoted values that it shouldn't need.
|
|
||
| cmd.RunE = func(cmd *cobra.Command, args []string) error { | ||
| t, api, err := loadTrigger(cmd) | ||
| if err != nil { |
There was a problem hiding this comment.
[nice to have] list says it covers "this bundle's targets", but loadTrigger runs ProcessBundle, which selects one target first. In a bundle with two targets and no default: true, bundle auto-deploy list fails with "please specify target" even though the filter never uses the target. When prod sets its own workspace.host, running list from dev only queries dev's workspace and leaves out prod's trigger without saying so. The same happens when a target overrides bundle.git.origin_url, because repo_url comes from the selected target (trigger.go resolveTrigger). Should list work without a selected target, or go through each target's workspace and origin? Failing that, can the help text say it lists the triggers in the selected target's workspace and repository?
|
|
||
| // The service shows deploy_as only for a service principal. A trigger can only deploy as a | ||
| // service principal or the user who set it up. | ||
| const deployAsTemplate = `{{with .TriggerConfig.DabsDeploy.DeployAs}}{{or .UserEmail .ServicePrincipalClientID}}{{else}}its creator{{end}}` |
There was a problem hiding this comment.
[nice to have] create --deploy-as alice@example.com sends DeployAs{UserEmail: ...} (deployAsIdentity in create.go), and its help says it takes a user's email. The comment here and the one in libs/gitwebhooks/model.go say the service returns deploy_as only for a service principal, and that an unset value means the creator. If both are true, a trigger that bob created to deploy as alice shows "its creator" in get and list, which reads as bob. And {{or .UserEmail ...}} is a branch the comment says never runs. Which is it? If the service drops user_email, the unset case can't honestly read "its creator", and the .UserEmail branch should go. If the service keeps it, the comments here and in model.go need fixing. The fake's list handler returns user_email too, so the goldens can't tell the two cases apart.
There was a problem hiding this comment.
🤖 Should fix +1. The current wording is still wrong after someone else updates the trigger: an update keeps the trigger's creator but makes it deploy as the caller. Scenario: user U runs auto-deploy create -t prod, then a workspace admin A runs the same command (admins can update any trigger). The trigger now deploys as A, but get and list print Deploy as: its creator, which reads as U. The same happens when U creates it with --deploy-as <SP> and that service principal runs get, since deploy_as is left out when it is the caller.
Since deploy_as comes back only for a service principal other than the caller, an unset value can only honestly say that it isn't one, e.g. you or a user or a user (not shown). The comment on DabsDeployTarget.DeployAs (libs/gitwebhooks/model.go:72) makes the same claim.
There was a problem hiding this comment.
Changed in ee80a9e to you or a user. The model comment now says deploy_as is set only for a service principal other than the caller. The get test also renders the service-principal case as text now.
| if _, ok := gitWebhookFilterFields[field]; !ok { | ||
| return nil, fmt.Errorf("unsupported filter field: %s", field) | ||
| } | ||
| if strings.HasPrefix(value, `"`) { |
There was a problem hiding this comment.
[nice to have] The parser's doc comment says the supported subset takes string values in double quotes, but when a value doesn't start with ", this branch silently matches on the raw text. So repo_url = https://github.com/acme/repo succeeds in the fake. If a later change dropped quote() from the client, every acceptance test would still pass. That's the kind of just-in-case fallback AGENTS.md asks us not to add, and testing.md wants the fake to model the real contract. Can this return INVALID_PARAMETER_VALUE for an unquoted value instead?
Regression test report ✅Commit: Selected 3 changed tests (limit=20, 0 not selected) 3 tests: regression=3 unreleased=0 coverage=0 failing=0
TestAccept/bundle/auto-deploy/create: branch ✅ | main (4c4f104) ❌ | latest (v1.28.0) ❌main (4c4f104): latest (v1.28.0): same output as main (4c4f104) TestAccept/bundle/auto-deploy/get: branch ✅ | main (4c4f104) ❌ | latest (v1.28.0) ❌main (4c4f104): latest (v1.28.0): same output as main (4c4f104) TestAccept/bundle/auto-deploy/list: branch ✅ | main (4c4f104) ❌ | latest (v1.28.0) ❌main (4c4f104): latest (v1.28.0): same output as main (4c4f104) |
✅ Integration test reportCommit: b78dec4
Top 3 slowest tests (at least 2 minutes):
|
cd55ba9 to
cf6b8e1
Compare
bbaf04d to
eb8b631
Compare
cf6b8e1 to
cfcecee
Compare
eb8b631 to
852eda8
Compare
denik
left a comment
There was a problem hiding this comment.
🤖 Automated review of 852eda8 by Opus, Fable and Astra; each finding verified against the code.
No blocking issues. Two should-fix points: one inline, one as a reply in review-oss-bot's deploy-as thread. I reviewed only this PR's diff against dabs-ad-d4-pr3-create (stacked on #7940). The auto-deploy acceptance and unit tests pass at this head, and also with it merged into current main.
Review points:
- review-oss-bot's three threads from
bbaf04dare still open. The new help text looks like it covers thelistscope thread. The unquoted-value thread is mostly addressed: onlygit_providerstill takes a bare value (item 1 below). - No cloud run is possible because test workspaces don't serve the git-webhooks API yet. Until then, the list path, filter field names and escaping are pinned only by the fake.
Not posted inline:
-
Should fix
libs/testserver/gitwebhooks.go:115: the fake differs from the list endpoint in ways that let tests pass for the wrong reason:- It filters before paging, so it never returns a page with the match plus a
next_page_token. That hides thefindTriggerpaging issue. - It returns every trigger to every caller, so no test can reach the "that you can view" error. An
as-test-spstep could cover it. - Its parser splits on
ANDbefore reading quotes, so a bundle underR AND D/gets a 400. - It decodes values with
strconv.Unquote, which also accepts\n,\tand\x41. Replacingquote()withstrconv.Quotewould still pass. - A repeated field is last-wins instead of an error.
- The CLI never sends
git_provider. - A negative
page_tokenpanics atmatched[offset:end].
- It filters before paging, so it never returns a page with the match plus a
-
Should fix
acceptance/bundle/auto-deploy/get/script:13,list/script:10: two paths are never pinned:- The service-principal branch of
deployAsTemplatenever renders as text: the SP trigger is read only with-o json. - The
other/exclusion would still pass ifcreateinother/resolved to the rootdatabricks.yml, because its request is deleted before printing.
Rendering
get -t prodas text, and printing theothercreate's request (or runninglistinother/), would pin both. - The service-principal branch of
-
Should fix (minor)
cmd/bundle/autodeploy/trigger.go:97: the "To create one, run: ..." hint drops an explicit-p. For a bundle withoutworkspace.host,get -p staging -t prodsuggests a command that creates the trigger, and immediately deploys, in the default profile's workspace.cmd/workspace/apps/errors.go:53adds--profileto its suggested command.
|
|
||
| // findTrigger returns the trigger of the bundle's target, or an error if it has none. | ||
| func findTrigger(ctx context.Context, api *gitwebhooks.API, t trigger) (*gitwebhooks.WebhookTrigger, error) { | ||
| triggers, err := listing.ToSlice(ctx, api.ListWebhookTriggers(ctx, gitwebhooks.ListWebhookTriggersRequest{Filter: t.targetFilter()})) |
There was a problem hiding this comment.
🤖 Should fix listing.ToSlice keeps paging after the one match get needs. The list endpoint pages over all of the repository's triggers and returns the matches of each page, so in a repository with more triggers than one page holds, the page with the match still carries a next_page_token. get then sends more GETs whose results it can't use (each one an extra round trip), and a 429/5xx on one of them fails get with the answer already in hand.
Taking the first item avoids both; the iterator already skips empty pages that carry a token:
found, err := api.ListWebhookTriggers(ctx, gitwebhooks.ListWebhookTriggersRequest{Filter: t.targetFilter()}).Next(ctx)
if errors.Is(err, listing.ErrNoMoreItems) {
return nil, fmt.Errorf("target %s has no auto-deploy trigger ...", ...)
}listing.ToSliceN(ctx, it, 1) doesn't help: its loop calls HasNext (which fetches the next page) before checking the count. The fake filters before paging, so it never returns such a page, and the golden shows one request per get.
There was a problem hiding this comment.
Fixed in ee80a9e. findTrigger now takes the first item with Next. The fake pages over all of the repository's triggers, as the service does, so get -t prod in the get test reads two pages and stops at the match.
|
|
||
| // The service shows deploy_as only for a service principal. A trigger can only deploy as a | ||
| // service principal or the user who set it up. | ||
| const deployAsTemplate = `{{with .TriggerConfig.DabsDeploy.DeployAs}}{{or .UserEmail .ServicePrincipalClientID}}{{else}}its creator{{end}}` |
There was a problem hiding this comment.
🤖 Should fix +1. The current wording is still wrong after someone else updates the trigger: an update keeps the trigger's creator but makes it deploy as the caller. Scenario: user U runs auto-deploy create -t prod, then a workspace admin A runs the same command (admins can update any trigger). The trigger now deploys as A, but get and list print Deploy as: its creator, which reads as U. The same happens when U creates it with --deploy-as <SP> and that service principal runs get, since deploy_as is left out when it is the caller.
Since deploy_as comes back only for a service principal other than the caller, an unset value can only honestly say that it isn't one, e.g. you or a user or a user (not shown). The comment on DabsDeployTarget.DeployAs (libs/gitwebhooks/model.go:72) makes the same claim.
cfcecee to
30d20e7
Compare
852eda8 to
ee80a9e
Compare
|
Thanks @denik. I pushed ee80a9e with your points addressed. Inline threads have replies.
|
`get` shows the trigger of the bundle target and `list` lists the triggers of all the bundle's targets. Both call ListWebhookTriggers, filtered on the bundle's repository and path, plus the target for `get`. The fake list handler supports the filter fields the CLI sends and returns one trigger per page, so the CLI's paging is exercised. Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: atreyadbrx <atreya.misra@databricks.com>
30d20e7 to
b8e3fd8
Compare
ee80a9e to
b78dec4
Compare
Changes
getshows the trigger of the bundle target.listlists the triggers of all the bundle's targets.ListWebhookTriggerswith an AIP-160 filter on the repo URL and bundle path, plus the target forget.getstops at the first match, since the service keeps one trigger per target. Its "no trigger" error suggests thecreatecommand, including-pwhen it was passed. Both support text and-o jsonoutput.listcovers the selected target's origin and workspace, as its help says.\"/\\escapes the service takes, and rejects a repeated field and a bad page token.Why
Users need to see what auto-deploy is set up for a bundle. The service keeps at most one trigger per repository and target, so a target filter is enough for
get. The service returnsdeploy_asonly for a service principal, so an unset value shows as "its creator".Tests
acceptance/bundle/auto-deploy/get: a target with no trigger, text output, and-o json.acceptance/bundle/auto-deploy/list: two targets, plus another bundle in the same repo whose trigger is left out. The fake's one-item pages exercise the client's paging.Stacked on #7940.
This pull request and its description were written by Isaac.