sending an initial corrupt telemetry message to a child device prevents device being registered
Closed this issue · 1 comments
Describe the bug
If an event with an invalid payload is published to the thin-edge.io broker, it prevents the child device from being registered with Cumulocity IoT.
If the user then fixed the event payload, and publishes the event again, the event is rejected by Cumulocity IoT as the device has not been registered (due to the absent 101
SmartREST message).
The following error is seen on the second publishing of the corrected thin-edge.io event message:
[c8y/error] {"messageId":190,"error":"general/internalError","message":"Current device is not the owner of the given source null","info":"https://cumulocity.com/guides/reference/rest-implementation"}
To Reproduce
-
Create an event for a new child device. The event is ill-formed (e.g. invalid json)
tedge mqtt pub 'te/device/mytest///e/something' '{corrupt fragment, "text":"my event"}'
If you have subscribed to the
#
topic locally, you should see an error message about the ill-formed event payload[te/device/mytest///e/something] {corrupt fragment, "text":"my event"} [te/errors] Parsing of event message received on topic: te/device/mytest///e/something failed due to error: key must be a string at line 1 column 2. Snipped payload: {corrupt fragment, "text":"my event"}
-
Fix the ill-formed event payload, and publish again
tedge mqtt pub 'te/device/mytest///e/something' '{"text":"my event"}'
On the
#
topic, thin-edge.io will attempt to create an event, but without registering the child device first.[te/device/mytest///e/something] {"text":"my event"} [c8y/event/events/create] {"type":"something","time":"2024-05-22T06:12:43.254635699Z","text":"my event","externalSource":{"externalId":"rpi4-d83add90fe56:device:mytest","type":"c8y_Serial"}} [c8y/error] {"messageId":190,"error":"general/internalError","message":"Current device is not the owner of the given source null","info":"https://cumulocity.com/guides/reference/rest-implementation"}
Expected behavior
- Invalid telemetry data messages should not prevent the registration of a device in Cumulocity IoT
Screenshots
Environment (please complete the following information):
Property | Value |
---|---|
OS [incl. version] | Poky (Yocto Project Reference Distro) 4.0.18 (kirkstone) |
Hardware [incl. revision] | Raspberry Pi 4 Model B Rev 1.5 |
System-Architecture | Linux rpi4-d83add90fe56 5.15.92-v8 #1 SMP PREEMPT Wed Feb 8 16:47:50 UTC 2023 aarch64 GNU/Linux |
thin-edge.io version | tedge 1.0.1 |
Additional context
entity store: cat /etc/tedge/.tedge-mapper-c8y/entity_store.jsonl
The internal entity store shows the mytest
child device has been recorded, however a child device registration message (c8y/s/us 101) was not sent to Cumulocity IoT.
{"version":"1.0"}
{"topic":{"name":"te/device/main///twin/c8y_Agent"},"payload":"{\"name\":\"thin-edge.io\",\"url\":\"https://thin-edge.io\",\"version\":\"1.0.1\"}","qos":1,"retain":true}
{"topic":{"name":"te/device/main/service/tedge-mapper-c8y"},"payload":"{\"@id\":\"rpi4-d83add90fe56:device:main:service:tedge-mapper-c8y\",\"@parent\":\"device/main//\",\"@type\":\"service\",\"name\":\"tedge-mapper-c8y\",\"type\":\"service\"}","qos":1,"retain":true}
{"topic":{"name":"te/device/main/service/mosquitto-c8y-bridge"},"payload":"{\"@id\":\"rpi4-d83add90fe56:device:main:service:mosquitto-c8y-bridge\",\"@parent\":\"device/main//\",\"@type\":\"service\",\"name\":\"mosquitto-c8y-bridge\",\"type\":\"service\"}","qos":1,"retain":true}
{"topic":{"name":"te/device/main/service/tedge-agent"},"payload":"{\"@id\":\"rpi4-d83add90fe56:device:main:service:tedge-agent\",\"@parent\":\"device/main//\",\"@type\":\"service\",\"name\":\"tedge-agent\",\"type\":\"service\"}","qos":1,"retain":true}
{"topic":{"name":"te/device/main/service/tedge-mapper-collectd"},"payload":"{\"@id\":\"rpi4-d83add90fe56:device:main:service:tedge-mapper-collectd\",\"@parent\":\"device/main//\",\"@type\":\"service\",\"name\":\"tedge-mapper-collectd\",\"type\":\"service\"}","qos":1,"retain":true}
{"topic":{"name":"te/device/main///twin/c8y_Hardware"},"payload":"{\"model\":\"Raspberry Pi 4 Model B Rev 1.5\",\"revision\":\"BCM2835-d03115\",\"serialNumber\":\"1000000044d70329\",\"sysClockSync\":\"no\"}","qos":1,"retain":true}
{"topic":{"name":"te/device/main///twin/device_OS"},"payload":"{\"arch\":\"aarch64\",\"displayName\":\"Poky (Yocto Project Reference Distro) 4.0.18 (kirkstone)\",\"family\":\"GNU/Linux\",\"hostname\":\"rpi4-d83add90fe56\",\"kernel\":\"#1 SMP PREEMPT Wed Feb 8 16:47:50 UTC 2023\",\"sysClockSync\":\"no\",\"version\":\"4.0.18\"}","qos":1,"retain":true}
{"topic":{"name":"te/device/main///twin/c8y_Firmware"},"payload":"{\"name\":\"core-image-tedge-rauc\",\"updated\":\"Tue May 21 22:17:11 UTC 2024\",\"version\":\"20240521.1820\"}","qos":1,"retain":true}
{"topic":{"name":"te/device/mytest//"},"payload":"{\"@id\":\"rpi4-d83add90fe56:device:mytest\",\"@type\":\"child-device\",\"name\":\"mytest\"}","qos":1,"retain":true}
Workaround
- Edit the
/etc/tedge/.tedge-mapper-c8y/entity_store.jsonl
file, and remove the message matching the erroneous child device - Restart the mapper
sudo systemctl restart tedge-mapper-c8y
QA has tested the bug and it's not reproducable anymore