FIWARE / context.Orion-LD

Context Broker and CEF building block for context data management which supports both the NGSI-LD and the NGSI-v2 APIs
https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.06.01_60/gs_CIM009v010601p.pdf
GNU Affero General Public License v3.0
51 stars 43 forks source link

q Field Updates correctly when updating subscription, but notification still triggers on old condition. #1648

Open SystemsPurge opened 4 months ago

SystemsPurge commented 4 months ago

Steps: Post an entity Post a subscription with a condition ( e.g q = temperature<30 ) Update the entity to correspond to the condition Update subscription to other condition (e.g q = temperature > 30 ) Update entity to correspond to new condition Update entity to correspond to old condition again

What happens: Notification is received on the first and third entity update but not the second one, despite the fact that on mongo express, the subscription is showing the correct expression

Here is the bash script i used to test it out :

#!/bin/bash

#Post Entity
curl -X POST http://localhost:1026/ngsi-ld/v1/entities --header 'Content-Type:application/json' --data '{"id":"urn:ngsi-ld:Entity:test_entity03","type":"Room","temperature":{"type":"Property","value":29}}'
#Post Subscription
curl -X POST --url 'http://localhost:1026/ngsi-ld/v1/subscriptions' --header 'Content-Type: application/json' --data '{"description":"TestSubscription","id":"urn:ngsi-ld:Subscription:test_sub25","type":"Subscription","entities":[{"idPattern":".*","type":"Room"}],"watchedAttributes":["temperature"],"q":"temperature>30","notification":{"attributes":["temperature"],"format":"normalized","endpoint":{"uri":"mqtt://mosquitto:1883/my/test/topic"}}}'
#Update Entity
sleep 5
curl -iX PATCH --url 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Entity:test_entity03/attrs' --header 'Content-Type: application/json' --data-raw '{"temperature":{"type":"Property","value":35}}' 
#Update Subscription
curl -iX PATCH --url 'http://localhost:1026/ngsi-ld/v1/subscriptions/urn:ngsi-ld:Subscription:test_sub25' --header 'Content-Type: application/json' --data-raw '{"q":"temperature<30"}'
#Update entity
sleep 5
curl -iX PATCH --url 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Entity:test_entity03/attrs' --header 'Content-Type: application/json' --data-raw '{"temperature":{"type":"Property","value":24}}'
sleep 5
curl -iX PATCH --url 'http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Entity:test_entity03/attrs' --header 'Content-Type: application/json' --data-raw '{"temperature":{"type":"Property","value":35}}' 
kzangeli commented 2 months ago

Seems like a bug in the subscription cache, not updating 'q' correctly. I'm on it. Just, on a business trip all next week. I'll do my best.

As a workaround, try PATCH http://localhost:1026/ngsi-ld/v1/entities/urn:ngsi-ld:Entity:test_entity03 instead of the one ending in /attrs (the one you use replaces the attribute, it's really a PUT, not a PATCH, while the one I propose is a proper PATCH).

What CLI params do you use when starting Orion-LD ?

kzangeli commented 2 months ago

Nah, idiot proposal (removing /attrs from the URL path of the entity patch request), the bug is in t he PATCH of the subscription. I just tested both and the bug is (wrong q in sub-cache after subscription patch) there for noth versions of PATCH Entity. So, scratch that.

SystemsPurge commented 2 months ago

@kzangeli To answer the question about the CLI params , its a docker image ( in a compose file ) with the following env vars and command: environment:

kzangeli commented 2 months ago

Still working on this. Found a solution though, long story, try adding the option -experimental. The entire DB layer has been reimplemented, using a newer mongo driver. I tried it and it seems to be working.