# Request log exercise

The six rows in sample-events.csv are illustrative and describe two invented requests. The exercise runs offline using Python 3.10 or newer and its standard library. The script reads the CSV and prints a report. It leaves the input file untouched.

## Run

Extract the ZIP, open a terminal in the extracted folder and run:

    python event_report.py sample-events.csv

If your installation uses the python3 command, substitute python3. On Windows with the Python launcher installed, you can use py -3.

The sample reports six valid events, two unique request IDs, four gateway events, two worker events, a largest observation gap of 710.000 ms, and zero warnings and errors.

## Input and errors

Keep the header in the supplied order. Use UTF-8 (an optional BOM is accepted), comma separation and standard CSV quoting. Both timestamps use YYYY-MM-DDTHH:MM:SS[.fraction]Z, with one to six fractional digits if present. Request and service names use letters, digits, dots, underscores and hyphens and must start with a letter or digit. The level is DEBUG, INFO, WARN or ERROR. Use a nonblank message.

The tool describes invalid rows on standard error and counts only valid rows in the report. A malformed CSV that cannot be parsed, an invalid header or an unreadable file stops the run. Exit status 0 means the input passed validation, 1 means file, CSV or row validation failed, and 2 means the command-line arguments were invalid. An observation time before the event time adds a warning and excludes that difference from the maximum. Clock agreement remains unverified.

## Try two changes

1. Make a copy of the CSV. Change one level to NOTICE, then run the script against the copy. Look for one invalid row and a nonzero exit status.
2. Use a fresh copy. Set one observation time earlier than its event time. Look for a warning and check that the maximum excludes the negative difference.

Reconstruct req-100 by sorting its events by event time and comparing them with the order in the file. Use the [request log guide](https://balticdev.org/notes/read-request-logs/) for the interpretation.
