Skip to content

chore: convert agent stats to use a table #6374

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 3 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix migration using default values
  • Loading branch information
kylecarbs committed Feb 28, 2023
commit 6769cf474107ddd412fc427cd39fba91c4a31eed
Original file line number Diff line number Diff line change
@@ -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;
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ALTER TABLE agent_stats
RENAME TO workspace_agent_stats;
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;
Expand All @@ -9,11 +8,11 @@ ALTER TABLE workspace_agent_stats ADD COLUMN tx_packets integer DEFAULT 0 NOT NU
ALTER TABLE workspace_agent_stats ADD COLUMN tx_bytes integer DEFAULT 0 NOT NULL;

UPDATE workspace_agent_stats SET
connections_by_proto = (payload ->> 'conns_by_proto')::jsonb,
connection_count = (payload ->> 'num_conns')::integer,
rx_packets = (payload ->> 'rx_packets')::integer,
rx_bytes = (payload ->> 'rx_bytes')::integer,
tx_packets = (payload ->> 'tx_packets')::integer,
tx_bytes = (payload ->> 'tx_bytes')::integer;
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;