Skip to content

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

Merged
merged 13 commits into from
Aug 21, 2025

Conversation

rafrdz
Copy link
Contributor

@rafrdz rafrdz commented Aug 15, 2025

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 only idle and busy provisioner daemons will be returned.
  • --status=<list_of_statuses>: When this option is provided with a comma-separated list of valid statuses (idle, busy, or offline) 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 a last_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 a last_seen_at timestamp within the max age duration.

Frontend

  • Since offline provisioners will not be returned by default anymore (--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 displayed

Current provisioners page (without checkbox)

Screenshot 2025-08-20 at 10 51 00 AM

Provisioners page with checkbox (unchecked)

Screenshot 2025-08-20 at 10 48 40 AM

Provisioner page with checkbox (checked) and URL updated with query parameters

Screenshot 2025-08-20 at 10 50 14 AM

Show Offline vs Offline Status

To list offline provisioner daemons, users can either:

  1. Include the --show-offline option

OR

  1. Include offline in the list of values provided to the --status option

@rafrdz rafrdz marked this pull request as draft August 15, 2025 21:26
@rafrdz rafrdz marked this pull request as ready for review August 20, 2025 16:43
@rafrdz rafrdz requested a review from aslilac as a code owner August 20, 2025 16:43
@rafrdz rafrdz requested review from Emyrk, a team, brettkolodny and aslilac and removed request for aslilac and a team August 20, 2025 16:43
@brettkolodny
Copy link
Contributor

@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

Copy link
Contributor

@brettkolodny brettkolodny left a 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

Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

backend 👍

Comment on lines +114 to +144
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))
)
)
Copy link
Member

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

Comment on lines +1 to +16
// 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)
}
Copy link
Member

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

@rafrdz rafrdz requested a review from brettkolodny August 20, 2025 20:38
Copy link
Member

@aslilac aslilac left a 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!

@brettkolodny brettkolodny merged commit ad5e678 into main Aug 21, 2025
36 checks passed
@brettkolodny brettkolodny deleted the rafrdz/offline-provisioners branch August 21, 2025 20:03
@github-actions github-actions bot locked and limited conversation to collaborators Aug 21, 2025
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.

Feature Request: Improve Provisioner List Display and Filtering
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy