telefonicaid / fiware-orion

Context Broker and CEF building block for context data management, providing NGSI interfaces.
https://fiware-orion.rtfd.io/
GNU Affero General Public License v3.0
212 stars 265 forks source link

Unexpected Behavior with entityUpdate and notifyOnMetadataChange #4605

Closed goten002 closed 2 hours ago

goten002 commented 3 weeks ago

When using subscriptions in FIWARE Orion with the alterationTypes field set to entityUpdate and notifyOnMetadataChange set to false, the subscription does not behave as expected. Specifically, the notification fails to trigger when an entity is updated with changes in metadata, when the attribute values remain unchanged. This behavior suggests that the subscription is incorrectly ignoring updates that involve metadata changes while the attribute values stay the same.

How to reproduce it

  1. Create a subscription::

    curl -iX POST 'http://127.0.0.1:1026/v2/subscriptions' \
    -H 'Fiware-Service: test' \
    -H 'Fiware-ServicePath: /test' \
    -H 'Content-Type: application/json' \
    -d '{
    "description": "testing-quantumleap-subscription",
    "subject": {
    "entities": [
      {
        "idPattern": ".*",
        "type": "DummyDevice"
      }
    ],
    "condition": {
      "attrs": [
        "temperature",
        "humidity"
      ],
      "notifyOnMetadataChange": false,
      "alterationTypes": [
        "entityUpdate",
        "entityCreate"
      ]
    }
    },
    "notification": {
    "attrs": [
      "temperature",
      "humidity"
    ],
    "onlyChangedAttrs": true,
    "attrsFormat": "normalized",
    "http": {
      "url": "http://quantumleap:8668/v2/notify"
    },
    "metadata": [
      "TimeInstant"
    ]
    }
    }'
  2. Create an entity

    curl -iX POST 'http://localhost:1026/v2/entities' \
    -H 'Fiware-Service: test' \
    -H 'Fiware-ServicePath: /test' \
    -H 'Content-Type: application/json' \
    -d '{
    "id": "dummy-device-01",
    "type": "DummyDevice",
    "temperature": {
    "type": "Number",
    "value": 20,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2024-08-20T00:00:00.000Z"
      }
    }
    },
    "humidity": {
    "type": "Number",
    "value": 50,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2024-08-20T00:00:00.000Z"
      }
    }
    }
    }'
  3. Update Attributes

curl -iX POST 'http://localhost:1026/v2/entities/dummy-device-01/attrs' \
-H 'Fiware-Service: test' \
-H 'Fiware-ServicePath: /test' \
-H 'Content-Type: application/json' \
-d '{
  "temperature": {
    "type": "Number",
    "value": 20,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2024-08-20T00:10:00.000Z"
      }
    }
  },
  "humidity": {
    "type": "Number",
    "value": 50,
    "metadata": {
      "TimeInstant": {
        "type": "DateTime",
        "value": "2024-08-20T00:10:00.000Z"
      }
    }
  }
}'

Expected behavior Following the requests above the notification should be triggered twice: once when the entity is created, and once when the entity is updated, regardless of whether the metadata or the value has changed. Specifically, the update request should trigger the subscription because the alterationTypes field includes entityUpdate. The subscription should react to any update operation, regardless of whether the attribute values change, as long as the update occurs, even if notifyOnMetadataChange is set to false.

Additional information Interestingly, if the update request is sent without metadata or if the TimeInstant metadata value remains the same as in the create request, the subscription triggers as expected. This suggests that the issue arises only when metadata changes are included in the update.

fgalan commented 3 weeks ago

Thank you for your detailed report!

We would have a look as soon as possible.

fgalan commented 23 hours ago

PR #4612 solves this issue

@goten002 it would be great if you could have a look to the test/functionalTest/cases/4605_alterationtype_entityupdate_with_notifyonmetadatachange/alterationtype_entityupdate_with_notifyonmetadatachange.test file added in that PR and provide feedback, please. Step 01-03 are fully based in your issue report and step 04 is an extra addition. As a result, 3 notifications are sent (shown in step 05).

fgalan commented 8 hours ago

PR https://github.com/telefonicaid/fiware-orion/pull/4612 has been merged.

@goten002 it would be great if you could check if the issue has been solved and provide feedback, using the telefonicaiot/fiware-orion:latest image at dockerhub.

fgalan commented 2 hours ago

We have just released Orion 4.1.0 which includes PR #4612 so we are closing this issue.

However, @goten002 your feedback would still be very valuable. The issue could be reopened if the solution is not correct.

goten002 commented 2 hours ago

@fgalan Thank you so much for addressing the issue. I’ve tested the functionality with the latest image, and everything seems to be working as expected now. I really appreciate all the work and the fix!