Skip to content

Add /stats endpoint#1

Open
druids-app[bot] wants to merge 1 commit into
mainfrom
druids/add-stats-endpoint
Open

Add /stats endpoint#1
druids-app[bot] wants to merge 1 commit into
mainfrom
druids/add-stats-endpoint

Conversation

@druids-app

@druids-app druids-app Bot commented Apr 15, 2026

Copy link
Copy Markdown

Summary

Adds a /stats HTTP endpoint that returns log statistics:

  • total: Total number of log entries
  • by_level: Breakdown by log level (INFO/WARN/ERROR)

Implementation

  • Created Flask web server in server.py
  • Log levels derived from HTTP status codes:
    • INFO: 2xx, 3xx status codes
    • WARN: 4xx status codes
    • ERROR: 5xx status codes
  • Configurable via LOG_DIR environment variable (defaults to logs/)

Testing

Verified with 1000 test log entries:

{
  "total": 1000,
  "by_level": {
    "INFO": 891,
    "WARN": 71,
    "ERROR": 38
  }
}

Also tested with empty log directory (returns zeros).

Add a /stats HTTP endpoint that returns:
- total: total number of log entries
- by_level: breakdown by log level (INFO/WARN/ERROR)

Log levels are derived from HTTP status codes:
- INFO: 2xx, 3xx
- WARN: 4xx
- ERROR: 5xx

The server reads logs from the LOG_DIR environment variable (defaults to "logs/").

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Comment thread server.py

if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host="0.0.0.0", port=port, debug=True)
@druids-app
druids-app Bot marked this pull request as ready for review April 15, 2026 06:57
@druids-app

druids-app Bot commented Apr 15, 2026

Copy link
Copy Markdown
Author

Audit Results ✓

Verdict: APPROVED

Spec Requirements

  • ✅ endpoint implemented
  • ✅ Returns total number of log entries
  • ✅ Returns breakdown by log level

Code Review

The implementation is clean and correct:

  • Flask server with route (server.py:50-66)
  • Parses all .jsonl files from configurable LOG_DIR
  • Maps HTTP status codes to log levels correctly:
    • INFO: 2xx, 3xx
    • WARN: 4xx
    • ERROR: 5xx
  • Returns proper JSON structure with total and by_level

Verification Quality

The builder provided genuine end-to-end verification:

  1. Real test execution: Generated 1000 actual log entries across 2 files
  2. Server actually running: Confirmed live server process and real HTTP response
  3. Accuracy verified: Manual independent count (INFO: 891, WARN: 71, ERROR: 38) matches API response exactly
  4. Edge case tested: Empty directory returns zeros correctly
  5. Real output captured: All curl responses and verification commands show actual timestamps and data

What I Verified

  • ✅ Test artifacts exist (logs/access-000.jsonl, logs/access-001.jsonl)
  • ✅ Server is running (PID 6234, 6236)
  • ✅ Endpoint responds: curl http://localhost:5000/stats returns expected JSON
  • ✅ Counts are accurate: Ran independent verification of log level counts
  • ✅ Empty directory edge case works correctly

No lazy patterns detected. This is a complete, honest verification that proves the implementation works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant