From 74ce748059383e9a37e449f356036a266ed88e39 Mon Sep 17 00:00:00 2001 From: dashevchenko Date: Mon, 20 Mar 2023 12:10:08 +0200 Subject: [PATCH 1/5] changed default value for ws message queue limit per session from 0 to 1000 --- application/src/main/data/upgrade/3.4.4/schema_update.sql | 7 +++++++ .../dao/service/validator/TenantProfileDataValidator.java | 7 +++++++ ui-ngx/src/app/shared/models/tenant.model.ts | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/application/src/main/data/upgrade/3.4.4/schema_update.sql b/application/src/main/data/upgrade/3.4.4/schema_update.sql index d71fc158ef..9a5ac9b32b 100644 --- a/application/src/main/data/upgrade/3.4.4/schema_update.sql +++ b/application/src/main/data/upgrade/3.4.4/schema_update.sql @@ -347,3 +347,10 @@ END $$; -- ALARM FUNCTIONS END + +-- TENANT PROFILE START + +update tenant_profile SET profile_data = jsonb_set(profile_data, array['configuration','wsMsgQueueLimitPerSession'], to_jsonb(1000)) + WHERE profile_data::json#>>'{configuration,wsMsgQueueLimitPerSession}' = '0'; + +-- TENANT PROFILE END diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java b/dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java index 0477ccf32f..9a003e235c 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java +++ b/dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java @@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.queue.ProcessingStrategy; import org.thingsboard.server.common.data.queue.SubmitStrategy; import org.thingsboard.server.common.data.queue.SubmitStrategyType; +import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; import org.thingsboard.server.common.data.tenant.profile.TenantProfileQueueConfiguration; import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.service.DataValidator; @@ -57,6 +58,12 @@ public class TenantProfileDataValidator extends DataValidator { if (tenantProfile.getProfileData().getConfiguration() == null) { throw new DataValidationException("Tenant profile data configuration should be specified!"); } + if (tenantProfile.getProfileData().getConfiguration() instanceof DefaultTenantProfileConfiguration) { + DefaultTenantProfileConfiguration configuration = (DefaultTenantProfileConfiguration) tenantProfile.getProfileData().getConfiguration(); + if (configuration.getWsMsgQueueLimitPerSession() == 0) { + throw new DataValidationException("WS message queue limit per session should be greater than 0"); + } + } if (tenantProfile.isDefault()) { TenantProfile defaultTenantProfile = tenantProfileService.findDefaultTenantProfile(tenantId); if (defaultTenantProfile != null && !defaultTenantProfile.getId().equals(tenantProfile.getId())) { diff --git a/ui-ngx/src/app/shared/models/tenant.model.ts b/ui-ngx/src/app/shared/models/tenant.model.ts index 990852ed8c..45843a951c 100644 --- a/ui-ngx/src/app/shared/models/tenant.model.ts +++ b/ui-ngx/src/app/shared/models/tenant.model.ts @@ -110,7 +110,7 @@ export function createTenantProfileConfiguration(type: TenantProfileType): Tenan maxWsSessionsPerCustomer: 0, maxWsSessionsPerRegularUser: 0, maxWsSessionsPerPublicUser: 0, - wsMsgQueueLimitPerSession: 0, + wsMsgQueueLimitPerSession: 1000, maxWsSubscriptionsPerTenant: 0, maxWsSubscriptionsPerCustomer: 0, maxWsSubscriptionsPerRegularUser: 0, From b42d663670029753785e32fcb4a0a3f88a6fc469 Mon Sep 17 00:00:00 2001 From: dashevchenko Date: Tue, 21 Mar 2023 12:25:42 +0200 Subject: [PATCH 2/5] updated UI to display another default value for wsMessageQueuePerSession (1000 instead of 0) --- application/src/main/data/upgrade/3.4.4/schema_update.sql | 6 ------ .../server/controller/plugin/TbWebSocketHandler.java | 4 +++- application/src/main/resources/thingsboard.yml | 1 + .../dao/service/validator/TenantProfileDataValidator.java | 6 ------ .../default-tenant-profile-configuration.component.html | 3 +++ ui-ngx/src/assets/locale/locale.constant-en_US.json | 1 + 6 files changed, 8 insertions(+), 13 deletions(-) diff --git a/application/src/main/data/upgrade/3.4.4/schema_update.sql b/application/src/main/data/upgrade/3.4.4/schema_update.sql index 9a5ac9b32b..88ee90a53f 100644 --- a/application/src/main/data/upgrade/3.4.4/schema_update.sql +++ b/application/src/main/data/upgrade/3.4.4/schema_update.sql @@ -348,9 +348,3 @@ $$; -- ALARM FUNCTIONS END --- TENANT PROFILE START - -update tenant_profile SET profile_data = jsonb_set(profile_data, array['configuration','wsMsgQueueLimitPerSession'], to_jsonb(1000)) - WHERE profile_data::json#>>'{configuration,wsMsgQueueLimitPerSession}' = '0'; - --- TENANT PROFILE END diff --git a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java index f43607b24c..2a4c150e18 100644 --- a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java +++ b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java @@ -81,6 +81,8 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr private long sendTimeout; @Value("${server.ws.ping_timeout:30000}") private long pingTimeout; + @Value("${server.ws.max_queue_messages_per_session:1000}") + private int wsQueueMessagesPerSession; private final ConcurrentMap blacklistedSessions = new ConcurrentHashMap<>(); private final ConcurrentMap perSessionUpdateLimits = new ConcurrentHashMap<>(); @@ -142,7 +144,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements Telemetr var tenantProfileConfiguration = getTenantProfileConfiguration(sessionRef); internalSessionMap.put(internalSessionId, new SessionMetaData(session, sessionRef, tenantProfileConfiguration != null && tenantProfileConfiguration.getWsMsgQueueLimitPerSession() > 0 ? - tenantProfileConfiguration.getWsMsgQueueLimitPerSession() : 500)); + tenantProfileConfiguration.getWsMsgQueueLimitPerSession() : wsQueueMessagesPerSession)); externalSessionMap.put(externalSessionId, internalSessionId); processInWebSocketService(sessionRef, SessionEvent.onEstablished()); diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 10c4c9edac..a689483056 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -65,6 +65,7 @@ server: max_per_user: "${TB_SERVER_WS_DYNAMIC_PAGE_LINK_MAX_PER_USER:10}" max_entities_per_data_subscription: "${TB_SERVER_WS_MAX_ENTITIES_PER_DATA_SUBSCRIPTION:10000}" max_entities_per_alarm_subscription: "${TB_SERVER_WS_MAX_ENTITIES_PER_ALARM_SUBSCRIPTION:10000}" + max_queue_messages_per_session: "${TB_SERVER_WS_MAX_QUEUE_MESSAGES_PER_SESSION:1000}" rest: server_side_rpc: # Minimum value of the server side RPC timeout. May override value provided in the REST API call. diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java b/dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java index 9a003e235c..6f8dfceede 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java +++ b/dao/src/main/java/org/thingsboard/server/dao/service/validator/TenantProfileDataValidator.java @@ -58,12 +58,6 @@ public class TenantProfileDataValidator extends DataValidator { if (tenantProfile.getProfileData().getConfiguration() == null) { throw new DataValidationException("Tenant profile data configuration should be specified!"); } - if (tenantProfile.getProfileData().getConfiguration() instanceof DefaultTenantProfileConfiguration) { - DefaultTenantProfileConfiguration configuration = (DefaultTenantProfileConfiguration) tenantProfile.getProfileData().getConfiguration(); - if (configuration.getWsMsgQueueLimitPerSession() == 0) { - throw new DataValidationException("WS message queue limit per session should be greater than 0"); - } - } if (tenantProfile.isDefault()) { TenantProfile defaultTenantProfile = tenantProfileService.findDefaultTenantProfile(tenantId); if (defaultTenantProfile != null && !defaultTenantProfile.getId().equals(tenantProfile.getId())) { diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html index 35ea628784..90f84eab4a 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html @@ -410,6 +410,9 @@ {{ 'tenant-profile.too-small-value-one' | translate}} + + {{ 'tenant-profile.value-will-be-dropped-to-default' | translate}} +
diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 7f0b1badeb..e1f29fadbf 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3322,6 +3322,7 @@ "incorrect-pattern-for-rate-limits": "The format is comma separated pairs of capacity and period (in seconds) with a colon between, e.g. 100:1,2000:60", "too-small-value-zero": "The value must be bigger than 0", "too-small-value-one": "The value must be bigger than 1", + "value-will-be-dropped-to-default": "0 value will be dropped to default", "cassandra-tenant-limits-configuration": "Cassandra query for tenant", "ws-limit-max-sessions-per-tenant": "Sessions per tenant maximum number", "ws-limit-max-sessions-per-customer": "Sessions per customer maximum number", From fae2427d8ba774d834c49ad7a47ec5fa9c3597c8 Mon Sep 17 00:00:00 2001 From: dashevchenko Date: Tue, 4 Apr 2023 11:59:33 +0300 Subject: [PATCH 3/5] refactoring --- .../server/controller/plugin/TbWebSocketHandler.java | 2 +- application/src/main/resources/thingsboard.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java index 822a38c3fd..88bdf0f709 100644 --- a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java +++ b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java @@ -84,7 +84,7 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements WebSocke private long sendTimeout; @Value("${server.ws.ping_timeout:30000}") private long pingTimeout; - @Value("${server.ws.max_queue_messages_per_session:1000}") + @Value("${server.ws.default_queue_messages_per_session:1000}") private int wsQueueMessagesPerSession; private final ConcurrentMap blacklistedSessions = new ConcurrentHashMap<>(); diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index e776497717..a4c82aac99 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -65,7 +65,7 @@ server: max_per_user: "${TB_SERVER_WS_DYNAMIC_PAGE_LINK_MAX_PER_USER:10}" max_entities_per_data_subscription: "${TB_SERVER_WS_MAX_ENTITIES_PER_DATA_SUBSCRIPTION:10000}" max_entities_per_alarm_subscription: "${TB_SERVER_WS_MAX_ENTITIES_PER_ALARM_SUBSCRIPTION:10000}" - max_queue_messages_per_session: "${TB_SERVER_WS_MAX_QUEUE_MESSAGES_PER_SESSION:1000}" + default_queue_messages_per_session: "${TB_SERVER_WS_DEFAULT_QUEUE_MESSAGES_PER_SESSION:1000}" rest: server_side_rpc: # Minimum value of the server side RPC timeout. May override value provided in the REST API call. From 939c00c2995e46fa71ce13962892962a4b9c4391 Mon Sep 17 00:00:00 2001 From: dashevchenko Date: Mon, 10 Apr 2023 16:55:20 +0300 Subject: [PATCH 4/5] added validation for max value of wsQueueMessagesPerSession --- .../server/controller/plugin/TbWebSocketHandler.java | 9 +++++---- application/src/main/resources/thingsboard.yml | 2 +- .../default-tenant-profile-configuration.component.html | 2 +- ui-ngx/src/app/shared/models/tenant.model.ts | 2 +- ui-ngx/src/assets/locale/locale.constant-en_US.json | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java index 88bdf0f709..4eceebd98a 100644 --- a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java +++ b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java @@ -84,8 +84,8 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements WebSocke private long sendTimeout; @Value("${server.ws.ping_timeout:30000}") private long pingTimeout; - @Value("${server.ws.default_queue_messages_per_session:1000}") - private int wsQueueMessagesPerSession; + @Value("${server.ws.max_queue_messages_per_session:1000}") + private int wsMaxQueueMessagesPerSession; private final ConcurrentMap blacklistedSessions = new ConcurrentHashMap<>(); private final ConcurrentMap perSessionUpdateLimits = new ConcurrentHashMap<>(); @@ -146,8 +146,9 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements WebSocke } var tenantProfileConfiguration = getTenantProfileConfiguration(sessionRef); internalSessionMap.put(internalSessionId, new SessionMetaData(session, sessionRef, - tenantProfileConfiguration != null && tenantProfileConfiguration.getWsMsgQueueLimitPerSession() > 0 ? - tenantProfileConfiguration.getWsMsgQueueLimitPerSession() : wsQueueMessagesPerSession)); + tenantProfileConfiguration != null && tenantProfileConfiguration.getWsMsgQueueLimitPerSession() > 0 && + tenantProfileConfiguration.getWsMsgQueueLimitPerSession() < wsMaxQueueMessagesPerSession ? + tenantProfileConfiguration.getWsMsgQueueLimitPerSession() : wsMaxQueueMessagesPerSession)); externalSessionMap.put(externalSessionId, internalSessionId); processInWebSocketService(sessionRef, SessionEvent.onEstablished()); diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index a4c82aac99..4c673d27e2 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -65,7 +65,7 @@ server: max_per_user: "${TB_SERVER_WS_DYNAMIC_PAGE_LINK_MAX_PER_USER:10}" max_entities_per_data_subscription: "${TB_SERVER_WS_MAX_ENTITIES_PER_DATA_SUBSCRIPTION:10000}" max_entities_per_alarm_subscription: "${TB_SERVER_WS_MAX_ENTITIES_PER_ALARM_SUBSCRIPTION:10000}" - default_queue_messages_per_session: "${TB_SERVER_WS_DEFAULT_QUEUE_MESSAGES_PER_SESSION:1000}" + max_queue_messages_per_session: "${TB_SERVER_WS_DEFAULT_QUEUE_MESSAGES_PER_SESSION:1000}" rest: server_side_rpc: # Minimum value of the server side RPC timeout. May override value provided in the REST API call. diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html index 47b75783ae..efa6ef7e13 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html @@ -411,7 +411,7 @@ {{ 'tenant-profile.too-small-value-one' | translate}} - {{ 'tenant-profile.value-will-be-dropped-to-default' | translate}} + {{ 'tenant-profile.queue-size-is-limited-by-system-configuration' | translate}}
diff --git a/ui-ngx/src/app/shared/models/tenant.model.ts b/ui-ngx/src/app/shared/models/tenant.model.ts index a3bf7ca869..95e0314a52 100644 --- a/ui-ngx/src/app/shared/models/tenant.model.ts +++ b/ui-ngx/src/app/shared/models/tenant.model.ts @@ -111,7 +111,7 @@ export function createTenantProfileConfiguration(type: TenantProfileType): Tenan maxWsSessionsPerCustomer: 0, maxWsSessionsPerRegularUser: 0, maxWsSessionsPerPublicUser: 0, - wsMsgQueueLimitPerSession: 1000, + wsMsgQueueLimitPerSession: 0, maxWsSubscriptionsPerTenant: 0, maxWsSubscriptionsPerCustomer: 0, maxWsSubscriptionsPerRegularUser: 0, diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 8c97a63d13..07924831c3 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3576,7 +3576,7 @@ "incorrect-pattern-for-rate-limits": "The format is comma separated pairs of capacity and period (in seconds) with a colon between, e.g. 100:1,2000:60", "too-small-value-zero": "The value must be bigger than 0", "too-small-value-one": "The value must be bigger than 1", - "value-will-be-dropped-to-default": "0 value will be dropped to default", + "queue-size-is-limited-by-system-configuration": "The size of the queue is also limited by the system configuration.", "cassandra-tenant-limits-configuration": "Cassandra query for tenant", "ws-limit-max-sessions-per-tenant": "Sessions per tenant maximum number", "ws-limit-max-sessions-per-customer": "Sessions per customer maximum number", From 6b92ed8005c220b411cd09c76b5284a27d1c4e91 Mon Sep 17 00:00:00 2001 From: dashevchenko Date: Tue, 11 Apr 2023 13:07:48 +0300 Subject: [PATCH 5/5] refactoring --- .../server/controller/plugin/TbWebSocketHandler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java index 4eceebd98a..7a396ff795 100644 --- a/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java +++ b/application/src/main/java/org/thingsboard/server/controller/plugin/TbWebSocketHandler.java @@ -145,10 +145,11 @@ public class TbWebSocketHandler extends TextWebSocketHandler implements WebSocke return; } var tenantProfileConfiguration = getTenantProfileConfiguration(sessionRef); + int wsTenantProfileQueueLimit = tenantProfileConfiguration != null ? + tenantProfileConfiguration.getWsMsgQueueLimitPerSession() : wsMaxQueueMessagesPerSession; internalSessionMap.put(internalSessionId, new SessionMetaData(session, sessionRef, - tenantProfileConfiguration != null && tenantProfileConfiguration.getWsMsgQueueLimitPerSession() > 0 && - tenantProfileConfiguration.getWsMsgQueueLimitPerSession() < wsMaxQueueMessagesPerSession ? - tenantProfileConfiguration.getWsMsgQueueLimitPerSession() : wsMaxQueueMessagesPerSession)); + (wsTenantProfileQueueLimit > 0 && wsTenantProfileQueueLimit < wsMaxQueueMessagesPerSession) ? + wsTenantProfileQueueLimit : wsMaxQueueMessagesPerSession)); externalSessionMap.put(externalSessionId, internalSessionId); processInWebSocketService(sessionRef, SessionEvent.onEstablished());