This application is a simple FastAPI-based web service that provides the following functionality:
- Displays a list of countries with their full names and ISO country codes.
- Allows users to retrieve the current local time for a specific country using its ISO country code.
- Serves as an example of building and deploying a FastAPI application with Docker.
- Country List: Returns a dictionary of countries in the format
{'TH': 'Thailand', 'US': 'United States', ...}. - Local Time API: Fetches the current local time for a given country code, including all available timezones.
- Pod Info: Returns the Kubernetes pod name the instance is running on.
GET /- Displays a welcome message, instructions, and a list of available countries.
GET /pod- Returns the Kubernetes pod name (from
HOSTNAMEenv var). - Example Response:
{ "pod_name": "my-app-pod-abc123" }
- Returns the Kubernetes pod name (from
GET /localtime/{country}- Returns the local time, timezone name, all available timezones, and country name for the specified ISO 3166-1 alpha-2 country code.
- Returns HTTP 400 for invalid country codes.
- Example Response:
{ "country": "United States", "timezone": "America/New_York", "all_timezones": ["America/New_York", "America/Chicago", "..."], "local_time": "2023-10-27 10:30:00" }
GET /docs- Interactive API documentation (Swagger UI).
GET /metrics- Prometheus metrics endpoint.
- Install dependencies:
pip install -r requirements.txt
- Run the application:
uvicorn app:app --host 0.0.0.0 --port 8000 --reload
- Test: Open http://localhost:8000/docs in your browser.
- OpenTelemetry: The application is instrumented with OpenTelemetry to trace requests. Traces are exported to the console and an OTLP collector (default:
localhost:4317). - Prometheus: Metrics are exposed at
/metrics.
- Build and run the application using Docker:
docker build -t simple-fastapi . docker run -p 8000:8000 simple-fastapi - with k8s image can be found here
quay.io/rh_ee_swongpai/fast-localtime-check