Flink Longest Session Per Job
This skill implements a Flink streaming job that:
- Reads Google cluster trace task events and job events from gzipped CSV files
- Filters task SUBMIT events (eventType=0)
- Groups by jobId and applies EventTimeSessionWindows with a configurable gap (default 10 minutes)
- Counts tasks per session window per job
- Finds the session with the maximum task count per job
- Only outputs results for jobs that have FINISH events (eventType=4)
- Output format:
(jobId,maxTaskCount)one per line
Key Technical Details
Data Schema (Google Cluster Trace)
Task Events CSV columns: timestamp, missingInfo, jobId, taskIndex, machineId, eventType, user, schedulingClass, priority, cpuRequest, memoryRequest, diskSpaceRequest, differentMachinesRestriction
Job Events CSV columns: timestamp, missingInfo, jobId, eventType, user, schedulingClass, jobName, logicalJobName
Event Types: 0=SUBMIT, 1=SCHEDULE, 2=EVICT, 3=FAIL, 4=FINISH, 5=KILL, 6=LOST, 7=UPDATE_PENDING, 8=UPDATE_RUNNING
Timestamp Handling
- Dataset timestamps are in microseconds
- Flink event time uses milliseconds
- Convert:
event.timestamp / 1000
Session Window Strategy
- A "stage" is a period of SUBMIT events close together in event time
- Gap of 10 minutes (600 seconds) with no SUBMIT events ends a stage
- Uses
EventTimeSessionWindows.withGap(Time.seconds(600)) - Each resubmission of a task counts separately
Join Strategy
- Uses
KeyedCoProcessFunctionto join session counts with job finish events - Registers event-time timer at
Long.MAX_VALUE - 1to emit final results - For bounded streams, this timer fires when the watermark reaches MAX_VALUE at stream end
- Only emits for jobs where both session counts AND finish event exist
Project Structure
workspace/ pom.xml # Do not modify src/main/java/clusterdata/ datatypes/ TaskEvent.java # Generated by skill JobEvent.java # Generated by skill query/ LongestSessionPerJob.java # Generated by skill utils/ AppBase.java # Provided skeleton
End-to-End Usage
pythonimport sys import os # Add skill scripts to path sys.path.insert(0, '/app/environment/skills/evo-flink-session-job/scripts') from generate_java_sources import write_java_sources from build_and_run import run_end_to_end from validate_output import validate_output_format, validate_against_data # Configuration - adapt these paths to your environment workspace_dir = '/app/workspace' task_input = '/app/workspace/data/task_events/part-00001-of-00500.csv.gz' job_input = '/app/workspace/data/job_events/part-00001-of-00500.csv.gz' output_path = '/app/workspace/output.txt' # Run end-to-end run_end_to_end(workspace_dir, task_input, job_input, output_path) # Validate output format result = validate_output_format(output_path) assert result['valid'], f"Output format invalid: {result['errors']}" # Cross-validate against input data result2 = validate_against_data(output_path, task_input, job_input) assert result2['valid'], f"Cross-validation failed: {result2['errors']}" print(f"SUCCESS: {result['line_count']} jobs output")
Individual Function Usage
Generate Java Sources Only
pythonimport sys sys.path.insert(0, '/app/environment/skills/evo-flink-session-job/scripts') from generate_java_sources import write_java_sources write_java_sources('/app/workspace')
Build Only
pythonimport sys sys.path.insert(0, '/app/environment/skills/evo-flink-session-job/scripts') from build_and_run import build_maven_project jar_path = build_maven_project('/app/workspace')
Validate Only
pythonimport sys sys.path.insert(0, '/app/environment/skills/evo-flink-session-job/scripts') from validate_output import validate_output_format, validate_against_data result = validate_output_format('/app/workspace/output.txt')


