Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 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
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")

op.add_column("oonirun_nettest", sa.Column("backend_options", sa.ARRAY(sa.JSON()), nullable=True))
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 All @@ -24,8 +25,8 @@
from typing import List, Tuple
import logging

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

from clickhouse_driver import Client as Clickhouse
import sqlalchemy as sa
Expand Down Expand Up @@ -154,4 +155,4 @@ def generate_test_list(

if debug:
return out, entries, prio_rules
return out, (), ()
return out, (), ()
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from ...common.auth import create_jwt, decode_jwt, jwt
from ...common.config import Settings
from ...common.utils import setnocacheresponse
from ...prio import generate_test_list
from ...common.prio import generate_test_list

router = APIRouter(prefix="/v1")

Expand Down
2 changes: 1 addition & 1 deletion ooniapi/services/ooniprobe/tests/test_prio.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from ooniprobe import prio
from ooniprobe.common import prio


def test_prio():
Expand Down
2 changes: 1 addition & 1 deletion ooniapi/services/oonirun/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ packages = ["src/oonirun"]
artifacts = ["BUILD_LABEL"]

[tool.hatch.envs.default]
dependencies = ["pytest", "pytest-cov", "click", "black", "pytest-postgresql", "pytest-asyncio"]
dependencies = ["pytest", "pytest-cov", "click", "black", "pytest-postgresql", "pytest-asyncio", "pytest-docker"]
path = ".venv/"

[tool.hatch.envs.default.scripts]
Expand Down
24 changes: 21 additions & 3 deletions ooniapi/services/oonirun/src/oonirun/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from functools import lru_cache
from typing import Annotated

from fastapi import Depends

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import sessionmaker, Session

from clickhouse_driver import Client as Clickhouse

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


def get_postgresql_session(settings: Annotated[Settings, Depends(get_settings)]):
DependsSettings = Annotated[Settings, Depends(get_settings)]


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

Expand All @@ -19,3 +23,17 @@ def get_postgresql_session(settings: Annotated[Settings, Depends(get_settings)])
yield db
finally:
db.close()


DependsPostgresSession = Annotated[Session, Depends(get_postgresql_session)]


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


DependsClickhouseClient = Annotated[Clickhouse, Depends(get_clickhouse_session)]
25 changes: 22 additions & 3 deletions ooniapi/services/oonirun/src/oonirun/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
from . import models
from .routers import v2

from .dependencies import get_postgresql_session
from .dependencies import (
DependsPostgresSession,
DependsClickhouseClient,
DependsSettings,
)
from .common.dependencies import get_settings
from .common.version import get_build_label, get_pkg_version
from .common.version import get_build_label, get_pkg_version
from .common.metrics import mount_metrics
from .common.clickhouse_utils import query_click

log = logging.getLogger(__name__)

pkg_name = "oonirun"

Expand Down Expand Up @@ -63,10 +69,23 @@ class HealthStatus(BaseModel):

@app.get("/health")
async def health(
settings=Depends(get_settings),
db=Depends(get_postgresql_session),
settings: DependsSettings,
db: DependsPostgresSession,
clickhouse: DependsClickhouseClient,
):
errors = []

try:
query = """
SELECT COUNT()
FROM fastpath
WHERE measurement_start_time < NOW() AND measurement_start_time > NOW() - INTERVAL 3 HOUR
"""
query_click(db=clickhouse, query=query, query_params={})
except Exception as e:
errors.append("clickhouse_error")
log.error(e)

try:
db.query(models.OONIRunLink).limit(1).all()
except Exception as exc:
Expand Down
3 changes: 2 additions & 1 deletion ooniapi/services/oonirun/src/oonirun/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class OONIRunLinkNettest(Base):
test_name: Mapped[str] = mapped_column()
inputs: Mapped[List[str]] = mapped_column(nullable=True)
options: Mapped[Dict[str, Any]] = mapped_column(nullable=True)
backend_options: Mapped[Dict[str, Any]] = mapped_column(nullable=True)

is_background_run_enabled_default: Mapped[bool] = mapped_column(default=False)
is_manual_run_enabled_default: Mapped[bool] = mapped_column(default=False)
targets_name: Mapped[str] = mapped_column(nullable=True)
inputs_extra: Mapped[List[Dict[str, Any]]] = mapped_column(nullable=True)
Loading