Merge pull request #457 from JakobStadlhuber/Readiness-Liveness-Probes

Readiness liveness probes
This commit is contained in:
Nicolas 2024-07-25 17:20:31 -04:00 committed by GitHub
commit ffd430f198
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 110 additions and 33 deletions

View File

@ -0,0 +1,6 @@
import { Request, Response } from "express";
export async function livenessController(req: Request, res: Response) {
//TODO: add checks if the application is live and healthy like checking the redis connection
res.status(200).json({ status: "ok" });
}

View File

@ -0,0 +1,6 @@
import { Request, Response } from "express";
export async function readinessController(req: Request, res: Response) {
// TODO: add checks when the application is ready to serve traffic
res.status(200).json({ status: "ok" });
}

View File

@ -7,6 +7,8 @@ import { crawlJobStatusPreviewController } from "../../src/controllers/status";
import { searchController } from "../../src/controllers/search"; import { searchController } from "../../src/controllers/search";
import { crawlCancelController } from "../../src/controllers/crawl-cancel"; import { crawlCancelController } from "../../src/controllers/crawl-cancel";
import { keyAuthController } from "../../src/controllers/keyAuth"; import { keyAuthController } from "../../src/controllers/keyAuth";
import { livenessController } from "../controllers/liveness";
import { readinessController } from "../controllers/readiness";
export const v0Router = express.Router(); export const v0Router = express.Router();
@ -23,3 +25,6 @@ v0Router.get("/v0/keyAuth", keyAuthController);
// Search routes // Search routes
v0Router.post("/v0/search", searchController); v0Router.post("/v0/search", searchController);
// Health/Probe routes
v0Router.get("/v0/health/liveness", livenessController);
v0Router.get("/v0/health/readiness", readinessController);

View File

@ -5,7 +5,7 @@ the HTML content of a specified URL. It supports optional proxy settings and med
from os import environ from os import environ
from fastapi import FastAPI from fastapi import FastAPI, Response
from fastapi.responses import JSONResponse from fastapi.responses import JSONResponse
from playwright.async_api import Browser, async_playwright from playwright.async_api import Browser, async_playwright
from pydantic import BaseModel from pydantic import BaseModel
@ -39,6 +39,20 @@ async def shutdown_event():
"""Event handler for application shutdown to close the browser.""" """Event handler for application shutdown to close the browser."""
await browser.close() await browser.close()
@app.get("/health/liveness")
def liveness_probe():
"""Endpoint for liveness probe."""
return JSONResponse(content={"status": "ok"}, status_code=200)
@app.get("/health/readiness")
async def readiness_probe():
"""Endpoint for readiness probe. Checks if the browser instance is ready."""
if browser:
return JSONResponse(content={"status": "ok"}, status_code=200)
return JSONResponse(content={"status": "Service Unavailable"}, status_code=503)
@app.post("/html") @app.post("/html")
async def root(body: UrlModel): async def root(body: UrlModel):
""" """

View File

@ -4,12 +4,12 @@
2. Build Docker images, and host it in your Docker Registry (replace the target registry with your own) 2. Build Docker images, and host it in your Docker Registry (replace the target registry with your own)
1. API (which is also used as a worker image) 1. API (which is also used as a worker image)
1. ```bash 1. ```bash
docker build -t ghcr.io/winkk-dev/firecrawl:latest ../../apps/api docker build --no-cache -t ghcr.io/winkk-dev/firecrawl:latest ../../../apps/api
docker push ghcr.io/winkk-dev/firecrawl:latest docker push ghcr.io/winkk-dev/firecrawl:latest
``` ```
2. Playwright 2. Playwright
1. ```bash 1. ```bash
docker build -t ghcr.io/winkk-dev/firecrawl-playwright:latest ../../apps/playwright-service docker build --no-cache -t ghcr.io/winkk-dev/firecrawl-playwright:latest ../../../apps/playwright-service
docker push ghcr.io/winkk-dev/firecrawl-playwright:latest docker push ghcr.io/winkk-dev/firecrawl-playwright:latest
``` ```
3. Replace the image in [worker.yaml](worker.yaml), [api.yaml](api.yaml) and [playwright-service.yaml](playwright-service.yaml) 3. Replace the image in [worker.yaml](worker.yaml), [api.yaml](api.yaml) and [playwright-service.yaml](playwright-service.yaml)

View File

@ -17,14 +17,33 @@ spec:
containers: containers:
- name: api - name: api
image: ghcr.io/winkk-dev/firecrawl:latest image: ghcr.io/winkk-dev/firecrawl:latest
imagePullPolicy: Always
args: [ "pnpm", "run", "start:production" ] args: [ "pnpm", "run", "start:production" ]
ports: ports:
- containerPort: 3002 - containerPort: 3002
envFrom: envFrom:
- configMapRef: - configMapRef:
name: firecrawl-config name: firecrawl-config
- secretRef: #- secretRef:
name: firecrawl-secret # name: firecrawl-secret
livenessProbe:
httpGet:
path: /v0/health/liveness
port: 3002
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /v0/health/readiness
port: 3002
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service

View File

@ -7,8 +7,7 @@ data:
PORT: "3002" PORT: "3002"
HOST: "0.0.0.0" HOST: "0.0.0.0"
REDIS_URL: "redis://redis:6379" REDIS_URL: "redis://redis:6379"
PLAYWRIGHT_MICROSERVICE_URL: "http://playwright-service:3000" REDIS_RATE_LIMIT_URL: "redis://redis:6379"
PLAYWRIGHT_MICROSERVICE_URL: "http://playwright-service:3000/html"
USE_DB_AUTHENTICATION: "false" USE_DB_AUTHENTICATION: "false"
SUPABASE_ANON_TOKEN: "" HDX_NODE_BETA_MODE: "1"
SUPABASE_URL: ""
SUPABASE_SERVICE_TOKEN: ""

View File

@ -1,3 +1,10 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: playwright-service-config
data:
PORT: "3000"
---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
@ -17,11 +24,30 @@ spec:
containers: containers:
- name: playwright-service - name: playwright-service
image: ghcr.io/winkk-dev/firecrawl-playwright:latest image: ghcr.io/winkk-dev/firecrawl-playwright:latest
imagePullPolicy: Always
ports: ports:
- containerPort: 3000 - containerPort: 3000
envFrom: envFrom:
- configMapRef: - configMapRef:
name: firecrawl-config name: playwright-service-config
livenessProbe:
httpGet:
path: /health/liveness
port: 3000
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
readinessProbe:
httpGet:
path: /health/readiness
port: 3000
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 5
successThreshold: 1
failureThreshold: 3
--- ---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service

View File

@ -17,8 +17,10 @@ spec:
containers: containers:
- name: worker - name: worker
image: ghcr.io/winkk-dev/firecrawl:latest image: ghcr.io/winkk-dev/firecrawl:latest
imagePullPolicy: Always
args: [ "pnpm", "run", "workers" ]
envFrom: envFrom:
- configMapRef: - configMapRef:
name: firecrawl-config name: firecrawl-config
- secretRef: #- secretRef:
name: firecrawl-secret # name: firecrawl-secret