Skip to content

Commit

Permalink
schema: Enlarge Command Argument and Environment Key
Browse files Browse the repository at this point in the history
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]: 05d5e97
[1]: #791 (comment)
  • Loading branch information
oxzi committed Aug 15, 2024
1 parent 77ccab2 commit e122ceb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
18 changes: 9 additions & 9 deletions schema/mysql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)',

Expand Down Expand Up @@ -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,
Expand All @@ -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)',

Expand Down Expand Up @@ -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,
Expand All @@ -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)',

Expand Down
11 changes: 11 additions & 0 deletions schema/mysql/upgrades/1.3.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
12 changes: 6 additions & 6 deletions schema/pgsql/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand Down Expand Up @@ -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,

Expand Down
8 changes: 8 additions & 0 deletions schema/pgsql/upgrades/1.3.0.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit e122ceb

Please sign in to comment.