Skip to content

Commit 568c16f

Browse files
committed
Fix response structure
1 parent 3d70b2a commit 568c16f

File tree

10 files changed

+138
-115
lines changed

10 files changed

+138
-115
lines changed

coderd/apidoc/docs.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/metricscache/metricscache.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -235,23 +235,26 @@ func (c *Cache) refreshDeploymentStats(ctx context.Context) error {
235235
c.deploymentStatsResponse.Store(&codersdk.DeploymentStats{
236236
AggregatedFrom: from,
237237
CollectedAt: database.Now(),
238-
RefreshingAt: database.Now().Add(c.intervals.DeploymentStats),
239-
WorkspaceConnectionLatencyMS: codersdk.WorkspaceConnectionLatencyMS{
240-
P50: agentStats.WorkspaceConnectionLatency50,
241-
P95: agentStats.WorkspaceConnectionLatency95,
238+
NextUpdateAt: database.Now().Add(c.intervals.DeploymentStats),
239+
Workspaces: codersdk.WorkspaceDeploymentStats{
240+
Pending: workspaceStats.PendingWorkspaces,
241+
Building: workspaceStats.BuildingWorkspaces,
242+
Running: workspaceStats.RunningWorkspaces,
243+
Failed: workspaceStats.FailedWorkspaces,
244+
Stopped: workspaceStats.StoppedWorkspaces,
245+
ConnectionLatencyMS: codersdk.WorkspaceConnectionLatencyMS{
246+
P50: agentStats.WorkspaceConnectionLatency50,
247+
P95: agentStats.WorkspaceConnectionLatency95,
248+
},
249+
RxBytes: agentStats.WorkspaceRxBytes,
250+
TxBytes: agentStats.WorkspaceTxBytes,
251+
},
252+
SessionCount: codersdk.SessionCountDeploymentStats{
253+
VSCode: agentStats.SessionCountVSCode,
254+
SSH: agentStats.SessionCountSSH,
255+
JetBrains: agentStats.SessionCountJetBrains,
256+
ReconnectingPTY: agentStats.SessionCountReconnectingPTY,
242257
},
243-
SessionCountVSCode: agentStats.SessionCountVSCode,
244-
SessionCountSSH: agentStats.SessionCountSSH,
245-
SessionCountJetBrains: agentStats.SessionCountJetBrains,
246-
SessionCountReconnectingPTY: agentStats.SessionCountReconnectingPTY,
247-
WorkspaceRxBytes: agentStats.WorkspaceRxBytes,
248-
WorkspaceTxBytes: agentStats.WorkspaceTxBytes,
249-
250-
PendingWorkspaces: workspaceStats.PendingWorkspaces,
251-
BuildingWorkspaces: workspaceStats.BuildingWorkspaces,
252-
RunningWorkspaces: workspaceStats.RunningWorkspaces,
253-
FailedWorkspaces: workspaceStats.FailedWorkspaces,
254-
StoppedWorkspaces: workspaceStats.StoppedWorkspaces,
255258
})
256259
return nil
257260
}

coderd/metricscache/metricscache_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,5 +399,5 @@ func TestCache_DeploymentStats(t *testing.T) {
399399
stat, ok = cache.DeploymentStats()
400400
return ok
401401
}, testutil.WaitLong, testutil.IntervalMedium)
402-
require.Equal(t, int64(1), stat.SessionCountVSCode)
402+
require.Equal(t, int64(1), stat.SessionCount.VSCode)
403403
}

codersdk/deployment.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,29 +1532,35 @@ type WorkspaceConnectionLatencyMS struct {
15321532
P95 float64
15331533
}
15341534

1535+
type WorkspaceDeploymentStats struct {
1536+
Pending int64 `json:"pending"`
1537+
Building int64 `json:"building"`
1538+
Running int64 `json:"running"`
1539+
Failed int64 `json:"failed"`
1540+
Stopped int64 `json:"stopped"`
1541+
1542+
ConnectionLatencyMS WorkspaceConnectionLatencyMS `json:"connection_latency_ms"`
1543+
RxBytes int64 `json:"rx_bytes"`
1544+
TxBytes int64 `json:"tx_bytes"`
1545+
}
1546+
1547+
type SessionCountDeploymentStats struct {
1548+
VSCode int64 `json:"vscode"`
1549+
SSH int64 `json:"ssh"`
1550+
JetBrains int64 `json:"jetbrains"`
1551+
ReconnectingPTY int64 `json:"reconnecting_pty"`
1552+
}
1553+
15351554
type DeploymentStats struct {
15361555
// AggregatedFrom is the time in which stats are aggregated from.
15371556
// This might be back in time a specific duration or interval.
1538-
AggregatedFrom time.Time `json:"aggregated_since" format:"date-time"`
1557+
AggregatedFrom time.Time `json:"aggregated_from" format:"date-time"`
15391558
// CollectedAt is the time in which stats are collected at.
15401559
CollectedAt time.Time `json:"collected_at" format:"date-time"`
1541-
// RefreshingAt is the time when the next batch of stats will
1542-
// be refreshed.
1543-
RefreshingAt time.Time `json:"refreshing_at" format:"date-time"`
1544-
1545-
PendingWorkspaces int64 `json:"pending_workspaces"`
1546-
BuildingWorkspaces int64 `json:"building_workspaces"`
1547-
RunningWorkspaces int64 `json:"running_workspaces"`
1548-
FailedWorkspaces int64 `json:"failed_workspaces"`
1549-
StoppedWorkspaces int64 `json:"stopped_workspaces"`
1550-
1551-
WorkspaceConnectionLatencyMS WorkspaceConnectionLatencyMS `json:"workspace_connection_latency_ms"`
1552-
1553-
SessionCountVSCode int64 `json:"session_count_vscode"`
1554-
SessionCountSSH int64 `json:"session_count_ssh"`
1555-
SessionCountJetBrains int64 `json:"session_count_jetbrains"`
1556-
SessionCountReconnectingPTY int64 `json:"session_count_reconnecting_pty"`
1560+
// NextUpdateAt is the time when the next batch of stats will
1561+
// be updated.
1562+
NextUpdateAt time.Time `json:"next_update_at" format:"date-time"`
15571563

1558-
WorkspaceRxBytes int64 `json:"workspace_rx_bytes"`
1559-
WorkspaceTxBytes int64 `json:"workspace_tx_bytes"`
1564+
Workspaces WorkspaceDeploymentStats `json:"workspaces"`
1565+
SessionCount SessionCountDeploymentStats `json:"session_count"`
15601566
}

docs/api/general.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,12 @@ curl -X GET http://coder-server:8080/api/v2/deployment/stats \
416416
417417
```json
418418
{
419-
"aggregated_since": "2019-08-24T14:15:22Z",
419+
"aggregated_from": "2019-08-24T14:15:22Z",
420420
"building_workspaces": 0,
421421
"collected_at": "2019-08-24T14:15:22Z",
422422
"failed_workspaces": 0,
423+
"next_update_at": "2019-08-24T14:15:22Z",
423424
"pending_workspaces": 0,
424-
"refreshing_at": "2019-08-24T14:15:22Z",
425425
"running_workspaces": 0,
426426
"session_count_jetbrains": 0,
427427
"session_count_reconnecting_pty": 0,

docs/api/schemas.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,12 +1951,12 @@ CreateParameterRequest is a structure used to create a new parameter value for a
19511951

19521952
```json
19531953
{
1954-
"aggregated_since": "2019-08-24T14:15:22Z",
1954+
"aggregated_from": "2019-08-24T14:15:22Z",
19551955
"building_workspaces": 0,
19561956
"collected_at": "2019-08-24T14:15:22Z",
19571957
"failed_workspaces": 0,
1958+
"next_update_at": "2019-08-24T14:15:22Z",
19581959
"pending_workspaces": 0,
1959-
"refreshing_at": "2019-08-24T14:15:22Z",
19601960
"running_workspaces": 0,
19611961
"session_count_jetbrains": 0,
19621962
"session_count_reconnecting_pty": 0,
@@ -1974,23 +1974,23 @@ CreateParameterRequest is a structure used to create a new parameter value for a
19741974

19751975
### Properties
19761976

1977-
| Name | Type | Required | Restrictions | Description |
1978-
| --------------------------------- | ------------------------------------------------------------------------------ | -------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------- |
1979-
| `aggregated_since` | string | false | | Aggregated since is the time in which stats are aggregated from. This might be back in time a specific duration or interval. |
1980-
| `building_workspaces` | integer | false | | |
1981-
| `collected_at` | string | false | | Collected at is the time in which stats are collected at. |
1982-
| `failed_workspaces` | integer | false | | |
1983-
| `pending_workspaces` | integer | false | | |
1984-
| `refreshing_at` | string | false | | Refreshing at is the time when the next batch of stats will be refreshed. |
1985-
| `running_workspaces` | integer | false | | |
1986-
| `session_count_jetbrains` | integer | false | | |
1987-
| `session_count_reconnecting_pty` | integer | false | | |
1988-
| `session_count_ssh` | integer | false | | |
1989-
| `session_count_vscode` | integer | false | | |
1990-
| `stopped_workspaces` | integer | false | | |
1991-
| `workspace_connection_latency_ms` | [codersdk.WorkspaceConnectionLatencyMS](#codersdkworkspaceconnectionlatencyms) | false | | |
1992-
| `workspace_rx_bytes` | integer | false | | |
1993-
| `workspace_tx_bytes` | integer | false | | |
1977+
| Name | Type | Required | Restrictions | Description |
1978+
| --------------------------------- | ------------------------------------------------------------------------------ | -------- | ------------ | --------------------------------------------------------------------------------------------------------------------------- |
1979+
| `aggregated_from` | string | false | | Aggregated from is the time in which stats are aggregated from. This might be back in time a specific duration or interval. |
1980+
| `building_workspaces` | integer | false | | |
1981+
| `collected_at` | string | false | | Collected at is the time in which stats are collected at. |
1982+
| `failed_workspaces` | integer | false | | |
1983+
| `next_update_at` | string | false | | Next update at is the time when the next batch of stats will be updated. |
1984+
| `pending_workspaces` | integer | false | | |
1985+
| `running_workspaces` | integer | false | | |
1986+
| `session_count_jetbrains` | integer | false | | |
1987+
| `session_count_reconnecting_pty` | integer | false | | |
1988+
| `session_count_ssh` | integer | false | | |
1989+
| `session_count_vscode` | integer | false | | |
1990+
| `stopped_workspaces` | integer | false | | |
1991+
| `workspace_connection_latency_ms` | [codersdk.WorkspaceConnectionLatencyMS](#codersdkworkspaceconnectionlatencyms) | false | | |
1992+
| `workspace_rx_bytes` | integer | false | | |
1993+
| `workspace_tx_bytes` | integer | false | | |
19941994

19951995
## codersdk.DeploymentValues
19961996

site/src/api/typesGenerated.ts

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -314,21 +314,11 @@ export interface DeploymentDAUsResponse {
314314

315315
// From codersdk/deployment.go
316316
export interface DeploymentStats {
317-
readonly aggregated_since: string
317+
readonly aggregated_from: string
318318
readonly collected_at: string
319-
readonly refreshing_at: string
320-
readonly pending_workspaces: number
321-
readonly building_workspaces: number
322-
readonly running_workspaces: number
323-
readonly failed_workspaces: number
324-
readonly stopped_workspaces: number
325-
readonly workspace_connection_latency_ms: WorkspaceConnectionLatencyMS
326-
readonly session_count_vscode: number
327-
readonly session_count_ssh: number
328-
readonly session_count_jetbrains: number
329-
readonly session_count_reconnecting_pty: number
330-
readonly workspace_rx_bytes: number
331-
readonly workspace_tx_bytes: number
319+
readonly next_update_at: string
320+
readonly workspaces: WorkspaceDeploymentStats
321+
readonly session_count: SessionCountDeploymentStats
332322
}
333323

334324
// From codersdk/deployment.go
@@ -753,6 +743,14 @@ export interface ServiceBannerConfig {
753743
readonly background_color?: string
754744
}
755745

746+
// From codersdk/deployment.go
747+
export interface SessionCountDeploymentStats {
748+
readonly vscode: number
749+
readonly ssh: number
750+
readonly jetbrains: number
751+
readonly reconnecting_pty: number
752+
}
753+
756754
// From codersdk/deployment.go
757755
export interface SupportConfig {
758756
// Named type "github.com/coder/coder/cli/clibase.Struct[[]github.com/coder/coder/codersdk.LinkConfig]" unknown, using "any"
@@ -1169,6 +1167,18 @@ export interface WorkspaceConnectionLatencyMS {
11691167
readonly P95: number
11701168
}
11711169

1170+
// From codersdk/deployment.go
1171+
export interface WorkspaceDeploymentStats {
1172+
readonly pending: number
1173+
readonly building: number
1174+
readonly running: number
1175+
readonly failed: number
1176+
readonly stopped: number
1177+
readonly connection_latency_ms: WorkspaceConnectionLatencyMS
1178+
readonly rx_bytes: number
1179+
readonly tx_bytes: number
1180+
}
1181+
11721182
// From codersdk/workspaces.go
11731183
export interface WorkspaceFilter {
11741184
readonly q?: string

0 commit comments

Comments
 (0)