Skip to content

Commit

Permalink
Add aggregation filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoCeratto committed Oct 17, 2023
1 parent e7ac4ad commit fa74631
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
11 changes: 11 additions & 0 deletions api/ooniapi/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from ooniapi.database import query_click, query_click_one_row
from ooniapi.utils import jerror, convert_to_csv
from ooniapi.urlparams import (
commasplit,
param_asn_m,
param_date,
param_domain_m,
Expand Down Expand Up @@ -141,6 +142,10 @@ def get_aggregated() -> Response:
in: query
type: string
description: Name of the tests, comma separated
- name: ooni_run_link_ids
in: query
type: string
description: OONIRun descriptors comma separated
- name: since
in: query
type: string
Expand Down Expand Up @@ -203,6 +208,7 @@ def get_aggregated() -> Response:
inp = param_input_or_none() or ""
probe_asn_s = param_asn_m()
probe_cc_s = param_probe_cc_m()
ooni_run_link_ids_raw = param("ooni_run_link_ids")
since = param_date("since")
until = param_date("until")
time_grain = param("time_grain", "auto").lower()
Expand Down Expand Up @@ -269,6 +275,11 @@ def get_aggregated() -> Response:
where.append(sql.text("probe_asn IN :probe_asn_s"))
query_params["probe_asn_s"] = probe_asn_s

if ooni_run_link_ids_raw:
ooni_run_link_ids = commasplit(ooni_run_link_ids_raw)
where.append(sql.text("ooni_run_link_id IN :ooni_run_link_ids"))
query_params["ooni_run_link_ids"] = ooni_run_link_ids

if since:
where.append(sql.text("measurement_start_time >= :since"))
query_params["since"] = since
Expand Down
3 changes: 2 additions & 1 deletion api/tests/integ/clickhouse_1_schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ CREATE TABLE default.fastpath
`engine_version` String,
`blocking_type` String,
`test_helper_address` LowCardinality(String),
`test_helper_type` LowCardinality(String)
`test_helper_type` LowCardinality(String),
`ooni_run_link_id` UInt64
)
ENGINE = ReplacingMergeTree
ORDER BY (measurement_start_time, report_id, input)
Expand Down
18 changes: 18 additions & 0 deletions api/tests/integ/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,24 @@ def test_aggregation_no_axis_filter_multi_test_name_1_axis(client):
}, fjd(r)


def test_aggregation_no_axis_filter_multi_oonirun(client):
# 0-dimensional data
url = "aggregation?ooni_run_link_ids=1234,2345&since=2021-07-09&until=2021-07-10"
r = api(client, url)
r.pop("db_stats", None)
assert r == {
"dimension_count": 0,
"result": {
"anomaly_count": 0,
"confirmed_count": 0,
"failure_count": 0,
"measurement_count": 0,
"ok_count": 0,
},
"v": 0,
}, fjd(r)


def test_aggregation_x_axis_only(client, log):
# 1 dimension: X
url = "aggregation?probe_cc=CH&probe_asn=AS3303&since=2021-07-09&until=2021-07-11&time_grain=day&axis_x=measurement_start_day"
Expand Down

0 comments on commit fa74631

Please sign in to comment.