-
Notifications
You must be signed in to change notification settings - Fork 973
feat: add filtering options to provisioners list #19378
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
Conversation
@rafrdz Going to take a look no! For the chromatic tests we typically self check those to make sure we didn't accidentally introduce some glaring UI bug. So you can go through those yourself when you have a chance, but feel free to ping me if you're having issues on that front |
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.
Just a few small changes on the TS side. The backend changes look good to me but @Emyrk may want to take another look as well
...s/OrganizationSettingsPage/OrganizationProvisionersPage/OrganizationProvisionersPageView.tsx
Outdated
Show resolved
Hide resolved
...pages/OrganizationSettingsPage/OrganizationProvisionersPage/OrganizationProvisionersPage.tsx
Outdated
Show resolved
Hide resolved
...pages/OrganizationSettingsPage/OrganizationProvisionersPage/OrganizationProvisionersPage.tsx
Outdated
Show resolved
Hide resolved
...pages/OrganizationSettingsPage/OrganizationProvisionersPage/OrganizationProvisionersPage.tsx
Outdated
Show resolved
Hide resolved
...pages/OrganizationSettingsPage/OrganizationProvisionersPage/OrganizationProvisionersPage.tsx
Outdated
Show resolved
Hide resolved
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.
backend 👍
AND ( | ||
sqlc.narg('max_age_ms')::bigint IS NULL | ||
OR pd.last_seen_at IS NULL | ||
OR pd.last_seen_at >= (NOW() - (sqlc.narg('max_age_ms')::bigint || ' ms')::interval) | ||
) | ||
AND ( | ||
-- Always include online daemons | ||
(pd.last_seen_at IS NOT NULL AND pd.last_seen_at >= (NOW() - (@stale_interval_ms::bigint || ' ms')::interval)) | ||
-- Include offline daemons if offline param is true or 'offline' status is requested | ||
OR ( | ||
(pd.last_seen_at IS NULL OR pd.last_seen_at < (NOW() - (@stale_interval_ms::bigint || ' ms')::interval)) | ||
AND ( | ||
COALESCE(sqlc.narg('offline')::bool, false) = true | ||
OR 'offline'::provisioner_daemon_status = ANY(@statuses::provisioner_daemon_status[]) | ||
) | ||
) | ||
) | ||
AND ( | ||
-- Filter daemons by any statuses if provided | ||
COALESCE(array_length(@statuses::provisioner_daemon_status[], 1), 0) = 0 | ||
OR (current_job.id IS NOT NULL AND 'busy'::provisioner_daemon_status = ANY(@statuses::provisioner_daemon_status[])) | ||
OR (current_job.id IS NULL AND 'idle'::provisioner_daemon_status = ANY(@statuses::provisioner_daemon_status[])) | ||
OR ( | ||
'offline'::provisioner_daemon_status = ANY(@statuses::provisioner_daemon_status[]) | ||
AND (pd.last_seen_at IS NULL OR pd.last_seen_at < (NOW() - (@stale_interval_ms::bigint || ' ms')::interval)) | ||
) | ||
OR ( | ||
COALESCE(sqlc.narg('offline')::bool, false) = true | ||
AND (pd.last_seen_at IS NULL OR pd.last_seen_at < (NOW() - (@stale_interval_ms::bigint || ' ms')::interval)) | ||
) | ||
) |
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.
We usually do CASE ... WHEN
, but this works
// Package sdk2db provides common conversion routines from codersdk types to database types | ||
package sdk2db | ||
|
||
import ( | ||
"github.com/coder/coder/v2/coderd/database" | ||
"github.com/coder/coder/v2/coderd/database/db2sdk" | ||
"github.com/coder/coder/v2/codersdk" | ||
) | ||
|
||
func ProvisionerDaemonStatus(status codersdk.ProvisionerDaemonStatus) database.ProvisionerDaemonStatus { | ||
return database.ProvisionerDaemonStatus(status) | ||
} | ||
|
||
func ProvisionerDaemonStatuses(params []codersdk.ProvisionerDaemonStatus) []database.ProvisionerDaemonStatus { | ||
return db2sdk.List(params, ProvisionerDaemonStatus) | ||
} |
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.
👍
I bet we can move some things here 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.
frontend code looks good!
Summary
In this pull request we're adding support for additional filtering options to the
provisioners list
CLI command and the/provisionerdaemons
API endpoint.Resolves: #18783
Changes
Added CLI Options
--show-offline
: When this option is provided, all provisioner daemons will be returned. This means that when--show-offline
is not provided onlyidle
andbusy
provisioner daemons will be returned.--status=<list_of_statuses>
: When this option is provided with a comma-separated list of valid statuses (idle
,busy
, oroffline
) only provisioner daemons that have these statuses will be returned.--max-age=<duration>
: When this option is provided with a valid duration value (e.g.,24h
,30s
) only provisioner daemons with alast_seen_at
timestamp within the provided max age will be returned.Query Params
?offline=true
: Include offline provisioner daemons in the results. Offline provisioner daemons will be excluded if?offline=false
or if offline is not provided.?status=<list_of_statuses>
: Include provisioner daemons with the specified statuses.?max_age=<duration>
: Include provisioner daemons with alast_seen_at
timestamp within the max age duration.Frontend
--show-offline
has to be provided to see them), a checkbox was added to the provisioners list page to allow for offline provisioners to be displayedCurrent provisioners page (without checkbox)
Provisioners page with checkbox (unchecked)
Provisioner page with checkbox (checked) and URL updated with query parameters
Show Offline vs Offline Status
To list offline provisioner daemons, users can either:
--show-offline
optionOR
offline
in the list of values provided to the--status
option