mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: convert agent stats to use a table (#6374)
* chore: convert workspace agent stats from json to table * chore: convert agent stats to use a table Backwards compatibility becomes hard when all agent stats are in a JSON blob. We also want to query this table for new agents that are failing health checks so we can display it in the UI. * Fix migration using default values
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
ALTER TABLE workspace_agent_stats RENAME TO agent_stats;
|
||||
|
||||
ALTER TABLE agent_stats ADD COLUMN payload jsonb NOT NULL DEFAULT '{}'::jsonb;
|
||||
ALTER TABLE agent_stats DROP COLUMN connections_by_proto,
|
||||
DROP COLUMN connection_count,
|
||||
DROP COLUMN rx_packets,
|
||||
DROP COLUMN rx_bytes,
|
||||
DROP COLUMN tx_packets,
|
||||
DROP COLUMN tx_bytes;
|
||||
@@ -0,0 +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;
|
||||
|
||||
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);
|
||||
|
||||
ALTER TABLE workspace_agent_stats DROP COLUMN payload;
|
||||
Reference in New Issue
Block a user