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

JEXL expressions in custom notifications #4511

Merged
merged 113 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
0005522
ADD first version of jexlManager with init method to load Python inte…
fgalan Jan 31, 2024
42f215e
FIX PoC to measure times
fgalan Feb 5, 2024
e696631
FIX JexlManager init() and release() methods
fgalan Feb 7, 2024
7f1b784
Merge branch 'master' into feature/4004_jexl_expressions
fgalan Feb 8, 2024
1038622
FIX replace map by JEXL context (compiles but still wip)
fgalan Feb 9, 2024
cda7164
FIX improve JexlContext class
fgalan Feb 9, 2024
e1389f6
FIX improve JexlManager and JexlContext classes
fgalan Feb 9, 2024
cbd523b
FIX use JEXL evaluate to evaluate macros
fgalan Feb 9, 2024
590af6e
FIX increase debug log tracing in jexl library
fgalan Feb 9, 2024
9dfdccc
FIX jexl implementation
fgalan Feb 12, 2024
726dc9c
FIX add pyjexl to CI image
fgalan Feb 12, 2024
904c965
FIX comments in Dockerfiles
fgalan Feb 14, 2024
ae88c6e
ADD JexlResult class (still wip)
fgalan Feb 14, 2024
fb5939d
ADD new JexlContextList
fgalan Feb 14, 2024
8a6c762
FIX expression evaluation logic
fgalan Feb 14, 2024
7231ad4
FIX value not given processing logic
fgalan Feb 14, 2024
06e0d98
FIX ftest
fgalan Feb 14, 2024
444b6e2
Revert "FIX value not given processing logic"
fgalan Feb 15, 2024
e20b1e3
Revert "FIX ftest"
fgalan Feb 15, 2024
ae3d83b
FIX ftest
fgalan Feb 15, 2024
a57599d
FIX add CompoundValue to JexlResult
fgalan Feb 16, 2024
9ea1c82
FIX JexlResult improvements (wip)
fgalan Feb 16, 2024
f9f9ed6
FIX JexlResult improvements (wip)
fgalan Feb 19, 2024
d7b3a66
FIX JexlResult improvements
fgalan Feb 19, 2024
4a5d3e3
FIX JexlResult improvements
fgalan Feb 19, 2024
9827b46
FIX cleanup
fgalan Feb 19, 2024
8e3bdd3
FIX rename jexl to expression in class names and so
fgalan Feb 19, 2024
49a3694
FIX refactor common code and fix utest
fgalan Feb 19, 2024
8417f19
FIX enable venv in ci image utest
fgalan Feb 19, 2024
8cebfdd
FIX improvement
fgalan Feb 19, 2024
0beb957
FIX refactor
fgalan Feb 19, 2024
6f77ee5
FIX indent
fgalan Feb 19, 2024
b56cd7e
FIX add libpython to version operation
fgalan Feb 21, 2024
df3e8dd
FIX version operation
fgalan Feb 21, 2024
a8411ab
FIX new ftest
fgalan Feb 21, 2024
92e9289
ADD exprLang
fgalan Feb 26, 2024
1592131
Merge branch 'master' into feature/4004_jexl_expressions
fgalan Feb 26, 2024
f2a601a
FIX temporarly force legacy mode in ExprContext to check all ftest in…
fgalan Feb 26, 2024
b16e897
Merge branch 'feature/4004_jexl_expressions' of github.com:telefonica…
fgalan Feb 26, 2024
450374a
wip
fgalan Feb 28, 2024
2386677
FIX ftest for legacy forced test
fgalan Mar 5, 2024
69ff5de
Merge branch 'master' into feature/4004_jexl_expressions
fgalan Mar 5, 2024
742936f
FIX rollback hack to use always legacy expressions
fgalan Mar 6, 2024
ea94c57
FIX change pyjexl by tcjexl
fgalan Mar 6, 2024
a71c173
ADD ftest for null values and not defined attrs cases
fgalan Mar 7, 2024
e6f0e6b
ADD ftest for array filtering
fgalan Mar 7, 2024
3a1474a
FIX upgrade tcjexl to 0.2.0 in CI Dockerfile
fgalan Mar 11, 2024
0c6fcd4
ADD ftest jexl_transformation_with_arguments
fgalan Mar 11, 2024
2bc5287
Merge branch 'master' into feature/4004_jexl_expressions
fgalan Mar 11, 2024
2cc2424
FIX remove forbidden chars restrictions in ngsi subfields
fgalan Mar 11, 2024
3968dfa
FIX remove Python jexl implementation
fgalan Apr 12, 2024
6504fe6
FIX solution without ExprResult class (have problemas with rendering …
fgalan Apr 15, 2024
ed875f5
Revert "FIX solution without ExprResult class (have problemas with re…
fgalan Apr 15, 2024
9cc132a
FIX new cjexl function names and cjexl_version() usage
fgalan Apr 15, 2024
8097a8d
FIX ExprResult implementation
fgalan Apr 15, 2024
c5411b3
FIX cleanup
fgalan Apr 18, 2024
2a20139
FIX align version tests
fgalan Apr 19, 2024
fb976cd
FIX unit tests
fgalan Apr 22, 2024
390edea
Merge branch 'master' into feature/4004_jexl_expressions
fgalan Apr 22, 2024
b91409c
Merge branch 'feature/4004_jexl_expressions' into task/from-python-to…
fgalan Apr 22, 2024
30d4556
FIX libcjexl download in CI build.sh
fgalan Apr 24, 2024
9b02e23
FIX add token to gitactions that need it
fgalan Apr 24, 2024
ecdef99
Merge pull request #4538 from telefonicaid/task/from-python-to-cjexl
mapedraza Apr 24, 2024
3091187
FIX syntax error in GitActions
fgalan Apr 24, 2024
280d8f7
FIX GitAction unit tests
fgalan Apr 24, 2024
2169983
FIX improve buid.sh
fgalan Apr 25, 2024
49aa74c
FIX ExprResult::release() in the proper places
fgalan Apr 25, 2024
c9a0e58
FIX add ExprResult constructor to initialize compoundValueP to NULL
fgalan Apr 25, 2024
ecf7fbd
FIX add expr fields in timing section in GET /statistics
fgalan Apr 26, 2024
4db6066
FIX PoC to measure times CJEXL
fgalan Apr 26, 2024
b95dd16
FIX PoC to compare CJEXL with std::map
fgalan Apr 26, 2024
64ed369
Revert last two commits with PoC
fgalan Apr 26, 2024
9434b9c
FIX revert exprLang
fgalan May 8, 2024
48814b7
FIX legacy term changed to basic
fgalan May 8, 2024
81e98c6
ADD get_cjex.sh
fgalan May 8, 2024
8eefa7e
FIX Dockerfile
fgalan May 8, 2024
9151885
FIX add new jexl test cases
fgalan May 8, 2024
76234f4
FIX some FIXME PR marks
fgalan May 8, 2024
4bf6133
FIX conditional compilinig depending on cjexl availability
fgalan May 8, 2024
25b463c
ADD jexl_missing_attribute_as_null.test test
fgalan May 13, 2024
d510856
FIX simplify attribute_as_null test case and add extra one
fgalan May 14, 2024
264a9a6
FIX improve missing attribute as null jexl tests
fgalan May 17, 2024
dc35a4a
ADD GitAction to publish docker in Dockerhub for branches
fgalan May 17, 2024
2a75eb1
FIX GitAction login step
fgalan May 17, 2024
e789afc
FIX GitAction dockerhub credential fix
fgalan May 17, 2024
7281e1f
ADD GitAction for build docker for tags
fgalan May 17, 2024
8e92831
Update test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_n…
fgalan May 20, 2024
12c4574
ADD jexl_transformation_full.test
fgalan May 21, 2024
62d1a22
FIX remove FIXME PR mark
fgalan May 21, 2024
21d8f28
FIX CMakeList.txt
fgalan May 22, 2024
d5a1494
FIX conditional testing depending on expr flavour
fgalan May 22, 2024
68425b9
FIX to make basic behaviour the same than jexl regarding null
fgalan May 22, 2024
d7f2544
Merge branch 'master' into feature/4004_jexl_expressions
fgalan May 23, 2024
42c3a9a
ADD more test for null values cases
fgalan May 24, 2024
fcb9304
FIX null behaviour in custom notification payload field
fgalan May 27, 2024
ac2f915
FIX ftest
fgalan May 27, 2024
d039ce1
ADD log, log10, log2 and sqrt tests
fgalan May 27, 2024
13e2034
FIX use cjexl 0.1.0
fgalan May 27, 2024
9cdcb52
FIX memory leak
fgalan May 27, 2024
da9c9b5
ADD documentation
fgalan May 27, 2024
826ffdd
FIX basic replacement logic
fgalan May 27, 2024
9e04d8c
FIX warning about special chars
fgalan May 27, 2024
8587216
FIX enhance CNR
fgalan May 27, 2024
90ca88e
ADD mapper and thMapper transformations tests
fgalan May 28, 2024
e3a3f45
FIB use cjexl 0.2.0
fgalan May 28, 2024
ba0826f
FIX improve get_cjexl.sh
fgalan May 28, 2024
41f046f
ADD additional jexl expression test
fgalan May 28, 2024
486e7df
ADD JEXL usage example to doc
fgalan May 29, 2024
b0df97e
FIX doc
fgalan May 29, 2024
047a63b
Apply suggestions from code review
fgalan May 29, 2024
fbde34e
Update doc/manuals/orion-api.md
fgalan May 29, 2024
cfa543a
Update test/functionalTest/cases/4004_jexl_expressions_in_subs/jexl_t…
fgalan May 29, 2024
06cbe4e
Update doc/manuals/orion-api.md
fgalan May 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/functional.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,4 @@ jobs:

- name: Run functional test
run: |
docker run --network host -t --rm ${{ matrix.payload.range }} -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts functional
docker run --network host -t --rm -e REPO_ACCESS_TOKEN=${{ secrets.REPO_ACCESS_TOKEN }} ${{ matrix.payload.range }} -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts functional
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Publish pre Image from master
name: Publish pre Image from master in FIWARE dockerhub

# The workflow will push PRE images from master on every merge. The images will be tagged with PRE and the next minor increase on the
# The workflow will push PRE images from master on every merge to the fiware dockerhub organization. The images will be tagged with PRE and the next minor increase on the
# semver(based on the github releases)
# It will NOT produce releases and release images or the 'latest' tag from master. Both (releases and 'latest' tag) rely on the
# dockerhub autobuild feature
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/publishimage-master.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Publish Docker image (master)

# The workflow will push images for master on every merge
fgalan marked this conversation as resolved.
Show resolved Hide resolved
# Ideally, this should be done at dockerhub, but it doesn't support secrets (see https://stackoverflow.com/questions/78446824/use-environment-variables-with-sensible-information-in-docker-hub-autobuild)

on:
push:
branches:
- master

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_TEF_USERNAME }}
password: ${{ secrets.DOCKERHUB_TEF_TOKEN }}

- name: Build Docker image
run: docker build -t telefonicaiot/fiware-orion:latest --build-arg GIT_REV_ORION=master --build-arg REPO_ACCESS_TOKEN=${{ secrets.REPO_ACCESS_TOKEN }} --no-cache -f docker/Dockerfile .

- name: Push Docker image
run: docker push telefonicaiot/fiware-orion:latest
36 changes: 36 additions & 0 deletions .github/workflows/publishimage-tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Publish Docker image (tag)

# The workflow will push images on every tag in the format x.y.z
fgalan marked this conversation as resolved.
Show resolved Hide resolved
# Ideally, this should be done at dockerhub, but it doesn't support secrets (see https://stackoverflow.com/questions/78446824/use-environment-variables-with-sensible-information-in-docker-hub-autobuild)

on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'

jobs:
build-and-push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_TEF_USERNAME }}
password: ${{ secrets.DOCKERHUB_TEF_TOKEN }}

- name: Extract version from tag
id: extract_version
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Build Docker image
run: docker build -t telefonicaiot/fiware-orion:${{ env.VERSION }} --build-arg GIT_REV_ORION=${{ env.VERSION }} --build-arg REPO_ACCESS_TOKEN=${{ secrets.REPO_ACCESS_TOKEN }} --no-cache -f docker/Dockerfile .

- name: Push Docker image
run: docker push telefonicaiot/fiware-orion:${{ env.VERSION }}
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ jobs:

- name: Run unit tests
run: |
docker run --network host -t --rm -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts unit
docker run --network host -t --rm -e REPO_ACCESS_TOKEN=${{ secrets.REPO_ACCESS_TOKEN }} -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts unit
2 changes: 1 addition & 1 deletion .github/workflows/valgrind-nocache.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ jobs:

- name: Run valgrind test
run: |
docker run --privileged --network host -t --rm ${{ matrix.payload.range }} -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts valgrind
docker run --privileged --network host -t --rm -e REPO_ACCESS_TOKEN=${{ secrets.REPO_ACCESS_TOKEN }} ${{ matrix.payload.range }} -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts valgrind
2 changes: 1 addition & 1 deletion .github/workflows/valgrind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ jobs:

- name: Run valgrind test
run: |
docker run --privileged --network host -t --rm ${{ matrix.payload.range }} -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts valgrind
docker run --privileged --network host -t --rm -e REPO_ACCESS_TOKEN=${{ secrets.REPO_ACCESS_TOKEN }} ${{ matrix.payload.range }} -v $(pwd):/opt/fiware-orion ${{ env.TEST_IMAGE_NAME }} build -miqts valgrind
4 changes: 4 additions & 0 deletions CHANGES_NEXT_RELEASE
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
- Add: JEXL expression support in custom notification macro replacement (using cjexl 0.2.0) (#4004)
- Add: expression context build and evaluation counters in timing section in GET /statistics (#4004)
- Fix: use null for non existing attributes in custom covered notifications macro substitution (instead of empty string) to make behaviour more consistent (#4004)
- Fix: use null for non existing attributes in macro substitution applied to "paylaod" field (instead of empty string) to make behaviour more consistent (#4004)
- Fix: simplified GET /version operation, without including "libversions" field (add ?options=libVersions to get it)
- Fix: lighter operation to get databases list from MongoDB (#4517)
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ SET (ORION_LIBS
common
alarmMgr
metricsMgr
expressions
logSummary
lm
pa
Expand All @@ -229,10 +230,20 @@ SET (BOOST_MT
# SET for common static libs. We use 1.24.3 as reference version.
find_package (mongoc-1.0 1.24.3 EXACT)

# Is cjexl lib available?
find_library (HAVE_CJEXL cjexl PATHS /usr/lib /usr/lib64 /usr/local/lib64 /usr/local/lib)
if (HAVE_CJEXL)
message("Using cjexl")
else (HAVE_CJEXL)
message("Not using cjexl")
add_definitions(-DEXPR_BASIC)
endif (HAVE_CJEXL)

# Static libs common to contextBroker and unitTest binaries
SET (COMMON_STATIC_LIBS
microhttpd.a
mosquitto.a
${HAVE_CJEXL}
mongo::mongoc_static
)

Expand Down Expand Up @@ -264,7 +275,6 @@ endif (UNIT_TEST)
#
include_directories("/usr/include")


# Needed for the new C driver
include_directories("/usr/local/include/libmongoc-1.0")
include_directories("/usr/local/include/libbson-1.0")
Expand Down Expand Up @@ -319,6 +329,7 @@ if (error EQUAL 0)
ADD_SUBDIRECTORY(src/lib/cache)
ADD_SUBDIRECTORY(src/lib/alarmMgr)
ADD_SUBDIRECTORY(src/lib/metricsMgr)
ADD_SUBDIRECTORY(src/lib/expressions)
ADD_SUBDIRECTORY(src/lib/logSummary)
ADD_SUBDIRECTORY(src/lib/mqtt)
ADD_SUBDIRECTORY(src/app/contextBroker)
Expand Down
6 changes: 6 additions & 0 deletions ci/deb/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ echo "===================================== PREPARE ============================
echo "Builder: create temp folders"
rm -Rf /tmp/builder || true && mkdir -p /tmp/builder/{db1,db2,db,bu}

if [ -z "${REPO_ACCESS_TOKEN}" ]; then
echo "Builder: no REPO_ACCESS_TOKEN, skipping cjexl lib download"
else
bash /opt/fiware-orion/get_cjexl.sh 0.2.0 $REPO_ACCESS_TOKEN
fi

if [ -n "${branch}" ]; then
echo "===================================== CLONE ============================================"

Expand Down
2 changes: 2 additions & 0 deletions doc/manuals/admin/build_source.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Orion Context Broker reference distribution is Debian 12. This doesn't mean that

You can also have a look to [3.1 Building in not official distributions](../../../docker/README.md#31-building-in-not-official-distributions) section in the Docker documentation to check how to build Docker containers images in distributions other than the official one.

*NOTE:* the build process described in this document does not include the cjexl library, as it is considered optional from the point of view of the basic building process.

## Debian 12 (officially supported)

The Orion Context Broker uses the following libraries as build dependencies:
Expand Down
35 changes: 21 additions & 14 deletions doc/manuals/admin/statistics.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,22 @@ Provides timing information, i.e. the time that CB passes executing in different
"timing": {
"accumulated": {
"jsonV1Parse": 7.860908311,
"mongoBackend": 416.796091597,
"mongoReadWait": 4656.924425628,
"mongoWriteWait": 259.347915990,
"mongoCommandWait": 0.514811318,
"render": 108.162782114,
"total": 6476.593504743
},
"jsonV2Parse": 120.680244446,
"mongoBackend": 12778.52734375,
"mongoReadWait": 7532.301757812,
"mongoWriteWait": 3619.282226562,
"mongoCommandWait": 0.120559767,
"exprJexlCtxBld": 27.092681885,
"exprJexlEval": 124.217208862,
"render": 44.540554047,
"total": 25051.384765625
},
"last": {
"mongoBackend": 0.014752309,
"mongoReadWait": 0.012018445,
"mongoWriteWait": 0.000574611,
"render": 0.000019136,
"total": 0.015148915
}
"mongoBackend": 0.003775352,
"mongoReadWait": 0.0013743,
"render": 0.000286864,
"total": 0.00440685
}
}
...
}
Expand All @@ -167,10 +169,15 @@ The particular counters are as follows:
`last` includes the accumulation for all of them. In the case of mongoReadWait, only the time used
to get the results cursor is taken into account, but not the time to process cursors results (which
is time that belongs to mongoBackend counters).
* `exprJexlCtxBld`: time passed building context for custom notification expression evaluation (see [macro substitution](../orion-api.md#macro-substitution) and [JEXL support](../orion-api.md#jexl-support))
* `exprJexlEval`: time passed evaluating custom notification expressions (see [macro substitution](../orion-api.md#macro-substitution) and [JEXL support](../orion-api.md#jexl-support))

*NOTE*: if Orion binary is build without using cjexl and only basic replacement is available, then `exprBasicCtxtBld` and `exprBasicEval`
fields appear instead of `exprJexlCtxBld` and `exprJexlEval`.

Times are measured from the point in time in which a particular thread request starts using a module until it finishes using it.
Thus, if the thread is stopped for some reason (e.g. the kernel decides to give priority to another thread based on its
scheculing policy) the time that the thread was sleeping, waiting to execute again is included in the measurement and thus, the measurement is not accurate. That is why we say *pseudo* selt/end-to-end time. However,
scheculing policy) the time that the thread was sleeping, waiting to execute again is included in the measurement and thus, the measurement is not accurate. That is why we say *pseudo* self/end-to-end time. However,
under low load conditions this situation is not expected to have a significant impact.

### NotifQueue block
Expand Down
6 changes: 6 additions & 0 deletions doc/manuals/devel/sourceCode.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* [src/lib/cache/](#srclibcache) (Subscription cache implementation)
* [src/lib/logSummary/](#srcliblogsummary) (Log Summary implementation)
* [src/lib/metricsMgr/](#srclibmetricsmgr) (Metrics Manager implementation)
* [src/lib/expressions/](#srclibexpressions) (Custom notification expressions support)

## src/app/contextBroker/
The main program is found in `contextBroker.cpp` and its purpose it to:
Expand Down Expand Up @@ -551,3 +552,8 @@ This Metrics Manager resides in the library **metricsMgr**.
For information about the metrics, please refer to [this document](../admin/metrics_api.md).

[Top](#top)

## src/lib/expressions/
Provides support to the [macro substition logic used by custom notifications](../orion-api.md#macro-substitution). This library provides an abstraction for expression evaluation, providing two implementations: JEXL based and basic replacement based (the implementation to use is choosen at building time, based on the availability of the cjex library).

[Top](#top)
Loading
Loading