Skip to content

Commit

Permalink
analytics: fix typo to build the query
Browse files Browse the repository at this point in the history
adding nrt

Change-Id: I72bbb6d97a0aa2e3d39f847732a0425b6030509e
  • Loading branch information
ylamgarchal committed Oct 28, 2024
1 parent 9bb244e commit 642592b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
5 changes: 4 additions & 1 deletion dci/api/v1/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ def handle_es_timeframe(query, args):
]
}
}
return query


def handle_includes_excludes(args):
Expand Down Expand Up @@ -305,14 +306,16 @@ def build_es_query(args):
if _source:
es_query["_source"] = _source

return es_query


@api.route("/analytics/jobs", methods=["GET", "POST"])
@decorators.login_required
def tasks_jobs(user):
if user.is_not_super_admin() and user.is_not_epm() and user.is_not_read_only_user():
raise dci_exc.Unauthorized()

es_query = build_es_query()
es_query = build_es_query(flask.request.args.to_dict())

try:
res = requests.get(
Expand Down
71 changes: 71 additions & 0 deletions tests/api/v1/test_analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,74 @@ def test_handle_includes_excludes():

ret = analytics.handle_includes_excludes({})
assert ret == {}


def test_build_es_query():
args = {
"offset": 10,
"limit": 10,
"query": "(((components.type=ocp) and (components.tags in [build:ga])) and ((components.type=f5-spk)) and (tags in [daily]))",
"sort": "-created_at",
"from": "2024-01-01",
"to": "2024-02-01",
"includes": "team,topic",
"excludes": "jobstates",
}
ret = analytics.build_es_query(args)
assert ret == {
"from": 10,
"size": 10,
"query": {
"bool": {
"filter": [
{
"range": {
"created_at": {"gte": "2024-01-01", "lte": "2024-02-01"}
}
},
{
"bool": {
"filter": [
{
"nested": {
"path": "components",
"query": {
"bool": {
"filter": [
{
"term": {
"components.type": "ocp"
}
},
{
"terms": {
"components.tags": [
"build:ga"
]
}
},
]
}
},
}
},
{
"nested": {
"path": "components",
"query": {
"term": {"components.type": "f5-spk"}
},
}
},
{"terms": {"tags": ["daily"]}},
]
}
},
]
}
},
"sort": [
{"created_at": {"order": "desc", "format": "strict_date_optional_time"}}
],
"_source": {"excludes": ["jobstates"], "includes": ["team", "topic"]},
}

0 comments on commit 642592b

Please sign in to comment.