Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flags to disable MQTT and AMQP #685

Merged
merged 11 commits into from
Nov 4, 2022

Conversation

jason-fox
Copy link
Contributor

This avoids unnecessary polling to connect to MQTT and AMQP if they are not there and keeps the logs nice and clean.
As a side-effect, startup is quicker too.

Just add the following config to your docker-compose.

      - IOTA_MQTT_DISABLED=true
      - IOTA_AMPQ_DISABLED=true

@@ -202,6 +202,7 @@ The ones relating specific JSON bindings are described in the following table.
| IOTA_MQTT_AVOID_LEADING_SLASH | mqtt.avoidLeadingSlash |
| IOTA_MQTT_CLEAN | mqtt.clean |
| IOTA_MQTT_CLIENT_ID | mqtt.clientId |
| IOTA_MQTT_DISABLED | |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every env var shoud have its correspondence in config.js, for homogeneity. Two alternatives:

  • The omission of mqtt key in config.js equals to IOTA_MQTT_DISABLED=true. The existence of mqtt key in config.js equals IOTA_MQTT_ENABLED=false
  • Make it more explicit: IOTA_MQTT_DISABLED equals to a new sub-key, e.g. mqtt.enabled

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change of functionality (hidden behind a bug) 😄

For MQTT/AMPQ - the absence of config.mqtt in the configuration disables the MQTT - at least in the code. So theoretically an appropriately configured config.js could be injected. However the configService line 154 always sets up a config with mqtt and apmq objects. This plus the fact that the default config.js holds default values means that it is currently impossible not to enable AMQP and MQTT.

So how would you like this to be altered? I assume that both cases should be covered - absence and an explicit key.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential fix 94cca8e - you will still get the ERROR message if the object is missing, but if you use any of the MQTT or AMPQ env variables, the config will exist and you can only disable it by adding IOTA_MQTT_DISABLED / IOTA_AMPQ_DISABLED

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that ampq and/or mqtt could be missing from an injected config.js so the ERROR message still makes sense as an error.

Question - if config.mqtt.disabled = true is deliberately set, is this better to be logged at INFO or at ERROR level?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question - if config.mqtt.disabled = true is deliberately set, is this better to be logged at INFO or at ERROR level?

Unsure... How would be an example of such trace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this at WARN - last two lines.

{"op":"IoTAgentNGSI.JEXL","time":"2022-08-18T13:24:04.259Z","lvl":"INFO","msg":"Trasformations can be added to JEXL parser"}
{"time":"2022-08-18T13:24:04.649Z","lvl":"INFO","msg":"Setting IOTA_CB_HOST to environment value: orion"}
{"time":"2022-08-18T13:24:04.650Z","lvl":"INFO","msg":"Setting IOTA_CB_PORT to environment value: 1026"}
{"time":"2022-08-18T13:24:04.650Z","lvl":"INFO","msg":"Setting IOTA_CB_NGSI_VERSION to environment value: ld"}
{"time":"2022-08-18T13:24:04.650Z","lvl":"INFO","msg":"Setting IOTA_NORTH_PORT to environment value: 4041"}
{"time":"2022-08-18T13:24:04.650Z","lvl":"INFO","msg":"Setting IOTA_PROVIDER_URL to environment value: http://iot-agent:4041"}
{"time":"2022-08-18T13:24:04.650Z","lvl":"INFO","msg":"Setting IOTA_REGISTRY_TYPE to environment value: mongodb"}
{"time":"2022-08-18T13:24:04.651Z","lvl":"INFO","msg":"Setting IOTA_LOG_LEVEL to environment value: WARN"}
{"time":"2022-08-18T13:24:04.651Z","lvl":"INFO","msg":"Setting IOTA_TIMESTAMP to environment value: true"}
{"time":"2022-08-18T13:24:04.651Z","lvl":"INFO","msg":"Setting IOTA_DEFAULT_RESOURCE to environment value: /iot/json"}
{"time":"2022-08-18T13:24:04.651Z","lvl":"INFO","msg":"Setting IOTA_MONGO_HOST to environment value: mongo-db"}
{"time":"2022-08-18T13:24:04.651Z","lvl":"INFO","msg":"Setting IOTA_MONGO_PORT to environment value: 27017"}
{"time":"2022-08-18T13:24:04.652Z","lvl":"INFO","msg":"Setting IOTA_MONGO_DB to environment value: iotagentjson"}
{"time":"2022-08-18T13:24:04.652Z","lvl":"INFO","msg":"Setting IOTA_AUTOCAST to environment value: true"}
{"time":"2022-08-18T13:24:04.652Z","lvl":"INFO","msg":"Setting IOTA_JSON_LD_CONTEXT to environment value: http://context/ngsi-context.jsonld"}
{"time":"2022-08-18T13:24:04.652Z","lvl":"INFO","msg":"Setting IOTA_FALLBACK_TENANT to environment value: openiot"}
{"time":"2022-08-18T13:24:04.654Z","lvl":"WARN","msg":"***********************************************\nWARNING: authentication for secure connections is not in use,\nIt is recommended to enable authentication\n***********************************************"}

...

time=2022-08-18T13:24:04.670Z | lvl=WARN | corr=fdb713a2-d385-4fc0-8dde-18261cbf2893 | trans=fdb713a2-d385-4fc0-8dde-18261cbf2893 | op=IoTAgentNGSI.Global | from=n/a | srv=n/a | subsrv=n/a | msg=***********************************************
WARNING: authentication for secure connections is not in use,
It is recommended to enable authentication
*********************************************** | comp=IoTAgent
time=2022-08-18T13:24:04.673Z | lvl=WARN | corr=fdb713a2-d385-4fc0-8dde-18261cbf2893 | trans=fdb713a2-d385-4fc0-8dde-18261cbf2893 | op=IoTAgentNGSI.Global | from=n/a | srv=n/a | subsrv=n/a | msg=***********************************************
WARNING: authentication for secure connections is not in use,
It is recommended to enable authentication
*********************************************** | comp=IoTAgent
(node:1) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
time=2022-08-18T13:24:05.609Z | lvl=ERROR | corr=fdb713a2-d385-4fc0-8dde-18261cbf2893 | trans=fdb713a2-d385-4fc0-8dde-18261cbf2893 | op=IOTAJSON.AMQP.Binding | from=n/a | srv=n/a | subsrv=n/a | msg=Error AMPQ is not configured | comp=IoTAgent
time=2022-08-18T13:24:05.615Z | lvl=ERROR | corr=fdb713a2-d385-4fc0-8dde-18261cbf2893 | trans=fdb713a2-d385-4fc0-8dde-18261cbf2893 | op=IOTAJSON.MQTT.Binding | from=n/a | srv=n/a | subsrv=n/a | msg=Error MQTT is not configured | comp=IoTAgent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or msg=AMPQ is disabled for example.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is is not so severe to use ERROR, but maybe more relevant than INFO. Maybe WARN is the proper level, i.e:

time=2022-08-18T13:24:05.609Z | lvl=WARN | corr=fdb713a2-d385-4fc0-8dde-18261cbf2893 | trans=fdb713a2-d385-4fc0-8dde-18261cbf2893 | op=IOTAJSON.AMQP.Binding | from=n/a | srv=n/a | subsrv=n/a | msg=AMPQ is disabled | comp=IoTAgent
time=2022-08-18T13:24:05.615Z | lvl=WARN | corr=fdb713a2-d385-4fc0-8dde-18261cbf2893 | trans=fdb713a2-d385-4fc0-8dde-18261cbf2893 | op=IOTAJSON.MQTT.Binding | from=n/a | srv=n/a | subsrv=n/a | msg=MQTT is disabled | comp=IoTAgent

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 2bdd5af

@mapedraza
Copy link
Collaborator

Adding an entry into CHANGES_NEXT_RELEASE file is required before merging.

@jason-fox
Copy link
Contributor Author

Fixed 418ed64

CHANGES_NEXT_RELEASE Outdated Show resolved Hide resolved
@@ -202,6 +202,7 @@ The ones relating specific JSON bindings are described in the following table.
| IOTA_MQTT_AVOID_LEADING_SLASH | mqtt.avoidLeadingSlash |
| IOTA_MQTT_CLEAN | mqtt.clean |
| IOTA_MQTT_CLIENT_ID | mqtt.clientId |
| IOTA_MQTT_DISABLED | mqtt.disabled |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config.js should be modified to include the new mqtt.disabled and amqp.disables settings (in commented way). Note config.js is used also somehow to document configurations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 04e88ac

jason-fox and others added 2 commits November 4, 2022 09:38
Co-authored-by: Fermín Galán Márquez <fgalan@users.noreply.github.com>
Copy link
Member

@fgalan fgalan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@fgalan fgalan merged commit 8cf9b5f into telefonicaid:master Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants