Skip to content

Commit

Permalink
feat: add option sidecar for test on bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
mdaffad committed Jan 18, 2023
1 parent ddc097e commit 3f5341c
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .isort.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[settings]
known_third_party = fastapi,nltk,pydantic,river,statefun,yaml
known_third_party = fastapi,nltk,pydantic,requests,river,statefun,yaml
151 changes: 150 additions & 1 deletion poetry.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ river = "^0.13.0"
apache-flink-statefun = "^3.2.0"
nltk = "^3.7"
pyyaml = "^6.0"
requests = "^2.28.2"

[tool.poetry.dev-dependencies]
pre-commit = "^2.19.0"
Expand Down
6 changes: 5 additions & 1 deletion requirements/requirements.dev.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
anyio==3.6.1 ; python_version >= "3.9" and python_version < "4.0"
apache-flink-statefun==3.2.0 ; python_version >= "3.9" and python_version < "4.0"
certifi==2022.12.7 ; python_version >= "3.9" and python_version < "4"
cfgv==3.3.1 ; python_version >= "3.9" and python_version < "4.0"
charset-normalizer==3.0.1 ; python_version >= "3.9" and python_version < "4"
click==8.1.3 ; python_version >= "3.9" and python_version < "4.0"
colorama==0.4.5 ; python_version >= "3.9" and python_version < "4.0" and platform_system == "Windows"
distlib==0.3.6 ; python_version >= "3.9" and python_version < "4.0"
Expand All @@ -9,7 +11,7 @@ filelock==3.8.0 ; python_version >= "3.9" and python_version < "4.0"
gunicorn==20.1.0 ; python_version >= "3.9" and python_version < "4.0"
h11==0.13.0 ; python_version >= "3.9" and python_version < "4.0"
identify==2.5.3 ; python_version >= "3.9" and python_version < "4.0"
idna==3.3 ; python_version >= "3.9" and python_version < "4.0"
idna==3.3 ; python_version >= "3.9" and python_version < "4"
joblib==1.1.0 ; python_version >= "3.9" and python_version < "4.0"
nltk==3.7 ; python_version >= "3.9" and python_version < "4.0"
nodeenv==1.7.0 ; python_version >= "3.9" and python_version < "4.0"
Expand All @@ -23,6 +25,7 @@ python-dateutil==2.8.2 ; python_version >= "3.9" and python_version < "4.0"
pytz==2022.2.1 ; python_version >= "3.9" and python_version < "4.0"
pyyaml==6.0 ; python_version >= "3.9" and python_version < "4.0"
regex==2022.10.31 ; python_version >= "3.9" and python_version < "4.0"
requests==2.28.2 ; python_version >= "3.9" and python_version < "4"
river==0.13.0 ; python_version >= "3.9" and python_version < "4.0"
scikit-learn==1.1.2 ; python_version >= "3.9" and python_version < "4.0"
scipy==1.6.1 ; python_version >= "3.9" and python_version < "4.0"
Expand All @@ -34,5 +37,6 @@ threadpoolctl==3.1.0 ; python_version >= "3.9" and python_version < "4.0"
toml==0.10.2 ; python_version >= "3.9" and python_version < "4.0"
tqdm==4.64.1 ; python_version >= "3.9" and python_version < "4.0"
typing-extensions==4.3.0 ; python_version >= "3.9" and python_version < "4.0"
urllib3==1.26.14 ; python_version >= "3.9" and python_version < "4"
uvicorn==0.18.3 ; python_version >= "3.9" and python_version < "4.0"
virtualenv==20.16.4 ; python_version >= "3.9" and python_version < "4.0"
6 changes: 5 additions & 1 deletion requirements/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
anyio==3.6.1 ; python_version >= "3.9" and python_version < "4.0"
apache-flink-statefun==3.2.0 ; python_version >= "3.9" and python_version < "4.0"
certifi==2022.12.7 ; python_version >= "3.9" and python_version < "4"
charset-normalizer==3.0.1 ; python_version >= "3.9" and python_version < "4"
click==8.1.3 ; python_version >= "3.9" and python_version < "4.0"
colorama==0.4.5 ; python_version >= "3.9" and python_version < "4.0" and platform_system == "Windows"
fastapi==0.81.0 ; python_version >= "3.9" and python_version < "4.0"
gunicorn==20.1.0 ; python_version >= "3.9" and python_version < "4.0"
h11==0.13.0 ; python_version >= "3.9" and python_version < "4.0"
idna==3.3 ; python_version >= "3.9" and python_version < "4.0"
idna==3.3 ; python_version >= "3.9" and python_version < "4"
joblib==1.1.0 ; python_version >= "3.9" and python_version < "4.0"
nltk==3.7 ; python_version >= "3.9" and python_version < "4.0"
numpy==1.23.2 ; python_version < "4.0" and python_version >= "3.9"
Expand All @@ -16,6 +18,7 @@ python-dateutil==2.8.2 ; python_version >= "3.9" and python_version < "4.0"
pytz==2022.2.1 ; python_version >= "3.9" and python_version < "4.0"
pyyaml==6.0 ; python_version >= "3.9" and python_version < "4.0"
regex==2022.10.31 ; python_version >= "3.9" and python_version < "4.0"
requests==2.28.2 ; python_version >= "3.9" and python_version < "4"
river==0.13.0 ; python_version >= "3.9" and python_version < "4.0"
scikit-learn==1.1.2 ; python_version >= "3.9" and python_version < "4.0"
scipy==1.6.1 ; python_version >= "3.9" and python_version < "4.0"
Expand All @@ -26,4 +29,5 @@ starlette==0.19.1 ; python_version >= "3.9" and python_version < "4.0"
threadpoolctl==3.1.0 ; python_version >= "3.9" and python_version < "4.0"
tqdm==4.64.1 ; python_version >= "3.9" and python_version < "4.0"
typing-extensions==4.3.0 ; python_version >= "3.9" and python_version < "4.0"
urllib3==1.26.14 ; python_version >= "3.9" and python_version < "4"
uvicorn==0.18.3 ; python_version >= "3.9" and python_version < "4.0"
16 changes: 15 additions & 1 deletion springhead/controllers/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
from logging import getLogger
from time import time_ns

import requests
from fastapi import Request

from springhead.schemas import SpringheadTimeCreateRequest

logger = getLogger(__name__)


async def get_handler(request: Request):
start_time = time_ns()
handler = request.app.state.bootstrap.handler
end_time = time_ns()
logger.info(f"elapsed get_handler: {end_time-start_time}")
bootstrap_object = request.app.state.bootstrap
if bootstrap_object.benchmark_mode:
elapsed_time = end_time - start_time
requests.post(
bootstrap_object.side_car_address,
json=SpringheadTimeCreateRequest(
time_ns=elapsed_time,
type_test_case=bootstrap_object.type_test_case,
type_timer="get_handler",
).dict(),
)
logger.info(f"elapsed springhead get_handler: {elapsed_time}")
return handler
16 changes: 15 additions & 1 deletion springhead/controllers/statefun.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import logging
from time import time_ns

import requests
from fastapi import APIRouter, Depends, Request, Response
from statefun import RequestReplyHandler

from springhead.schemas import SpringheadTimeCreateRequest

from .dependencies import get_handler

router = APIRouter()
Expand All @@ -21,5 +24,16 @@ async def handle(request: Request, handler: RequestReplyHandler = Depends(get_ha
media_type="application/octet-stream",
)
end_time = time_ns()
logger.info(f"elapsed statefun endpoint: {end_time-start_time}")
bootstrap_object = request.app.state.bootstrap
if bootstrap_object.benchmark_mode:
elapsed_time = end_time - start_time
requests.post(
bootstrap_object.side_car_address,
json=SpringheadTimeCreateRequest(
time_ns=elapsed_time,
type_test_case=bootstrap_object.type_test_case,
type_timer="endpoint",
).dict(),
)
logger.info(f"elapsed springhead statefun endpoint: {end_time-start_time}")
return response
5 changes: 4 additions & 1 deletion springhead/core/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from typing import Callable, Dict, List

from pydantic import FilePath
from pydantic import AnyHttpUrl, FilePath
from statefun import Context, Message, RequestReplyHandler, ValueSpec

from springhead.models import Pipeline, Process
Expand All @@ -18,6 +18,9 @@
class Bootstrap:
pipeline: Pipeline
handler: RequestReplyHandler
side_car_address: AnyHttpUrl = "http://sidecar:8889/springhead" # type: ignore
type_test_case: str = "all-combination"
benchmark_mode: bool = False


async def bootstrap(
Expand Down
1 change: 1 addition & 0 deletions springhead/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .requests import SpringheadTimeCreateRequest
from .text import (
SPRINGHEAD_CLUSTREAM_VALUE_SPEC,
SPRINGHEAD_DFS_VALUE_SPEC,
Expand Down
7 changes: 7 additions & 0 deletions springhead/schemas/requests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from pydantic import BaseModel


class SpringheadTimeCreateRequest(BaseModel):
time_ns: int
type_timer: str
type_test_case: str

0 comments on commit 3f5341c

Please sign in to comment.