Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
db64003
Improve type checking in oonirun
LDiazN May 16, 2025
b98c9c0
Added targets_name and inputs_extra parameters
LDiazN May 21, 2025
5bcc9ee
Moved fields to right model
LDiazN May 21, 2025
d1c610c
Add migration for targets_name and input_extra
LDiazN May 21, 2025
6083adc
Add more tests to the sample oonirun link
LDiazN May 22, 2025
018cda1
Test insert of new nettests
LDiazN May 22, 2025
4267822
Add targets_name and inputs_extra to oonirun
LDiazN May 22, 2025
f041939
Add tests to check consistency of inputs_extra
LDiazN May 22, 2025
b0c9792
Add inputs_extra validation
LDiazN May 22, 2025
0ab1cae
Fixed broken test
LDiazN May 22, 2025
69f33b4
Add TODO comment
LDiazN May 22, 2025
e39a125
Removed useless comment
LDiazN May 22, 2025
d6fce79
Add filter by revision and test
LDiazN May 23, 2025
cd9fab9
Removed unused imports
LDiazN May 23, 2025
a2613c5
Added missing arguments to engine-descriptor and tests
LDiazN May 23, 2025
e784589
Add headers for dynamic test lists calculation
LDiazN May 23, 2025
1e79ef4
Add arguments for dynamic targets list generation
LDiazN May 23, 2025
cd4e6c3
Rename postgres session dependency
LDiazN May 26, 2025
1868336
Fix typo
LDiazN May 26, 2025
9f92981
Prevent both of targets_name and inputs to be present at the same time
LDiazN May 27, 2025
bf1a695
Remove unused import
LDiazN May 27, 2025
800753d
Drop backend options parameter
LDiazN May 27, 2025
631c61a
Drop backend options parameter
LDiazN May 27, 2025
60f8775
Working on headers parsing
LDiazN May 27, 2025
402c899
Merge branch 'master' into oonirun-v2-1
LDiazN May 27, 2025
2d701fa
Add tests for header parsing; moving arguments out of headers to post
LDiazN May 28, 2025
0f50f7a
Skip user agent parsing tests for now
LDiazN May 28, 2025
5645e77
Move prio to common
LDiazN May 28, 2025
af5bbf3
Move prio to common
LDiazN May 28, 2025
4c02b03
Move prio to common
LDiazN May 28, 2025
aba48e4
Changed priority list type
LDiazN May 28, 2025
3219604
Added clickhouse to oonirun
LDiazN May 29, 2025
9d92042
Add clickhouse to clients for testing
LDiazN May 29, 2025
06e1d0e
Set up get_nettest for dynamic lists calculation
LDiazN May 29, 2025
ea6cafb
Enforce targets_name/inputs validation only on write ops
LDiazN May 29, 2025
62b7864
Rename function to dynamically compute test lists
LDiazN May 29, 2025
0c9ddf6
Add dynamic test lists calculation to engine-descriptor endpoint
LDiazN May 29, 2025
32d524b
Improve validation of inputs_extra field
LDiazN May 29, 2025
8e4279f
Add todo
LDiazN May 29, 2025
80db37a
Fix bad creation of oonirun links with targets_name
LDiazN May 29, 2025
2705195
Fix bug assigning None to targets_name when not needed
LDiazN May 29, 2025
f2ebdc1
Add header parsing for engine-descriptor endpoint
LDiazN May 30, 2025
09515db
Fix broken test
LDiazN May 30, 2025
ec9f7b3
Fix broken test
LDiazN May 30, 2025
22a4eb8
Add integration test for dynamic lists calculation
LDiazN May 30, 2025
d0062c2
Remove useless prints
LDiazN May 30, 2025
673c907
Fix broken tests
LDiazN May 30, 2025
1a1f203
Remove print
LDiazN May 30, 2025
083e286
Add test for filtering with category codes
LDiazN Jun 2, 2025
b9ec631
Add setup for creating measurements for testing url priorization
LDiazN Jun 2, 2025
ec10d06
Add test for prioritization with measurements
LDiazN Jun 3, 2025
e2b2280
Add url basic url priorities tests
LDiazN Jun 3, 2025
8769092
Remove useless print
LDiazN Jun 3, 2025
b507c99
Simplify header format
LDiazN Jun 3, 2025
248a89b
Simplify get_nettests function
LDiazN Jun 3, 2025
f389bd6
Revert "Simplify get_nettests function"
LDiazN Jun 3, 2025
b5f4308
black reformat
LDiazN Jun 4, 2025
279c0b6
fix bad ooni domain
LDiazN Jun 4, 2025
5f41fca
Move fixtures to conftest; root fixtures dir to THIS_DIR
LDiazN Jun 4, 2025
e25e053
Add network type validation and some tests
LDiazN Jun 4, 2025
f3a9147
Improve ASN validation
LDiazN Jun 4, 2025
54f8f0f
rename header for anonymous credentials
LDiazN Jun 4, 2025
c823315
Remove only_latest parameter
LDiazN Jun 4, 2025
a3f1a8d
Simplify user agent header parsing
LDiazN Jun 4, 2025
70240f3
Changed default value of inputs field
LDiazN Jun 4, 2025
59f47dd
Add flag to compute dynamic lists in get_nettest function
LDiazN Jun 4, 2025
f53a30a
Remove backend_options and options, even from the DB
LDiazN Jun 4, 2025
0d28ee7
Split dynamic test list calculation from nettest db fetch
LDiazN Jun 4, 2025
eeb9743
drop backend_options and options column
LDiazN Jun 5, 2025
3d09989
Add backend_options and options on downgrade
LDiazN Jun 5, 2025
a7bf78f
Restor options field in nettest
LDiazN Jun 10, 2025
6868ab9
trigger CI
LDiazN Jun 10, 2025
48e60d9
Add bluetooth and usb as valid network types
LDiazN Jun 18, 2025
34f0c3e
Fix conflicts oonirun v2 1 (#1056)
aagbsn Jan 22, 2026
e2281f8
merge conflict
LDiazN Jan 22, 2026
819eff9
refactor tests
LDiazN Jan 22, 2026
0ab5f3e
refactor tests
LDiazN Jan 22, 2026
b5db96f
Remove merge conflict
LDiazN Jan 22, 2026
884306b
trigger ci
LDiazN Jan 29, 2026
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Add targets_name and inputs_extra columns to oonirun_nettest

Revision ID: b860eb79750f
Revises: 8e7ecea5c2f5
Create Date: 2025-05-21 15:44:32.959349

"""

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = "b860eb79750f"
down_revision: Union[str, None] = "8e7ecea5c2f5"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
op.add_column(
"oonirun_nettest", sa.Column("targets_name", sa.String(), nullable=True)
)
op.add_column(
"oonirun_nettest", sa.Column("inputs_extra", sa.ARRAY(sa.JSON()), nullable=True)
)
op.drop_column("oonirun_nettest", "backend_options")


def downgrade() -> None:
op.drop_column("oonirun_nettest", "targets_name")
op.drop_column("oonirun_nettest", "inputs_extra")
Comment thread
hellais marked this conversation as resolved.

op.add_column("oonirun_nettest", sa.Column("backend_options", sa.ARRAY(sa.JSON()), nullable=True))
33 changes: 32 additions & 1 deletion ooniapi/common/src/common/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from functools import lru_cache
from typing import Annotated
from typing import Annotated, TypeAlias

from clickhouse_driver import Client as Clickhouse

from fastapi import Depends
from fastapi import HTTPException, Header
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session

from .auth import get_client_token
from .config import Settings

Expand All @@ -11,6 +16,7 @@
def get_settings() -> Settings:
return Settings()

SettingsDep: TypeAlias = Annotated[Settings, Depends(get_settings)]

def role_required(roles: list[str]):
"""Wrapped function requiring user to be logged in and have the right role."""
Expand Down Expand Up @@ -38,3 +44,28 @@ async def verify_jwt(
return tok

return verify_jwt


def get_clickhouse_session(settings: SettingsDep):
db = Clickhouse.from_url(settings.clickhouse_url)
try:
yield db
finally:
db.disconnect()


ClickhouseDep = Annotated[Clickhouse, Depends(get_clickhouse_session)]


def get_postgresql_session(settings: SettingsDep):
engine = create_engine(settings.postgresql_url)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

db = SessionLocal()
try:
yield db
finally:
db.close()


PostgresDep = Annotated[Session, Depends(get_postgresql_session)]
1 change: 1 addition & 0 deletions ooniapi/common/src/common/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class Base(DeclarativeBase):
Dict[str, Any]: sa.JSON,
List[str]: sa.JSON,
Dict[str, str]: sa.JSON,
List[Dict[str, Any]] : sa.ARRAY(sa.JSON())
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

"""
OONI Probe Services API - reactive URL prioritization

Expand Down Expand Up @@ -32,8 +33,8 @@
from fastapi import Depends
from pydantic import BaseModel

from .common.clickhouse_utils import query_click
from .common.metrics import timer
from .clickhouse_utils import query_click
from .metrics import timer
from .dependencies import ClickhouseDep

log = logging.getLogger(__name__)
Expand Down
1 change: 1 addition & 0 deletions ooniapi/services/ooniauth/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ classifiers = [
]
dependencies = [
"fastapi ~= 0.108.0",
"clickhouse-driver ~= 0.2.6",
"sqlalchemy ~= 2.0.27",
"ujson ~= 5.9.0",
"python-dateutil ~= 2.8.2",
Expand Down
30 changes: 0 additions & 30 deletions ooniapi/services/oonifindings/src/oonifindings/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,30 +0,0 @@
from typing import Annotated

from clickhouse_driver import Client as Clickhouse

from fastapi import Depends

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from .common.config import Settings
from .common.dependencies import get_settings


def get_postgresql_session(settings: Annotated[Settings, Depends(get_settings)]):
engine = create_engine(settings.postgresql_url)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)

db = SessionLocal()
try:
yield db
finally:
db.close()


def get_clickhouse_session(settings: Annotated[Settings, Depends(get_settings)]):
db = Clickhouse.from_url(settings.clickhouse_url)
try:
yield db
finally:
db.disconnect()
4 changes: 2 additions & 2 deletions ooniapi/services/oonifindings/src/oonifindings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .routers import v1


from .dependencies import get_settings, get_postgresql_session
from .common.dependencies import get_settings, get_postgresql_session
from .common.version import get_build_label, get_pkg_version
from .common.metrics import mount_metrics

Expand Down Expand Up @@ -40,7 +40,7 @@ async def lifespan(app: FastAPI):

app.add_middleware(
CORSMiddleware,
allow_origin_regex="^https://[-A-Za-z0-9]+(\.test)?\.ooni\.(org|io)$",
allow_origin_regex=r"^https://[-A-Za-z0-9]+(\.test)?\.ooni\.(org|io)$",
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down
20 changes: 10 additions & 10 deletions ooniapi/services/oonifindings/src/oonifindings/routers/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
get_client_role,
)
from ..common.utils import setnocacheresponse, generate_random_intuid
from ..dependencies import get_postgresql_session
from ..common.dependencies import SettingsDep, PostgresDep

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -128,6 +128,8 @@ class OONIFindingIncidents(BaseModel):
)
def list_oonifindings(
response: Response,
db: PostgresDep,
settings: SettingsDep,
only_mine: Annotated[bool, Query(description="show only owned items")] = False,
theme: Annotated[
list[str] | None,
Expand All @@ -146,8 +148,6 @@ def list_oonifindings(
Query(description="The domain to filter by"),
] = None,
authorization: str = Header("authorization"),
db=Depends(get_postgresql_session),
settings=Depends(get_settings),
):
"""
Search and list incidents
Expand Down Expand Up @@ -227,9 +227,9 @@ def list_oonifindings(
def get_oonifinding_by_id(
finding_id: str,
response: Response,
db: PostgresDep,
settings: SettingsDep,
authorization: str = Header("authorization"),
db=Depends(get_postgresql_session),
settings=Depends(get_settings),
):
"""
Returns an incident
Expand Down Expand Up @@ -323,10 +323,10 @@ def generate_finding_slug(create_time: datetime, title: str):
def create_oonifinding(
create_request: OONIFindingCreateUpdate,
response: Response,
db: PostgresDep,
settings: SettingsDep,
authorization: str = Header("authorization"),
token=Depends(role_required(["admin"])),
db=Depends(get_postgresql_session),
settings=Depends(get_settings),
):
"""
Create an incident
Expand Down Expand Up @@ -388,7 +388,7 @@ def create_oonifinding(
def update_oonifinding(
update_request: OONIFindingCreateUpdate,
response: Response,
db=Depends(get_postgresql_session),
db: PostgresDep,
token=Depends(role_required(["admin", "user"])),
):
"""
Expand Down Expand Up @@ -457,8 +457,8 @@ def update_oonifinding(
def delete_oonifinding(
delete_request: OONIFindingWithMail,
response: Response,
db: PostgresDep,
token=Depends(role_required(["admin", "user"])),
db=Depends(get_postgresql_session),
):
"""
Delete an incident
Expand Down Expand Up @@ -503,7 +503,7 @@ def update_oonifinding_publish_status(
action: str,
publish_request: OONIFindingId,
response: Response,
db=Depends(get_postgresql_session),
db: PostgresDep,
):
"""
Publish/Unpublish an incident.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
aggregate_analysis,
)

from .dependencies import get_clickhouse_session
from .common.dependencies import get_settings
from .common.dependencies import get_settings, get_clickhouse_session
from .common.version import get_build_label, get_pkg_version
from .common.clickhouse_utils import query_click
from .common.metrics import mount_metrics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import logging

from fastapi import APIRouter

router = APIRouter()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pydantic import BaseModel


from ...dependencies import get_clickhouse_session
from ...common.dependencies import get_clickhouse_session
from .utils import (
SinceUntil,
get_measurement_start_day_agg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
from .utils import (
SinceUntil,
parse_probe_asn_to_int,
test_name_to_group,
utc_30_days_ago,
utc_today,
)

log = logging.getLogger(__name__)

from fastapi import APIRouter

router = APIRouter()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from pydantic import BaseModel
from typing_extensions import Annotated

from ...common.dependencies import get_settings
from ...dependencies import get_clickhouse_session
from ...common.dependencies import get_settings, get_clickhouse_session
from .utils import parse_probe_asn_to_int

from fastapi import APIRouter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from oonimeasurements.common.clickhouse_utils import query_click, query_click_one_row
from oonimeasurements.common.utils import jerror, commasplit, convert_to_csv
from ...dependencies import get_clickhouse_session
from oonimeasurements.common.dependencies import get_clickhouse_session
from ...common.routers import BaseModel

router = APIRouter()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from ...common.routers import BaseModel
from ...common.utils import setcacheresponse, commasplit, setnocacheresponse
from ...common.clickhouse_utils import query_click, query_click_one_row
from ...dependencies import get_clickhouse_session
from ...common.dependencies import get_clickhouse_session

log = logging.getLogger(__name__)

Expand Down
2 changes: 1 addition & 1 deletion ooniapi/services/oonimeasurements/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from clickhouse_driver import Client as ClickhouseClient

from oonimeasurements.common.config import Settings
from oonimeasurements.dependencies import get_settings
from oonimeasurements.common.dependencies import get_settings
from oonimeasurements.main import app

THIS_DIR = Path(__file__).parent.resolve()
Expand Down
24 changes: 5 additions & 19 deletions ooniapi/services/ooniprobe/src/ooniprobe/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
import io
from typing import Annotated, TypeAlias, Any, Dict
from datetime import datetime
import time
from pathlib import Path

import boto3
import ujson
import geoip2.database
from fastapi import Depends

import geoip2.database
from mypy_boto3_s3 import S3Client

import ujson
from pydantic import BaseModel, Field
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, Session

from clickhouse_driver import Client as Clickhouse
import io

import boto3
from mypy_boto3_s3 import S3Client

from .common.config import Settings
from .common.dependencies import get_settings

Expand Down Expand Up @@ -54,17 +51,6 @@ def get_asn_reader(settings: SettingsDep):
ASNReaderDep = Annotated[geoip2.database.Reader, Depends(get_asn_reader)]


def get_clickhouse_session(settings: SettingsDep):
db = Clickhouse.from_url(settings.clickhouse_url)
try:
yield db
finally:
db.disconnect()


ClickhouseDep = Annotated[Clickhouse, Depends(get_clickhouse_session)]


def get_s3_client() -> S3Client:
s3 = boto3.client("s3")
return s3
Expand Down
Loading