Skip to content

Commit

Permalink
ci(engine): Fix api sub routing
Browse files Browse the repository at this point in the history
  • Loading branch information
topher-lo committed Mar 19, 2024
1 parent dd15db9 commit 76ec86a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 32 deletions.
41 changes: 16 additions & 25 deletions aws/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,6 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
file="Dockerfile",
build_args={"API_MODULE": "tracecat.api.app:app"},
),
health_check=ecs.HealthCheck(
command=["CMD-SHELL", "curl -f http://localhost:8000/health"],
interval=Duration.seconds(120),
retries=5,
start_period=Duration.seconds(60),
timeout=Duration.seconds(10),
),
memory_limit_mib=512,
environment={
"API_MODULE": "tracecat.api.app:app",
Expand Down Expand Up @@ -216,13 +209,6 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
file="Dockerfile",
build_args={"API_MODULE": "tracecat.runner.app:app", "PORT": "8001"},
),
health_check=ecs.HealthCheck(
command=["CMD-SHELL", "curl -f http://localhost:8001/health"],
interval=Duration.seconds(120),
retries=5,
start_period=Duration.seconds(60),
timeout=Duration.seconds(10),
),
memory_limit_mib=512,
environment={"API_MODULE": "tracecat.runner.app:app", "PORT": "8001"},
secrets=runner_secrets,
Expand All @@ -247,15 +233,6 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
task_definition=task_definition,
)

service_health_check = elbv2.HealthCheck(
enabled=True,
interval=Duration.seconds(120),
timeout=Duration.seconds(10),
healthy_threshold_count=5,
unhealthy_threshold_count=2,
path="/health",
)

# Load balancer
alb = elbv2.ApplicationLoadBalancer(
self,
Expand Down Expand Up @@ -290,7 +267,14 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
port=8000,
protocol=elbv2.ApplicationProtocol.HTTP,
priority=10,
health_check=service_health_check,
health_check=elbv2.HealthCheck(
enabled=True,
interval=Duration.seconds(120),
timeout=Duration.seconds(10),
healthy_threshold_count=5,
unhealthy_threshold_count=2,
path="/api/health",
),
conditions=[elbv2.ListenerCondition.path_patterns(["/api", "/api/*"])],
targets=[
ecs_service.load_balancer_target(
Expand All @@ -303,7 +287,14 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
port=8001,
protocol=elbv2.ApplicationProtocol.HTTP,
priority=20,
health_check=service_health_check,
health_check=elbv2.HealthCheck(
enabled=True,
interval=Duration.seconds(120),
timeout=Duration.seconds(10),
healthy_threshold_count=5,
unhealthy_threshold_count=2,
path="/runner/health",
),
conditions=[
elbv2.ListenerCondition.path_patterns(["/runner", "/runner/*"])
],
Expand Down
13 changes: 9 additions & 4 deletions tracecat/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import polars as pl
import tantivy
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi import APIRouter, Depends, FastAPI, HTTPException, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import StreamingResponse
from sqlalchemy import Engine
Expand Down Expand Up @@ -60,6 +60,9 @@
)
from tracecat.types.cases import Case, CaseMetrics

logger = standard_logger("api")


engine: Engine


Expand All @@ -72,11 +75,13 @@ async def lifespan(app: FastAPI):

app = FastAPI(lifespan=lifespan)

# TODO: Check TRACECAT__APP_ENV to set origins
origins = [
"http://localhost",
"http://localhost:3000",
"http://localhost:8000",
]

# TODO: Check TRACECAT__APP_ENV to set methods and headers
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
Expand All @@ -85,8 +90,8 @@ async def lifespan(app: FastAPI):
allow_headers=["*"],
)


logger = standard_logger("api")
api_router = APIRouter()
app.include_router(api_router, prefix="/api")


@app.get("/")
Expand Down
13 changes: 10 additions & 3 deletions tracecat/runner/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

import httpx
from fastapi import (
APIRouter,
BackgroundTasks,
Depends,
FastAPI,
Expand Down Expand Up @@ -67,19 +68,25 @@


app = FastAPI(debug=True, default_response_class=ORJSONResponse)

# TODO: Check TRACECAT__APP_ENV to set origins
origins = [
"http://localhost",
"http://localhost:8080",
"http://localhost:3000",
"http://localhost:8001",
]

# TODO: Check TRACECAT__APP_ENV to set methods and headers
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

runner_router = APIRouter()
app.include_router(runner_router, prefix="/runner")


class RunnerStatus(StrEnum):
STARTING = auto()
Expand Down

0 comments on commit 76ec86a

Please sign in to comment.