Update app deployment of meteo

This commit is contained in:
dvirlabs 2026-02-16 18:50:03 +02:00
parent ffdb7ea6b4
commit 81f6039994
2 changed files with 83 additions and 8 deletions

View File

@ -32,6 +32,73 @@ A FastAPI-based microservice that queries the Open-Meteo Geocoding API to retrie
- Prometheus: http://localhost:9090
- Grafana: http://localhost:3000 (admin/admin)
## Helm (Kubernetes)
The Helm chart in the `helm` folder deploys the FastAPI app and, by default, Prometheus and Grafana.
### What it deploys
- **App**: FastAPI service with `/healthz` probes and Prometheus scrape annotations
- **Prometheus**: Scrapes the app metrics at `/metrics`
- **Grafana**: Pre-provisioned datasource and dashboard for the app metrics
### Prerequisites
- Kubernetes cluster
- Helm v3
### Install
```bash
helm install open-meteo-service ./helm
```
### Upgrade
```bash
helm upgrade open-meteo-service ./helm
```
### Access the services
```bash
kubectl port-forward svc/open-meteo-service-open-meteo-service 8080:8000
kubectl port-forward svc/open-meteo-service-open-meteo-service-prometheus 9090:9090
kubectl port-forward svc/open-meteo-service-open-meteo-service-grafana 3000:3000
```
### Values overview
You can customize the chart via `helm/values.yaml` or `--set` flags.
**App values**
- `image.repository`, `image.tag`, `image.pullPolicy`
- `service.type`, `service.port`
- `env.cacheFile`
- `persistence.enabled`, `persistence.size`, `persistence.storageClassName`
**Prometheus values**
- `prometheus.enabled`
- `prometheus.image`
- `prometheus.service.type`, `prometheus.service.port`
- `prometheus.persistence.enabled`, `prometheus.persistence.size`, `prometheus.persistence.storageClassName`
**Grafana values**
- `grafana.enabled`
- `grafana.image`
- `grafana.service.type`, `grafana.service.port`
- `grafana.adminUser`, `grafana.adminPassword`
- `grafana.persistence.enabled`, `grafana.persistence.size`, `grafana.persistence.storageClassName`
### Example: disable Grafana and Prometheus
```bash
helm install open-meteo-service ./helm \
--set grafana.enabled=false \
--set prometheus.enabled=false
```
### Example: enable persistence for all components
```bash
helm install open-meteo-service ./helm \
--set persistence.enabled=true \
--set prometheus.persistence.enabled=true \
--set grafana.persistence.enabled=true
```
## API Documentation
### Endpoints

View File

@ -6,7 +6,7 @@ import requests
from .metrics import CACHE_HITS_TOTAL, CACHE_MISSES_TOTAL, OPENMETEO_CALLS_TOTAL
API_URL = "https://geocoding-api.open-meteo.com/v1/search"
CITIES = ["Tel Aviv", "Beer Sheva", "Jerusalem", "Szeged"]
CITIES = ["Tel Aviv", "Beersheba", "Jerusalem", "Szeged"]
CACHE_FILE = os.environ.get("CACHE_FILE", "coordinates_cache.json")
@ -45,18 +45,26 @@ def _save_cache(data: Dict[str, Any]) -> None:
def get_all_coordinates() -> Dict[str, Any]:
cached = _load_cache()
if cached:
# Check if all cities from CITIES list are in cache
if cached and all(city in cached for city in CITIES):
CACHE_HITS_TOTAL.inc()
return {"source": "cache", "data": cached}
# Filter cache to only include cities from CITIES list
filtered_data = {city: cached[city] for city in CITIES}
return {"source": "cache", "data": filtered_data}
CACHE_MISSES_TOTAL.inc()
results: Dict[str, Any] = {}
# Fetch missing cities
results = cached if cached else {}
for city in CITIES:
if city not in results:
results[city] = _fetch_coordinates(city)
_save_cache(results)
return {"source": "open-meteo", "data": results}
# Return only cities from CITIES list
filtered_data = {city: results[city] for city in CITIES}
return {"source": "open-meteo", "data": filtered_data}
def get_coordinates_for_city(city: str) -> Dict[str, Any]: