diff --git a/doc/manuals/admin/cli.md b/doc/manuals/admin/cli.md index a133939397..57e95e0f25 100644 --- a/doc/manuals/admin/cli.md +++ b/doc/manuals/admin/cli.md @@ -185,6 +185,7 @@ The list of available options is the following: to the `-k` or `--insecure` parameteres of the curl command. - **-mqttMaxAge**. Max time (in minutes) that an unused MQTT connection is kept. Default: 60 - **-logDeprecate**. Log deprecation usages as warnings. More information in [this section of the documentation](../deprecated.md#log-deprecation-warnings). Default is: false. It can be changed after Orion startup with the [log admin REST API](management_api.md#log-configs-and-trace-levels), with the `deprecated` field +- **-notifAlarmThreshold**. Maximum threshold for notification queue alarms, as a percentage of the maximum queue size, default 0 (meaning no queue alarms are used) ## Configuration using environment variables @@ -263,3 +264,4 @@ Two facts have to be taken into account: | ORION_NGSIV1_AUTOCAST | ngsiv1Autocast | | ORION_MQTT_MAX_AGE | mqttMaxAge | | ORION_LOG_DEPRECATE | logDeprecate | +| ORION_NOTIF_ALARM_THRESHOLD | notifAlarmThreshold | diff --git a/src/app/contextBroker/contextBroker.cpp b/src/app/contextBroker/contextBroker.cpp index 59ff306550..52e2800530 100644 --- a/src/app/contextBroker/contextBroker.cpp +++ b/src/app/contextBroker/contextBroker.cpp @@ -206,7 +206,7 @@ unsigned long fcMaxInterval; int mqttMaxAge; bool logDeprecate; -long int maxthreshold; +long unsigned int notifAlarmThreshold; @@ -277,7 +277,7 @@ long int maxthreshold; #define NGSIV1_AUTOCAST_DESC "automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations" #define MQTT_MAX_AGE_DESC "max time (in minutes) that an unused MQTT connection is kept, default: 60" #define LOG_DEPRECATE_DESC "log deprecation usages as warnings" -#define MAX_THRESHOLD_DESC "maximum threshold for notification queue, default: 80%" +#define NOTIF_ALARM_THRESHOLD_DESC "maximum threshold for notification queue alarms, as a percentage of the maximum queue size, default 0 (meaning no queue alarms are used)" @@ -368,7 +368,7 @@ PaArgument paArgs[] = { "-logDeprecate", &logDeprecate, "LOG_DEPRECATE", PaBool, PaOpt, false, false, true, LOG_DEPRECATE_DESC }, - { "-maxthreshold", &maxthreshold, "MAX_THRESHOLD", PaInt, PaOpt, 0, PaNL, PaNL, MAX_THRESHOLD_DESC }, + { "-notifAlarmThreshold", ¬ifAlarmThreshold, "NOTIF_ALARM_THRESHOLD", PaInt, PaOpt, 0, PaNL, PaNL, NOTIF_ALARM_THRESHOLD_DESC }, PA_END_OF_ARGS }; @@ -660,15 +660,6 @@ static void contextBrokerInit(void) QueueNotifier* pQNotifier = new QueueNotifier(notificationQueueSize, notificationThreadNum, serviceV, serviceQueueSizeV, serviceNumThreadV); int rc = pQNotifier->start(); - if (maxthreshold > 0) - { - maxthreshold=notificationQueueSize*maxthreshold/100; - } - else - { - maxthreshold=notificationQueueSize*80; - } - if (rc != 0) { LM_X(1,("Runtime Error starting notification queue workers (%d)", rc)); diff --git a/src/lib/ngsiNotify/QueueNotifier.cpp b/src/lib/ngsiNotify/QueueNotifier.cpp index 1d2a88677f..049f1d948a 100644 --- a/src/lib/ngsiNotify/QueueNotifier.cpp +++ b/src/lib/ngsiNotify/QueueNotifier.cpp @@ -178,15 +178,30 @@ void QueueNotifier::sendNotifyContextRequest bool enqueued = sq->try_push(paramsP); - if (enqueued) + if (!enqueued) { + QueueStatistics::incReject(1); + LM_E(("Runtime Error (%s notification queue is full)", queueName.c_str())); + delete paramsP; - extern long int maxthreshold; - extern int notificationQueueSize; + return; + } + extern long unsigned int notifAlarmThreshold; + + if (notifAlarmThreshold != 0) + { std::string details = ("notification queue reached maximum threshold"); - if (maxthreshold >= notificationQueueSize) + if (notifAlarmThreshold > 0) + { + notifAlarmThreshold=queueSize(service)*notifAlarmThreshold/100; + } + if (notifAlarmThreshold > 100) + { + LM_X(1, ("Fatal Error (notifAlarmThreshol value is greater than 100%)")); + } + if (notifAlarmThreshold >= queueSize(service)) { alarmMgr.notificationQueue(queueName.c_str(), details); } @@ -196,14 +211,5 @@ void QueueNotifier::sendNotifyContextRequest } } - if (!enqueued) - { - QueueStatistics::incReject(1); - LM_E(("Runtime Error (%s notification queue is full)", queueName.c_str())); - delete paramsP; - - return; - } - QueueStatistics::incIn(1); } diff --git a/test/functionalTest/cases/0000_cli/bool_option_with_value.test b/test/functionalTest/cases/0000_cli/bool_option_with_value.test index dbdc0d45b7..021d81530b 100644 --- a/test/functionalTest/cases/0000_cli/bool_option_with_value.test +++ b/test/functionalTest/cases/0000_cli/bool_option_with_value.test @@ -103,5 +103,6 @@ Usage: contextBroker [option '-U' (extended usage)] [option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations)] [option '-mqttMaxAge' ] [option '-logDeprecate' (log deprecation usages as warnings)] + [option '-notifAlarmThreshold' ] --TEARDOWN-- diff --git a/test/functionalTest/cases/0000_cli/command_line_options.test b/test/functionalTest/cases/0000_cli/command_line_options.test index 8e5b9b1ecb..48282dd937 100644 --- a/test/functionalTest/cases/0000_cli/command_line_options.test +++ b/test/functionalTest/cases/0000_cli/command_line_options.test @@ -92,5 +92,6 @@ Usage: contextBroker [option '-U' (extended usage)] [option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations)] [option '-mqttMaxAge' ] [option '-logDeprecate' (log deprecation usages as warnings)] + [option '-notifAlarmThreshold' ] --TEARDOWN-- diff --git a/test/functionalTest/cases/0000_cli/tracelevel_without_logLevel_as_DEBUG.test b/test/functionalTest/cases/0000_cli/tracelevel_without_logLevel_as_DEBUG.test index 2ae2c7ad60..847d74af82 100644 --- a/test/functionalTest/cases/0000_cli/tracelevel_without_logLevel_as_DEBUG.test +++ b/test/functionalTest/cases/0000_cli/tracelevel_without_logLevel_as_DEBUG.test @@ -93,5 +93,6 @@ Usage: contextBroker [option '-U' (extended usage)] [option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSIv1 update/create attribute operations)] [option '-mqttMaxAge' ] [option '-logDeprecate' (log deprecation usages as warnings)] + [option '-notifAlarmThreshold' ] --TEARDOWN-- diff --git a/test/functionalTest/cases/3658_env_vars/env_vars.test b/test/functionalTest/cases/3658_env_vars/env_vars.test index bd68c35e98..f08dc9dbe2 100644 --- a/test/functionalTest/cases/3658_env_vars/env_vars.test +++ b/test/functionalTest/cases/3658_env_vars/env_vars.test @@ -138,6 +138,7 @@ Extended Usage: contextBroker [option '-U' (extended usage)] [option '-ngsiv1Autocast' (automatic cast for number, booleans and dates in NGSI] ORION_NGSIV1_AUTOCAST FALSE /FALSE/ [option '-mqttMaxAge'