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 264 forks source link

JEXL. Include attribute metadata in evaluation context #4594

Closed fgalan closed 1 month ago

fgalan commented 1 month ago

Is your feature request related to a problem / use case? Please describe.

Adding attribute metadata context will enhance CB JEXL notification features. For instance, we could define a new attribute which value is the one in some metadata.

Describe the solution you'd like

Include attribute metadata in evaluation context at JEXL context building time.

Describe alternatives you've considered

Considering the following entity:

A value is 1,
A metadata MD1 value is 11
A metadata MD1 value is 12
B value is 2,
B metadata MD1 value is 21
B metadata MD1 value is 22

Alternative 1: use a metadata object, which keys would be attribute names. So evaluation context will be:

A: 1
B: 2
metadata: {
  A: {MD1: 11, MD2: 12},
  B: {MD1: 21, MD2: 22},
}

Alternative 2: don't use an object, but a "flatten" of context identifiers, this way:

A: 1
B: 2
A__metadata__MD1: 11
A__metadata__MD2: 12
B__metadata__MD1: 21
B__metadata__MD2: 22

In both case, name collision could occur (i.e. new object metadata could collide if some attribute is named metatata in alterative 1 and the same with attributes named eg. A__metadata__MD1) but this would be very weird and an anti-pattern.

Describe why you need this feature

fgalan commented 1 month ago

The built-in attributes in https://github.com/telefonicaid/fiware-orion/blob/master/doc/manuals/orion-api.md#builtin-metadata could be included in the context:

In fact, adding previousValue would solve issue https://github.com/telefonicaid/fiware-orion/issues/4560

mrutid commented 1 month ago

For me 1) since JEXL provides great built in features to access JSON/Object data information and filtering.

fgalan commented 1 month ago

After a brief internal discussion, let's go for alternative 1

mapedraza commented 1 month ago

Did you consider to use a "less usual name", like __metadata to avoid unintentional collisions?

fgalan commented 1 month ago

Did you consider to use a "less usual name", like __metadata to avoid unintentional collisions?

Maybe, but the syntax is more "dirty"...

Is any actual probability that some insane user :) names an attribute with the name metadata ?

fgalan commented 1 month ago

PR https://github.com/telefonicaid/fiware-orion/pull/4600