From e122cebf3f2e598e9c32ace49fe1a42bf5c5225a Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Thu, 15 Aug 2024 18:14:59 +0200 Subject: [PATCH] schema: Enlarge Command Argument and Environment Key From the beginning, the Icinga DB's schema allowed 64 characters for both the command arguments and environment variable names[0]. In particular, this affects CheckCommand, EventCommand and NotificationCommand Icinga 2 objects. But if a command with either an argument key or an environment variable that is longer than 64 characters was defined in Icinga 2, Icinga DB will try to insert it into the database and may end up crashing. Although it may seem large enough, it is sometimes exceeded. After evaluating that there was no technical limitation[1], the limit was increased to 255 characters. This limit was chosen over the wider text type as it allows indexes in the future and requires less space. For example, the following CheckCommand was not possible before: > object CheckCommand "icingadb-i791" { > import "plugin-check-command" > command = [ "/bin/true" ] > env = { > "THAT_ARE_64_AS_WOW_AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" = "huhu" > } > arguments = { > "java.class.that.was.used.as.an.argument.that.was.eighty.seven.characters.long.and.broke" = { > value = "F" > } > } > } Another thing was a type difference between the MySQL and PostgreSQL schemas. While the MySQL schema defined argument_key_override as varchar(64), in PostgreSQL it was a citext. So it was changed to varchar(255) in MySQL and kept as it was in PostgreSQL. Closes #791. [0]: https://github.com/Icinga/icingadb/commit/05d5e97dd5b73d0792e3416fd66b9257b752fd0c [1]: https://github.com/Icinga/icingadb/issues/791#issuecomment-2291326687 --- schema/mysql/schema.sql | 18 +++++++++--------- schema/mysql/upgrades/1.3.0.sql | 11 +++++++++++ schema/pgsql/schema.sql | 12 ++++++------ schema/pgsql/upgrades/1.3.0.sql | 8 ++++++++ 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/schema/mysql/schema.sql b/schema/mysql/schema.sql index f270d2b74..a1db99084 100644 --- a/schema/mysql/schema.sql +++ b/schema/mysql/schema.sql @@ -562,14 +562,14 @@ CREATE TABLE checkcommand_argument ( id binary(20) NOT NULL COMMENT 'sha1(environment.id + checkcommand_id + argument_key)', environment_id binary(20) NOT NULL COMMENT 'env.id', checkcommand_id binary(20) NOT NULL COMMENT 'checkcommand.id', - argument_key varchar(64) NOT NULL, + argument_key varchar(255) NOT NULL, properties_checksum binary(20) NOT NULL COMMENT 'sha1(all properties)', argument_value text DEFAULT NULL, argument_order smallint DEFAULT NULL, description text DEFAULT NULL, - argument_key_override varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + argument_key_override varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, repeat_key enum('n', 'y') NOT NULL, required enum('n', 'y') NOT NULL, set_if varchar(255) DEFAULT NULL, @@ -583,7 +583,7 @@ CREATE TABLE checkcommand_envvar ( id binary(20) NOT NULL COMMENT 'sha1(environment.id + checkcommand_id + envvar_key)', environment_id binary(20) NOT NULL COMMENT 'env.id', checkcommand_id binary(20) NOT NULL COMMENT 'checkcommand.id', - envvar_key varchar(64) NOT NULL, + envvar_key varchar(255) NOT NULL, properties_checksum binary(20) NOT NULL COMMENT 'sha1(all properties)', @@ -626,14 +626,14 @@ CREATE TABLE eventcommand_argument ( id binary(20) NOT NULL COMMENT 'sha1(environment.id + eventcommand_id + argument_key)', environment_id binary(20) NOT NULL COMMENT 'env.id', eventcommand_id binary(20) NOT NULL COMMENT 'eventcommand.id', - argument_key varchar(64) NOT NULL, + argument_key varchar(255) NOT NULL, properties_checksum binary(20) NOT NULL COMMENT 'sha1(all properties)', argument_value text DEFAULT NULL, argument_order smallint DEFAULT NULL, description text DEFAULT NULL, - argument_key_override varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + argument_key_override varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, repeat_key enum('n', 'y') NOT NULL, required enum('n', 'y') NOT NULL, set_if varchar(255) DEFAULT NULL, @@ -647,7 +647,7 @@ CREATE TABLE eventcommand_envvar ( id binary(20) NOT NULL COMMENT 'sha1(environment.id + eventcommand_id + envvar_key)', environment_id binary(20) NOT NULL COMMENT 'env.id', eventcommand_id binary(20) NOT NULL COMMENT 'eventcommand.id', - envvar_key varchar(64) NOT NULL, + envvar_key varchar(255) NOT NULL, properties_checksum binary(20) NOT NULL COMMENT 'sha1(all properties)', @@ -688,14 +688,14 @@ CREATE TABLE notificationcommand_argument ( id binary(20) NOT NULL COMMENT 'sha1(environment.id + notificationcommand_id + argument_key)', environment_id binary(20) NOT NULL COMMENT 'env.id', notificationcommand_id binary(20) NOT NULL COMMENT 'notificationcommand.id', - argument_key varchar(64) NOT NULL, + argument_key varchar(255) NOT NULL, properties_checksum binary(20) NOT NULL COMMENT 'sha1(all properties)', argument_value text DEFAULT NULL, argument_order smallint DEFAULT NULL, description text DEFAULT NULL, - argument_key_override varchar(64) COLLATE utf8mb4_unicode_ci DEFAULT NULL, + argument_key_override varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL, repeat_key enum('n', 'y') NOT NULL, required enum('n', 'y') NOT NULL, set_if varchar(255) DEFAULT NULL, @@ -709,7 +709,7 @@ CREATE TABLE notificationcommand_envvar ( id binary(20) NOT NULL COMMENT 'sha1(environment.id + notificationcommand_id + envvar_key)', environment_id binary(20) NOT NULL COMMENT 'env.id', notificationcommand_id binary(20) NOT NULL COMMENT 'notificationcommand.id', - envvar_key varchar(64) NOT NULL, + envvar_key varchar(255) NOT NULL, properties_checksum binary(20) NOT NULL COMMENT 'sha1(all properties)', diff --git a/schema/mysql/upgrades/1.3.0.sql b/schema/mysql/upgrades/1.3.0.sql index ed86c6e72..047903807 100644 --- a/schema/mysql/upgrades/1.3.0.sql +++ b/schema/mysql/upgrades/1.3.0.sql @@ -7,5 +7,16 @@ ALTER TABLE notification MODIFY COLUMN properties_checksum binary(20) NOT NULL C ALTER TABLE timeperiod_range MODIFY COLUMN range_value text NOT NULL; +ALTER TABLE checkcommand_argument MODIFY COLUMN argument_key varchar(255) NOT NULL; +ALTER TABLE checkcommand_argument MODIFY COLUMN argument_key_override varchar(255) NOT NULL; +ALTER TABLE eventcommand_argument MODIFY COLUMN argument_key varchar(255) NOT NULL; +ALTER TABLE eventcommand_argument MODIFY COLUMN argument_key_override varchar(255) NOT NULL; +ALTER TABLE notificationcommand_argument MODIFY COLUMN argument_key varchar(255) NOT NULL; +ALTER TABLE notificationcommand_argument MODIFY COLUMN argument_key_override varchar(255) NOT NULL; + +ALTER TABLE checkcommand_envvar MODIFY COLUMN envvar_key varchar(255) NOT NULL; +ALTER TABLE eventcommand_envvar MODIFY COLUMN envvar_key varchar(255) NOT NULL; +ALTER TABLE notificationcommand_envvar MODIFY COLUMN envvar_key varchar(255) NOT NULL; + INSERT INTO icingadb_schema (version, timestamp) VALUES (6, UNIX_TIMESTAMP() * 1000); diff --git a/schema/pgsql/schema.sql b/schema/pgsql/schema.sql index 78db645f0..a68d41a1d 100644 --- a/schema/pgsql/schema.sql +++ b/schema/pgsql/schema.sql @@ -835,7 +835,7 @@ CREATE TABLE checkcommand_argument ( id bytea20 NOT NULL, environment_id bytea20 NOT NULL, checkcommand_id bytea20 NOT NULL, - argument_key varchar(64) NOT NULL, + argument_key varchar(255) NOT NULL, properties_checksum bytea20 NOT NULL, @@ -867,7 +867,7 @@ CREATE TABLE checkcommand_envvar ( id bytea20 NOT NULL, environment_id bytea20 NOT NULL, checkcommand_id bytea20 NOT NULL, - envvar_key varchar(64) NOT NULL, + envvar_key varchar(255) NOT NULL, properties_checksum bytea20 NOT NULL, @@ -941,7 +941,7 @@ CREATE TABLE eventcommand_argument ( id bytea20 NOT NULL, environment_id bytea20 NOT NULL, eventcommand_id bytea20 NOT NULL, - argument_key varchar(64) NOT NULL, + argument_key varchar(255) NOT NULL, properties_checksum bytea20 NOT NULL, @@ -972,7 +972,7 @@ CREATE TABLE eventcommand_envvar ( id bytea20 NOT NULL, environment_id bytea20 NOT NULL, eventcommand_id bytea20 NOT NULL, - envvar_key varchar(64) NOT NULL, + envvar_key varchar(255) NOT NULL, properties_checksum bytea20 NOT NULL, @@ -1045,7 +1045,7 @@ CREATE TABLE notificationcommand_argument ( id bytea20 NOT NULL, environment_id bytea20 NOT NULL, notificationcommand_id bytea20 NOT NULL, - argument_key varchar(64) NOT NULL, + argument_key varchar(255) NOT NULL, properties_checksum bytea20 NOT NULL, @@ -1076,7 +1076,7 @@ CREATE TABLE notificationcommand_envvar ( id bytea20 NOT NULL, environment_id bytea20 NOT NULL, notificationcommand_id bytea20 NOT NULL, - envvar_key varchar(64) NOT NULL, + envvar_key varchar(255) NOT NULL, properties_checksum bytea20 NOT NULL, diff --git a/schema/pgsql/upgrades/1.3.0.sql b/schema/pgsql/upgrades/1.3.0.sql index 5989e3a77..80d75f5d3 100644 --- a/schema/pgsql/upgrades/1.3.0.sql +++ b/schema/pgsql/upgrades/1.3.0.sql @@ -7,5 +7,13 @@ COMMENT ON COLUMN notification.properties_checksum IS 'sha1(all properties)'; ALTER TABLE timeperiod_range ALTER COLUMN range_value TYPE text; +ALTER TABLE checkcommand_argument ALTER COLUMN argument_key TYPE varchar(255); +ALTER TABLE eventcommand_argument ALTER COLUMN argument_key TYPE varchar(255); +ALTER TABLE notificationcommand_argument ALTER COLUMN argument_key TYPE varchar(255); + +ALTER TABLE checkcommand_envvar ALTER COLUMN envvar_key TYPE varchar(255); +ALTER TABLE eventcommand_envvar ALTER COLUMN envvar_key TYPE varchar(255); +ALTER TABLE notificationcommand_envvar ALTER COLUMN envvar_key TYPE varchar(255); + INSERT INTO icingadb_schema (version, timestamp) VALUES (4, extract(epoch from now()) * 1000);