Step 2: Convert Timezones to UTC
Once you have a standard timestamp object, the next step is to convert it to a consistent timezone. The universal standard for data processing is Coordinated Universal Time (UTC).
The Goal
You will modify your pipeline to take the normalized_timestamp from the previous step and convert it to a new timestamp_utc field, ensuring all your events are comparable on a single timeline.
Implementation
-
Start with the Previous Pipeline: Copy the
normalize-timestamps.yamlfrom Step 1 to a new file namedconvert-timezones.yaml.cp normalize-timestamps.yaml convert-timezones.yaml -
Add the Timezone Conversion Logic: Open
convert-timezones.yamland add the conversion logic to the bottom of the existingmappingprocessor.Add this to the 'mapping' processor in convert-timezones.yaml# --- Logic from Step 1 (Parsing) ---
# (The existing timestamp parsing logic remains here)
# --- START: New additions for Timezone Conversion ---
# Convert the parsed timestamp to a standard UTC string
root.timestamp_utc = this.normalized_timestamp.ts_format_iso8601("UTC")
# For auditing, it's good practice to also extract the original timezone offset
root.original_timezone = this.normalized_timestamp.ts_format("Z")
# --- END: New additions --- -
Deploy and Test:
# --- Send a timestamp with a non-UTC timezone ---
curl -X POST http://localhost:8080/ingest \
-H "Content-Type: application/json" \
-d '{"event_id": "C", "timestamp": "2025-10-20T14:23:45-04:00"}' -
Verify: Check your logs. The output will show:
original_timestamp: The original string with the-04:00offset.timestamp_utc: The converted time, which will be2025-10-20T18:23:45Z.original_timezone: The extracted-04:00offset.
You have now successfully standardized all incoming timestamps to UTC, which is a critical step for reliable time-based analysis.