From 31640a3b937632ddb45d8207b7f61c8fceb5eaeb Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 28 Feb 2023 19:52:09 +0000 Subject: [PATCH] fix: use bigint instead of integer in stats migration This broke dogfood! --- coderd/database/dump.sql | 10 +++++----- ...0101_workspace_agent_stats_tableify.up.sql | 20 +++++++++---------- coderd/database/models.go | 10 +++++----- coderd/database/queries.sql.go | 10 +++++----- coderd/workspaceagents.go | 10 +++++----- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/coderd/database/dump.sql b/coderd/database/dump.sql index afb2137a4bce7..e182ad382370e 100644 --- a/coderd/database/dump.sql +++ b/coderd/database/dump.sql @@ -470,11 +470,11 @@ CREATE TABLE workspace_agent_stats ( workspace_id uuid NOT NULL, template_id uuid NOT NULL, connections_by_proto jsonb DEFAULT '{}'::jsonb NOT NULL, - connection_count integer DEFAULT 0 NOT NULL, - rx_packets integer DEFAULT 0 NOT NULL, - rx_bytes integer DEFAULT 0 NOT NULL, - tx_packets integer DEFAULT 0 NOT NULL, - tx_bytes integer DEFAULT 0 NOT NULL + connection_count bigint DEFAULT 0 NOT NULL, + rx_packets bigint DEFAULT 0 NOT NULL, + rx_bytes bigint DEFAULT 0 NOT NULL, + tx_packets bigint DEFAULT 0 NOT NULL, + tx_bytes bigint DEFAULT 0 NOT NULL ); CREATE TABLE workspace_agents ( diff --git a/coderd/database/migrations/000101_workspace_agent_stats_tableify.up.sql b/coderd/database/migrations/000101_workspace_agent_stats_tableify.up.sql index f1999ae8b96d7..9e10bdb8c8c46 100644 --- a/coderd/database/migrations/000101_workspace_agent_stats_tableify.up.sql +++ b/coderd/database/migrations/000101_workspace_agent_stats_tableify.up.sql @@ -1,18 +1,18 @@ ALTER TABLE agent_stats RENAME TO workspace_agent_stats; ALTER TABLE workspace_agent_stats ADD COLUMN connections_by_proto jsonb NOT NULL DEFAULT '{}'::jsonb; -ALTER TABLE workspace_agent_stats ADD COLUMN connection_count integer DEFAULT 0 NOT NULL; -ALTER TABLE workspace_agent_stats ADD COLUMN rx_packets integer DEFAULT 0 NOT NULL; -ALTER TABLE workspace_agent_stats ADD COLUMN rx_bytes integer DEFAULT 0 NOT NULL; -ALTER TABLE workspace_agent_stats ADD COLUMN tx_packets integer DEFAULT 0 NOT NULL; -ALTER TABLE workspace_agent_stats ADD COLUMN tx_bytes integer DEFAULT 0 NOT NULL; +ALTER TABLE workspace_agent_stats ADD COLUMN connection_count bigint DEFAULT 0 NOT NULL; +ALTER TABLE workspace_agent_stats ADD COLUMN rx_packets bigint DEFAULT 0 NOT NULL; +ALTER TABLE workspace_agent_stats ADD COLUMN rx_bytes bigint DEFAULT 0 NOT NULL; +ALTER TABLE workspace_agent_stats ADD COLUMN tx_packets bigint DEFAULT 0 NOT NULL; +ALTER TABLE workspace_agent_stats ADD COLUMN tx_bytes bigint DEFAULT 0 NOT NULL; UPDATE workspace_agent_stats SET connections_by_proto = coalesce((payload ->> 'conns_by_proto')::jsonb, '{}'::jsonb), - connection_count = coalesce((payload ->> 'num_conns')::integer, 0), - rx_packets = coalesce((payload ->> 'rx_packets')::integer, 0), - rx_bytes = coalesce((payload ->> 'rx_bytes')::integer, 0), - tx_packets = coalesce((payload ->> 'tx_packets')::integer, 0), - tx_bytes = coalesce((payload ->> 'tx_bytes')::integer, 0); + connection_count = coalesce((payload ->> 'num_conns')::bigint, 0), + rx_packets = coalesce((payload ->> 'rx_packets')::bigint, 0), + rx_bytes = coalesce((payload ->> 'rx_bytes')::bigint, 0), + tx_packets = coalesce((payload ->> 'tx_packets')::bigint, 0), + tx_bytes = coalesce((payload ->> 'tx_bytes')::bigint, 0); ALTER TABLE workspace_agent_stats DROP COLUMN payload; diff --git a/coderd/database/models.go b/coderd/database/models.go index cdf65fd571c11..1467b95ef1e0e 100644 --- a/coderd/database/models.go +++ b/coderd/database/models.go @@ -1556,11 +1556,11 @@ type WorkspaceAgentStat struct { WorkspaceID uuid.UUID `db:"workspace_id" json:"workspace_id"` TemplateID uuid.UUID `db:"template_id" json:"template_id"` ConnectionsByProto json.RawMessage `db:"connections_by_proto" json:"connections_by_proto"` - ConnectionCount int32 `db:"connection_count" json:"connection_count"` - RxPackets int32 `db:"rx_packets" json:"rx_packets"` - RxBytes int32 `db:"rx_bytes" json:"rx_bytes"` - TxPackets int32 `db:"tx_packets" json:"tx_packets"` - TxBytes int32 `db:"tx_bytes" json:"tx_bytes"` + ConnectionCount int64 `db:"connection_count" json:"connection_count"` + RxPackets int64 `db:"rx_packets" json:"rx_packets"` + RxBytes int64 `db:"rx_bytes" json:"rx_bytes"` + TxPackets int64 `db:"tx_packets" json:"tx_packets"` + TxBytes int64 `db:"tx_bytes" json:"tx_bytes"` } type WorkspaceApp struct { diff --git a/coderd/database/queries.sql.go b/coderd/database/queries.sql.go index ab04330b34f10..c05b97727a368 100644 --- a/coderd/database/queries.sql.go +++ b/coderd/database/queries.sql.go @@ -5430,11 +5430,11 @@ type InsertWorkspaceAgentStatParams struct { TemplateID uuid.UUID `db:"template_id" json:"template_id"` AgentID uuid.UUID `db:"agent_id" json:"agent_id"` ConnectionsByProto json.RawMessage `db:"connections_by_proto" json:"connections_by_proto"` - ConnectionCount int32 `db:"connection_count" json:"connection_count"` - RxPackets int32 `db:"rx_packets" json:"rx_packets"` - RxBytes int32 `db:"rx_bytes" json:"rx_bytes"` - TxPackets int32 `db:"tx_packets" json:"tx_packets"` - TxBytes int32 `db:"tx_bytes" json:"tx_bytes"` + ConnectionCount int64 `db:"connection_count" json:"connection_count"` + RxPackets int64 `db:"rx_packets" json:"rx_packets"` + RxBytes int64 `db:"rx_bytes" json:"rx_bytes"` + TxPackets int64 `db:"tx_packets" json:"tx_packets"` + TxBytes int64 `db:"tx_bytes" json:"tx_bytes"` } func (q *sqlQuerier) InsertWorkspaceAgentStat(ctx context.Context, arg InsertWorkspaceAgentStatParams) (WorkspaceAgentStat, error) { diff --git a/coderd/workspaceagents.go b/coderd/workspaceagents.go index f3faf9a3be6fd..38fb311a4441d 100644 --- a/coderd/workspaceagents.go +++ b/coderd/workspaceagents.go @@ -948,11 +948,11 @@ func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Reques UserID: workspace.OwnerID, TemplateID: workspace.TemplateID, ConnectionsByProto: payload, - ConnectionCount: int32(req.ConnectionCount), - RxPackets: int32(req.RxPackets), - RxBytes: int32(req.RxBytes), - TxPackets: int32(req.TxPackets), - TxBytes: int32(req.TxBytes), + ConnectionCount: req.ConnectionCount, + RxPackets: req.RxPackets, + RxBytes: req.RxBytes, + TxPackets: req.TxPackets, + TxBytes: req.TxBytes, }) if err != nil { httpapi.InternalServerError(rw, err)