mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat(coderd): add workspace timings endpoint (#14648)
This commit is contained in:
@@ -626,6 +626,35 @@ func (c *Client) UnfavoriteWorkspace(ctx context.Context, workspaceID uuid.UUID)
|
||||
return nil
|
||||
}
|
||||
|
||||
type ProvisionerTiming struct {
|
||||
JobID uuid.UUID `json:"job_id" format:"uuid"`
|
||||
StartedAt time.Time `json:"started_at" format:"date-time"`
|
||||
EndedAt time.Time `json:"ended_at" format:"date-time"`
|
||||
Stage string `json:"stage"`
|
||||
Source string `json:"source"`
|
||||
Action string `json:"action"`
|
||||
Resource string `json:"resource"`
|
||||
}
|
||||
|
||||
type WorkspaceTimings struct {
|
||||
ProvisionerTimings []ProvisionerTiming `json:"provisioner_timings"`
|
||||
// TODO: Add AgentScriptTimings when it is done https://github.com/coder/coder/issues/14630
|
||||
}
|
||||
|
||||
func (c *Client) WorkspaceTimings(ctx context.Context, id uuid.UUID) (WorkspaceTimings, error) {
|
||||
path := fmt.Sprintf("/api/v2/workspaces/%s/timings", id.String())
|
||||
res, err := c.Request(ctx, http.MethodGet, path, nil)
|
||||
if err != nil {
|
||||
return WorkspaceTimings{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return WorkspaceTimings{}, ReadBodyAsError(res)
|
||||
}
|
||||
var timings WorkspaceTimings
|
||||
return timings, json.NewDecoder(res.Body).Decode(&timings)
|
||||
}
|
||||
|
||||
// WorkspaceNotifyChannel is the PostgreSQL NOTIFY
|
||||
// channel to listen for updates on. The payload is empty,
|
||||
// because the size of a workspace payload can be very large.
|
||||
|
||||
Reference in New Issue
Block a user