From 7c26a8ac3efc232cbeabeb6c687f951111a6f526 Mon Sep 17 00:00:00 2001 From: Zarina Yakubova Date: Tue, 22 Oct 2024 16:27:16 +0200 Subject: [PATCH] fix(#5658): Fix instruction stats --- ...on_execution_by_modified_on_table.down.sql | 58 ++++++++++++++++++ ...tion_execution_by_modified_on_table.up.sql | 60 +++++++++++++++++++ ...down.sql => 22_serial_name_table.down.sql} | 0 ...ble.up.sql => 22_serial_name_table.up.sql} | 0 ...ql => 23_create_action_log_table.down.sql} | 0 ....sql => 23_create_action_log_table.up.sql} | 0 6 files changed, 118 insertions(+) create mode 100644 community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.down.sql create mode 100644 community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.up.sql rename community/go-engines-community/database/postgres_migrations/{21_serial_name_table.down.sql => 22_serial_name_table.down.sql} (100%) rename community/go-engines-community/database/postgres_migrations/{21_serial_name_table.up.sql => 22_serial_name_table.up.sql} (100%) rename community/go-engines-community/database/postgres_migrations/{22_create_action_log_table.down.sql => 23_create_action_log_table.down.sql} (100%) rename community/go-engines-community/database/postgres_migrations/{22_create_action_log_table.up.sql => 23_create_action_log_table.up.sql} (100%) diff --git a/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.down.sql b/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.down.sql new file mode 100644 index 0000000000..e44cd81919 --- /dev/null +++ b/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.down.sql @@ -0,0 +1,58 @@ +BEGIN; + +DROP INDEX IF EXISTS instruction_execution_by_modified_on_instruction_updated_time_idx; +ALTER TABLE instruction_execution_by_modified_on RENAME TO instruction_execution_by_modified_on_to_remove; + +CREATE TABLE IF NOT EXISTS instruction_execution_by_modified_on +( + time TIMESTAMP NOT NULL, + instruction VARCHAR(500) NOT NULL, + execution_count INT NOT NULL, + successful INT NOT NULL, + avg_complete_time INT NOT NULL, + init_critical INT NOT NULL DEFAULT 0, + init_major INT NOT NULL DEFAULT 0, + init_minor INT NOT NULL DEFAULT 0, + res_critical INT NOT NULL DEFAULT 0, + res_major INT NOT NULL DEFAULT 0, + res_minor INT NOT NULL DEFAULT 0, + res_ok INT NOT NULL DEFAULT 0 +); +SELECT create_hypertable('instruction_execution_by_modified_on', 'time', if_not_exists => TRUE); + +INSERT INTO instruction_execution_by_modified_on +( + time, + instruction, + execution_count, + successful, + avg_complete_time, + init_critical, + init_major, + init_minor, + res_critical, + res_major, + res_minor, + res_ok +) +SELECT + instruction_updated as time, + instruction, + SUM(execution_count), + SUM(successful), + AVG(avg_complete_time), + SUM(init_critical), + SUM(init_major), + SUM(init_minor), + SUM(res_critical), + SUM(res_major), + SUM(res_minor), + SUM(res_ok) +FROM instruction_execution_by_modified_on_to_remove +GROUP BY instruction, instruction_updated; + +CREATE UNIQUE INDEX idx_instruction_time ON instruction_execution_by_modified_on (instruction, time); + +DROP TABLE instruction_execution_by_modified_on_to_remove; + +COMMIT; diff --git a/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.up.sql b/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.up.sql new file mode 100644 index 0000000000..35ebcda5c0 --- /dev/null +++ b/community/go-engines-community/database/postgres_migrations/21_alter_instruction_execution_by_modified_on_table.up.sql @@ -0,0 +1,60 @@ +BEGIN; + +DROP INDEX IF EXISTS idx_instruction_time; +ALTER TABLE instruction_execution_by_modified_on RENAME TO instruction_execution_by_modified_on_to_remove; + +CREATE TABLE IF NOT EXISTS instruction_execution_by_modified_on +( + time TIMESTAMP NOT NULL, + instruction_updated TIMESTAMP NOT NULL, + instruction VARCHAR(500) NOT NULL, + execution_count INT NOT NULL, + successful INT NOT NULL, + avg_complete_time INT NOT NULL, + init_critical INT NOT NULL DEFAULT 0, + init_major INT NOT NULL DEFAULT 0, + init_minor INT NOT NULL DEFAULT 0, + res_critical INT NOT NULL DEFAULT 0, + res_major INT NOT NULL DEFAULT 0, + res_minor INT NOT NULL DEFAULT 0, + res_ok INT NOT NULL DEFAULT 0 +); +SELECT create_hypertable('instruction_execution_by_modified_on', 'time', if_not_exists => TRUE); + +INSERT INTO instruction_execution_by_modified_on +( + time, + instruction_updated, + instruction, + execution_count, + successful, + avg_complete_time, + init_critical, + init_major, + init_minor, + res_critical, + res_major, + res_minor, + res_ok +) +SELECT + NOW()::date as time, + time as instruction_updated, + instruction, + execution_count, + successful, + avg_complete_time, + init_critical, + init_major, + init_minor, + res_critical, + res_major, + res_minor, + res_ok +FROM instruction_execution_by_modified_on_to_remove; + +CREATE UNIQUE INDEX instruction_execution_by_modified_on_instruction_updated_time_idx ON instruction_execution_by_modified_on (instruction, instruction_updated, time); + +DROP TABLE instruction_execution_by_modified_on_to_remove; + +COMMIT; diff --git a/community/go-engines-community/database/postgres_migrations/21_serial_name_table.down.sql b/community/go-engines-community/database/postgres_migrations/22_serial_name_table.down.sql similarity index 100% rename from community/go-engines-community/database/postgres_migrations/21_serial_name_table.down.sql rename to community/go-engines-community/database/postgres_migrations/22_serial_name_table.down.sql diff --git a/community/go-engines-community/database/postgres_migrations/21_serial_name_table.up.sql b/community/go-engines-community/database/postgres_migrations/22_serial_name_table.up.sql similarity index 100% rename from community/go-engines-community/database/postgres_migrations/21_serial_name_table.up.sql rename to community/go-engines-community/database/postgres_migrations/22_serial_name_table.up.sql diff --git a/community/go-engines-community/database/postgres_migrations/22_create_action_log_table.down.sql b/community/go-engines-community/database/postgres_migrations/23_create_action_log_table.down.sql similarity index 100% rename from community/go-engines-community/database/postgres_migrations/22_create_action_log_table.down.sql rename to community/go-engines-community/database/postgres_migrations/23_create_action_log_table.down.sql diff --git a/community/go-engines-community/database/postgres_migrations/22_create_action_log_table.up.sql b/community/go-engines-community/database/postgres_migrations/23_create_action_log_table.up.sql similarity index 100% rename from community/go-engines-community/database/postgres_migrations/22_create_action_log_table.up.sql rename to community/go-engines-community/database/postgres_migrations/23_create_action_log_table.up.sql