From 9f170a68d720658d737c43b7b7227665ed673f40 Mon Sep 17 00:00:00 2001 From: Muhammed Hussein karimi Date: Sat, 28 Oct 2023 10:12:55 +0330 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20boolean=20fields=20in=20k?= =?UTF-8?q?afka=20producer=20monitor=20(#3949)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 🐛 fix: boolean fields in kafka producer monitor Signed-off-by: Muhammed Hussein Karimi * 🐛 fix: boolean fields db patch table modify Signed-off-by: Muhammed Hussein Karimi * ✏️ typo: remove `_old` COLUMNs in patch-fix-kafka-producer-booleans Signed-off-by: Muhammed Hussein Karimi --------- Signed-off-by: Muhammed Hussein Karimi --- db/patch-fix-kafka-producer-booleans.sql | 29 ++++++++++++++++++++++++ server/database.js | 1 + server/model/monitor.js | 20 ++++++++++++++-- server/server.js | 3 +++ src/pages/EditMonitor.vue | 1 + 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 db/patch-fix-kafka-producer-booleans.sql diff --git a/db/patch-fix-kafka-producer-booleans.sql b/db/patch-fix-kafka-producer-booleans.sql new file mode 100644 index 00000000..810ec92e --- /dev/null +++ b/db/patch-fix-kafka-producer-booleans.sql @@ -0,0 +1,29 @@ +-- You should not modify if this have pushed to Github, unless it does serious wrong with the db. +BEGIN TRANSACTION; + +-- Rename COLUMNs to another one (suffixed by `_old`) +ALTER TABLE monitor + RENAME COLUMN kafka_producer_ssl TO kafka_producer_ssl_old; + +ALTER TABLE monitor + RENAME COLUMN kafka_producer_allow_auto_topic_creation TO kafka_producer_allow_auto_topic_creation_old; + +-- Add correct COLUMNs +ALTER TABLE monitor + ADD COLUMN kafka_producer_ssl BOOLEAN default 0 NOT NULL; + +ALTER TABLE monitor + ADD COLUMN kafka_producer_allow_auto_topic_creation BOOLEAN default 0 NOT NULL; + +-- Set bring old values from `_old` COLUMNs to correct ones +UPDATE monitor set kafka_producer_allow_auto_topic_creation = monitor.kafka_producer_allow_auto_topic_creation_old; +UPDATE monitor set kafka_producer_ssl = monitor.kafka_producer_ssl_old; + +-- Remove old COLUMNs +ALTER TABLE monitor + DROP COLUMN kafka_producer_allow_auto_topic_creation_old; + +ALTER TABLE monitor + DROP COLUMN kafka_producer_ssl_old; + +COMMIT; diff --git a/server/database.js b/server/database.js index af141dda..29ab3b94 100644 --- a/server/database.js +++ b/server/database.js @@ -82,6 +82,7 @@ class Database { "patch-add-timeout-monitor.sql": true, "patch-add-gamedig-given-port.sql": true, "patch-notification-config.sql": true, + "patch-fix-kafka-producer-booleans.sql": true, }; /** diff --git a/server/model/monitor.js b/server/model/monitor.js index 5cd94aa5..1e08ccd4 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -143,8 +143,8 @@ class Monitor extends BeanModel { expectedValue: this.expectedValue, kafkaProducerTopic: this.kafkaProducerTopic, kafkaProducerBrokers: JSON.parse(this.kafkaProducerBrokers), - kafkaProducerSsl: this.kafkaProducerSsl === "1" && true || false, - kafkaProducerAllowAutoTopicCreation: this.kafkaProducerAllowAutoTopicCreation === "1" && true || false, + kafkaProducerSsl: this.getKafkaProducerSsl(), + kafkaProducerAllowAutoTopicCreation: this.getKafkaProducerAllowAutoTopicCreation(), kafkaProducerMessage: this.kafkaProducerMessage, screenshot, }; @@ -287,6 +287,22 @@ class Monitor extends BeanModel { return Boolean(this.gamedigGivenPortOnly); } + /** + * Parse to boolean + * @returns {boolean} Kafka Producer Ssl enabled? + */ + getKafkaProducerSsl() { + return Boolean(this.kafkaProducerSsl); + } + + /** + * Parse to boolean + * @returns {boolean} Kafka Producer Allow Auto Topic Creation Enabled? + */ + getKafkaProducerAllowAutoTopicCreation() { + return Boolean(this.kafkaProducerAllowAutoTopicCreation); + } + /** * Start monitor * @param {Server} io Socket server instance diff --git a/server/server.js b/server/server.js index 6baf343e..605dde32 100644 --- a/server/server.js +++ b/server/server.js @@ -789,6 +789,9 @@ let needSetup = false; bean.kafkaProducerAllowAutoTopicCreation = monitor.kafkaProducerAllowAutoTopicCreation; bean.kafkaProducerSaslOptions = JSON.stringify(monitor.kafkaProducerSaslOptions); bean.kafkaProducerMessage = monitor.kafkaProducerMessage; + bean.kafkaProducerSsl = monitor.kafkaProducerSsl; + bean.kafkaProducerAllowAutoTopicCreation = + monitor.kafkaProducerAllowAutoTopicCreation; bean.gamedigGivenPortOnly = monitor.gamedigGivenPortOnly; bean.validate(); diff --git a/src/pages/EditMonitor.vue b/src/pages/EditMonitor.vue index 85687078..687aa42c 100644 --- a/src/pages/EditMonitor.vue +++ b/src/pages/EditMonitor.vue @@ -891,6 +891,7 @@ const monitorDefaults = { mechanism: "None", }, kafkaProducerSsl: false, + kafkaProducerAllowAutoTopicCreation: false, gamedigGivenPortOnly: true, };