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

Random sort of test helper addresses #838

Merged
merged 5 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
1 change: 1 addition & 0 deletions api/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ TESTARGS ?= \
tests/integ/test_private_api.py \
tests/integ/test_probe_services.py \
tests/unit/test_oonirun.py \
tests/unit/test_probe_services.py \
tests/unit/test_prio.py

#tests/integ/test_prioritization_nodb.py
Expand Down
7 changes: 7 additions & 0 deletions api/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
ooni-api (1.0.91) unstable; urgency=medium

* Remove 0.th from returned addresses
* Replace round_robin function with random sort

-- Arturo <[email protected]> Tue, 23 Apr 2024 09:15:18 +0100

ooni-api (1.0.90) unstable; urgency=medium

* Add 4.th to round robin
Expand Down
31 changes: 26 additions & 5 deletions api/ooniapi/probe_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from hashlib import sha512
from os import urandom
from pathlib import Path
import random
from typing import Dict, Any, Tuple, List, Optional
from urllib.request import urlopen
import ipaddress
Expand Down Expand Up @@ -244,7 +245,9 @@ def check_in() -> Response:
try:
charging = bool(charging)
except Exception:
log.error(f"check-in params: {url_limit} '{probe_cc}' '{charging}' '{run_type}' '{software_name}' '{software_version}'")
log.error(
f"check-in params: {url_limit} '{probe_cc}' '{charging}' '{run_type}' '{software_name}' '{software_version}'"
)

if "web_connectivity" in data:
catcodes = data["web_connectivity"].get("category_codes", [])
Expand Down Expand Up @@ -284,8 +287,8 @@ def check_in() -> Response:
# Temporarily disabled while we work towards deploying this in prod:
# https://github.com/ooni/probe/issues/2674
#
#octect = extract_probe_ipaddr_octect(1, 0)
#if octect in (34, 239):
# octect = extract_probe_ipaddr_octect(1, 0)
# if octect in (34, 239):
# conf["features"]["webconnectivity_0.5"] = True

conf["test_helpers"] = generate_test_helpers_conf()
Expand Down Expand Up @@ -325,7 +328,9 @@ def check_in() -> Response:
resp["tests"][tn]["report_id"] = rid # type: ignore

til = len(test_items)
log.debug(f"check-in params: {url_limit} {til} '{probe_cc}' '{charging}' '{run_type}' '{software_name}' '{software_version}'")
log.debug(
f"check-in params: {url_limit} {til} '{probe_cc}' '{charging}' '{run_type}' '{software_name}' '{software_version}'"
)

return nocachejson(**resp)

Expand Down Expand Up @@ -497,6 +502,15 @@ def probe_login_post() -> Response:
return nocachejson(token=token, expire=expire)


def random_web_test_helpers(th_list: List[str]) -> List[Dict]:
"""Randomly sort test helpers"""
random.shuffle(th_list)
out = []
for th_addr in th_list:
out.append({"address": th_addr, "type": "https"})
return out


def round_robin_web_test_helpers() -> List[Dict]:
"""Round robin test helpers based on the probe ipaddr.
0.th is special and gets only 10% of the traffic.
Expand Down Expand Up @@ -562,7 +576,14 @@ def generate_test_helpers_conf() -> Dict:
},
],
}
conf["web-connectivity"] = round_robin_web_test_helpers()
conf["web-connectivity"] = random_web_test_helpers(
[
"https://1.th.ooni.org",
"https://2.th.ooni.org",
"https://3.th.ooni.org",
"https://4.th.ooni.org",
]
)
conf["web-connectivity"].append(
{
"address": "https://d33d1gs9kpq1c5.cloudfront.net",
Expand Down
Loading
Loading