-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Labels
Description
OpenResty JSON Access Log Format - Implemented ✅
Summary
Implemented JSON access log format for Gateway nginx/OpenResty to enable structured querying in Grafana Loki.
Changes Made
Repository: test3207/m3w-k8s
Commits
d4d1dce: feat(observability): add JSON access log format to Gateway nginx - Closes OpenResty JSON access log format #252b6647f0: fix: initialize routing variables at server level to avoid warnings
Files Modified
-
ansible/playbooks/templates/gateway-nginx.conf.j2
- Replaced
log_format main(combined format) withlog_format json_access escape=json - Added structured JSON fields for observability
- Added server-level default variables for
$backendand$target_region
- Replaced
-
ansible/playbooks/templates/gateway-routing.lua.j2
- Added
ngx.var.target_region = regionto set the target region variable for logging
- Added
JSON Log Format Fields
{
"timestamp": "ISO8601 format",
"service": "m3w-gateway",
"gateway": "gateway1|gateway2",
"type": "access",
"http": {
"method": "GET|POST|...",
"path": "/api/...",
"query": "query string",
"status": 200,
"bytes_sent": 1234,
"request_time": 0.006,
"upstream_time": "0.006"
},
"client": {
"ip": "client IP",
"user_agent": "browser/version",
"referer": "",
"forwarded_for": ""
},
"upstream": {
"addr": "10.10.0.2:30400",
"status": "200"
},
"routing": {
"backend": "jp_backend|sea_backend",
"target_region": "jp|sea"
},
"traceId": ""
}Verification
- ✅ Deployed to both Gateway VMs (gateway1 and gateway2)
- ✅ OpenResty containers restarted successfully
- ✅ JSON logs verified working via curl requests
- ✅ No warnings in error logs
Example Log Output
{"timestamp":"2025-12-22T05:40:16+00:00","service":"m3w-gateway","gateway":"gateway1","type":"access","http":{"method":"GET","path":"/api/health","query":"","status":200,"bytes_sent":79,"request_time":0.006,"upstream_time":"0.006"},"client":{"ip":"221.225.23.135","user_agent":"curl/8.16.0","referer":"","forwarded_for":""},"upstream":{"addr":"10.10.0.2:30400","status":"200"},"routing":{"backend":"jp_backend","target_region":"jp"},"traceId":""}Part of Epic
- Parent: Epic 3.5: Observability & Operations #190 (Epic 3.5 Observability & Operations)
Reactions are currently unavailable