|
5 | 5 | from pydantic import BaseModel, Field, field_validator |
6 | 6 | from concurrent.futures import ThreadPoolExecutor, TimeoutError as FutureTimeoutError |
7 | 7 | import math |
8 | | -from datetime import datetime |
| 8 | +from datetime import datetime, timezone |
9 | 9 | from typing import List |
| 10 | +import os |
10 | 11 |
|
11 | 12 | # Optional scipy import for advanced calculations |
12 | 13 | try: |
|
44 | 45 | allow_headers=["*"], |
45 | 46 | ) |
46 | 47 |
|
| 48 | +# Metadata for /v1/info endpoint |
| 49 | +BUILD_TIMESTAMP = datetime.now(timezone.utc).isoformat() |
| 50 | +GIT_SHA = os.getenv("GIT_SHA", "unknown") |
| 51 | +ENVIRONMENT = os.getenv("ENVIRONMENT", "production") |
| 52 | + |
47 | 53 | # Standard Error Response Models |
48 | 54 | class ErrorDetail(BaseModel): |
49 | 55 | code: str |
@@ -209,23 +215,52 @@ async def http_exception_handler(request: Request, exc: HTTPException): |
209 | 215 | }, |
210 | 216 | ) |
211 | 217 |
|
212 | | -@app.get("/v1/health", |
213 | | - summary="Health Check", |
214 | | - description="Check if the API service is running and healthy.", |
215 | | - response_description="Service health status", |
216 | | - tags=["System"]) |
| 218 | +@app.get( |
| 219 | + "/v1/health", |
| 220 | + summary="Health Check", |
| 221 | + description="Check if the API service is running and healthy.", |
| 222 | + response_description="Service health status", |
| 223 | + tags=["System"], |
| 224 | +) |
217 | 225 | def health(): |
218 | 226 | """ |
219 | 227 | Health check endpoint. |
220 | | - |
| 228 | +
|
221 | 229 | Returns the current status of the API service including: |
222 | 230 | - Service name |
223 | 231 | - API version |
224 | | - |
| 232 | +
|
225 | 233 | Use this endpoint to verify the API is operational. |
226 | 234 | """ |
227 | 235 | return {"ok": True, "service": "finance-api", "version": "v1"} |
228 | 236 |
|
| 237 | + |
| 238 | +@app.get( |
| 239 | + "/v1/info", |
| 240 | + summary="Service Info", |
| 241 | + description="Return metadata about the running service (useful for debugging).", |
| 242 | + response_description="Service metadata", |
| 243 | + tags=["System"], |
| 244 | +) |
| 245 | +def info(): |
| 246 | + """ |
| 247 | + Service info endpoint. |
| 248 | +
|
| 249 | + Returns metadata useful for debugging and operations, such as: |
| 250 | + - API version |
| 251 | + - Environment (e.g. production, staging, local) |
| 252 | + - Build timestamp (UTC) |
| 253 | + - Git SHA (if provided via env var `GIT_SHA`) |
| 254 | + """ |
| 255 | + return { |
| 256 | + "ok": True, |
| 257 | + "service": "finance-api", |
| 258 | + "version": app.version, |
| 259 | + "environment": ENVIRONMENT, |
| 260 | + "build_timestamp": BUILD_TIMESTAMP, |
| 261 | + "git_sha": GIT_SHA, |
| 262 | + } |
| 263 | + |
229 | 264 | @app.post("/v1/echo", |
230 | 265 | response_model=EchoResponse, |
231 | 266 | summary="Echo Endpoint", |
|
0 commit comments