1.20. 恢复合规性数据
Grafana Datasource 主要来自名为 history.local_compliance 的表中。其记录由一个总结例程生成,该例程在每天的 00:00:00 开始。您通常不需要手动运行摘要过程。在某些情况下,运行合规作业时可能会出现意外错误,因此需要手动登录到数据库以运行整个摘要过程来恢复未生成的数据。您可以按照 手动运行 summarization 中的步骤来恢复数据。
1.20.1. 可选:手动将现有表升级到分区表 复制链接链接已复制到粘贴板!
如果您在 GA 之前安装了多集群全局 hub 的早期版本,则需要升级表使其与当前多集群全局 hub operator 兼容。升级的主要目的是将 event.local_policies、event.local_root_policies 和 history.local_compliance 表转换为分区表。
以下示例显示了使用 2023-08 设置的日期的 event.local_policies 表转换。其他两个表的升级步骤类似。
确保目标已分区。
SELECT relname, relkind FROM pg_class WHERE relname = 'local_policies';表输出类似以下示例:
Expand relname
relkind
local_policies
r
如果
relkind是p,则当前表将被分区。如果是,您可以跳过剩余的步骤并升级其他表。将常规表转换为分区表。
-- start a transaction BEGIN; -- Rename the legacy TABLE_NAME ALTER TABLE event.local_policies RENAME TO local_policies_old; -- Partition tables: https://github.com/stolostron/multicluster-global-hub/blob/main/operator/pkg/controllers/hubofhubs/database/2.tables.sql#L283-L318 CREATE TABLE IF NOT EXISTS event.local_policies ( event_name character varying(63) NOT NULL, policy_id uuid NOT NULL, cluster_id uuid NOT NULL, leaf_hub_name character varying(63) NOT NULL, message text, reason text, count integer NOT NULL DEFAULT 0, source jsonb, created_at timestamp without time zone DEFAULT now() NOT NULL, compliance local_status.compliance_type NOT NULL, -- Rename the constraint to avoid conflicts CONSTRAINT local_policies_unique_partition_constraint UNIQUE (event_name, count, created_at) ) PARTITION BY RANGE (created_at); -- Create partitions, load the old data to the previous partition table CREATE TABLE IF NOT EXISTS event.local_policies_2023_08 PARTITION OF event.local_policies FOR VALUES FROM ('2023-08-01') TO ('2023-09-01'); CREATE TABLE IF NOT EXISTS event.local_policies_2023_07 PARTITION OF event.local_policies FOR VALUES FROM ('2000-01-01') TO ('2023-08-01'); -- Move the records from regular table to partition table INSERT INTO event.local_policies SELECT * FROM event.local_polcies_old; DROP TABLE IF EXISTS event.local_policies_old; -- commit the transaction COMMIT;您可以根据表名称和当前日期替换以下值:
-
event.local_policies_2023_08是带有当前月份作为后缀的分区名称,例如这个示例中的 8 月 -
'2023-08-01'和'2023-09-01'是当前月份分区的最小和最大界限 -
event.local_policies_2023_07是 之前月份的后缀(July)的分区名称 -
'2000-01-01'和'2023-08-01'以前月分区的最小和最大边界
-