Skip to content

Commit 7d4f648

Browse files
Add /v1/info endpoint with service metadata
1 parent b371240 commit 7d4f648

1 file changed

Lines changed: 43 additions & 8 deletions

File tree

app/main.py

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
from pydantic import BaseModel, Field, field_validator
66
from concurrent.futures import ThreadPoolExecutor, TimeoutError as FutureTimeoutError
77
import math
8-
from datetime import datetime
8+
from datetime import datetime, timezone
99
from typing import List
10+
import os
1011

1112
# Optional scipy import for advanced calculations
1213
try:
@@ -44,6 +45,11 @@
4445
allow_headers=["*"],
4546
)
4647

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+
4753
# Standard Error Response Models
4854
class ErrorDetail(BaseModel):
4955
code: str
@@ -209,23 +215,52 @@ async def http_exception_handler(request: Request, exc: HTTPException):
209215
},
210216
)
211217

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+
)
217225
def health():
218226
"""
219227
Health check endpoint.
220-
228+
221229
Returns the current status of the API service including:
222230
- Service name
223231
- API version
224-
232+
225233
Use this endpoint to verify the API is operational.
226234
"""
227235
return {"ok": True, "service": "finance-api", "version": "v1"}
228236

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+
229264
@app.post("/v1/echo",
230265
response_model=EchoResponse,
231266
summary="Echo Endpoint",

0 commit comments

Comments
 (0)