Skip to content

feat: add provisioner daemon and jobs endpoints and commands - #15940

Closed
mafredri wants to merge 21 commits into
mainfrom
mafredri/feat-provisioner-and-jobs-list
Closed

mafredri wants to merge 21 commits into
mainfrom
mafredri/feat-provisioner-and-jobs-list

Conversation

@mafredri

Copy link
Copy Markdown
Member

Fixes #15190
Fixes #15191
Updates #15084

@mafredri
mafredri marked this pull request as draft December 19, 2024 18:21
@mafredri
mafredri force-pushed the mafredri/feat-provisioner-and-jobs-list branch from b776b1b to af6789a Compare December 20, 2024 15:05
Comment on lines +2 to +3
==========[version job ID]========== ====[timestamp]===== succeeded map[owner: scope:organization] template_version_import Coder
======[workspace build job ID]====== ====[timestamp]===== succeeded map[owner: scope:organization] workspace_build Coder

@johnstcn johnstcn Dec 20, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if tags were listed in k1=v1,k2=v2 format.
We can also probably "lie" a bit about the case {"owner": "", "scope": "organization"} and just pretend it's empty.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestions, and I agree we should hide default owner/scope. We should probably update table formatter to change how maps are output.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move "Queue" column to be the first one.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move "Queue" column to be the first one.

@mtojek I'm going to create a follow-up issue for this as ordering columns is not supported in our table formatter currently. I would like to avoid us having to craft custom structs every time we want to re-order columns.

Comment thread cli/provisionerjobs.go Resolved
Comment thread cli/provisionerjobs.go Outdated
Comment on lines +121 to +126
func convertSlice[D, S ~string](dstType []D, src []S) []D {
for _, item := range src {
dstType = append(dstType, D(item))
}
return dstType
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe throw this into slice as ToEnum 🤷‍♂️

Similar to ToStrings

// ToStrings works for any type where the base type is a string.
func ToStrings[T ~string](a []T) []string {
tmp := make([]string, 0, len(a))
for _, v := range a {
tmp = append(tmp, string(v))
}
return tmp
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can do 👍🏻

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, any good reason these utils under coderd? I wouldn't move it in this PR but could make it more accessible.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no good reason at all. I think it just grew over time

Version string `json:"version" table:"version"`
APIVersion string `json:"api_version" table:"api version"`
Provisioners []ProvisionerType `json:"provisioners" table:"-"`
Tags map[string]string `json:"tags" table:"tags"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not love this output: map[owner: scope:organization], but I'm ok with it.

We could have the table formatter know how to handle some basic types like map[string]string. Just leave it for this PR though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a similar thought, something human-readable and copy/paste friendly:

owner = (none)
scope = organization

Comment on lines +8 to +12
cmd := r.RootCmd.Provisioners()
cmd.AddSubcommands(
r.provisionerDaemonStart(),
r.provisionerKeys(),
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a crafty

),
Handler: func(inv *serpent.Invocation) error {
var closers closers
defer closers.Close()

@Emyrk Emyrk Dec 20, 2024 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, closers was a nice thought, but never closing the closers is quite the funny bug.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var losers closers
defer losers.Close()

:)

Comment thread coderd/coderd.go
Comment on lines +1010 to +1012
r.Route("/provisionerdaemons", func(r chi.Router) {
r.Get("/", api.provisionerDaemons)
})

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we add filtering by key, can we merge this with /organizations/{organization}/provisionerkeys/daemons? Or at least merge the code they both invoke? If possible, just to make sure we are consistent.

func (api *API) provisionerKeyDaemons(rw http.ResponseWriter, r *http.Request) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, I wasn't sure how much to move to AGPL vs enterprise but none of this code is critical to keep in enterprise 👍🏻

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally I think GET endpoints can be made AGPL, and POST/PATCH should be enterprise.

Comment thread cli/cliui/table.go
if val != nil {
v = val.Format(time.RFC3339)
}
case codersdk.NullTime:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: shouldn't we extract it to a separate PR?

Comment thread cli/provisionerjobs.go

jobs, err := client.OrganizationProvisionerJobs(ctx, org.ID, &codersdk.OrganizationProvisionerJobsOptions{
Status: slice.ToStringEnums[codersdk.ProvisionerJobStatus](status),
Limit: int(limit),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: paging?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to keep it simple for now, I realized we don't have a precedent on the CLI for paging so I didn't want to introduce it here. Granted --limit is also new, so I could remove that too but I was worried about how many entries there will be.

The original issue #15084 mentioned we should have "created at" (or rather "created after"), and I added that initially, but then I realized we don't have a precedent for filtering on time on the CLI either. (There's even a lack of serpent support there.) For this reason both pagination and created at filter have been omitted and should IMO be part of a grander plan for how to support these in a unified way on the CLI.

Comment on lines +2 to +3
==========[version job ID]========== ====[timestamp]===== succeeded map[owner: scope:organization] template_version_import Coder
======[workspace build job ID]====== ====[timestamp]===== succeeded map[owner: scope:organization] workspace_build Coder

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move "Queue" column to be the first one.

Comment on lines +467 to +469
if err != nil {
return "", nil, xerrors.Errorf("open container: %w", err)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: double-checking, is it intentional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, in some cases this will cause a nil pointer dereference otherwise.

// @Param tags query object false "Provisioner tags to filter by (JSON of the form {'tag1':'value1','tag2':'value2'})"
// @Success 200 {array} codersdk.ProvisionerDaemonWithStatus
// @Router /organizations/{organization}/provisionerdaemons [get]
func (api *API) provisionerDaemons(rw http.ResponseWriter, r *http.Request) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why endpoint changes and CLI go together? Alternatively, you could split the PR in half, and keep all golden files aside. Large PRs are typically a problem when somebody needs to revert them.

@mafredri mafredri Dec 23, 2024 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes and no, for development I'm working on them in tandem, CLI requirements have and keep resulted in API changes, etc. Stacking could be a better approach though.

I don't think the golden files should be separate as that would make the feature harder to revert, but API and CLI can definitely be.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be possible to have the DB stuff in its own PR and the CLI stuff then in a separate PR based off that. No need to have a really deep stack here IMO.

I'm fine with reviewing initially here "all-in-one".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Version string `json:"version" table:"version"`
APIVersion string `json:"api_version" table:"api version"`
Provisioners []ProvisionerType `json:"provisioners" table:"-"`
Tags map[string]string `json:"tags" table:"tags"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a similar thought, something human-readable and copy/paste friendly:

owner = (none)
scope = organization

Comment thread docs/manifest.json Outdated
Comment on lines +1149 to +1159
"path": "reference/cli/provisioner_keys.md"
"path": "reference/cli/provisioners_keys.md"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: renaming could go in a separate PR, right?

),
Handler: func(inv *serpent.Invocation) error {
var closers closers
defer closers.Close()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var losers closers
defer losers.Close()

:)

// We may in future decide to scope provisioner daemons to organizations, so we'll keep the API
// route as is.
r.Route("/organizations/{organization}/provisionerdaemons", func(r chi.Router) {
r.Route("/organizations/{organization}/provisionerdaemons/serve", func(r chi.Router) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: does this change give any special benefits? Most likely I'm missing something...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We removed the other endpoints from here that were under /organizations/{organization}/provisionerdaemons and only /organizations/{organization}/provisionerdaemons/serve remains. There's no reason to keep the broader one and IIRC it also interfered with the AGPL endpoint.

Comment on lines +48 to +54
if err != nil {
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
Message: "Internal error fetching provisioner daemons.",
Detail: err.Error(),
})
return
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: does sql.ErrNoRows need to be handled separately?

@github-actions github-actions Bot added the stale This issue is like stale bread. label Dec 31, 2024
@mafredri
mafredri force-pushed the mafredri/feat-provisioner-and-jobs-list branch 5 times, most recently from 5b54ed6 to 720b715 Compare December 31, 2024 13:11
@github-actions github-actions Bot removed the stale This issue is like stale bread. label Jan 1, 2025
@mafredri
mafredri force-pushed the mafredri/feat-provisioner-and-jobs-list branch from 720b715 to 24d49da Compare January 2, 2025 10:27
mafredri added a commit that referenced this pull request Jan 3, 2025
@github-actions github-actions Bot added the stale This issue is like stale bread. label Jan 10, 2025
@github-actions github-actions Bot closed this Jan 13, 2025
@johnstcn johnstcn reopened this Jan 13, 2025
@johnstcn johnstcn removed the stale This issue is like stale bread. label Jan 13, 2025
@mafredri

mafredri commented Jan 13, 2025 •

Copy link
Copy Markdown
Member Author

Closing this as it's split up into #16028, #16029 and #16030 (and a few other small PRs that fixed unrelated things).

@mafredri mafredri closed this Jan 13, 2025
@github-actions github-actions Bot locked and limited conversation to collaborators Jan 13, 2025
@mafredri
mafredri deleted the mafredri/feat-provisioner-and-jobs-list branch January 13, 2025 10:05
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

add CLI command to list provisioner jobs Add an API endpoint that lists all provisioner jobs.

4 participants