How sungbinlee/tk-incidentreporter works
1. What this repository is
- tk-incidentreporter is a small Python desktop app for the FPTR Toolkit (sgtk) environment.
- Its purpose is to watch client-side tk-*.log files, detect incident-like lines, and create a Ticket with the log attached.
2. Top-level runtime shape
- The app is packaged as a Toolkit app, not a standalone service.
- app.py is the visible entry point, while the real behavior lives under python/tk_incident/.
- info.yml likely provides Toolkit app metadata used by the SGTK loader.
3. Main control boundary
- python/tk_incident/bootstrap.py is the startup/orchestration layer.
- It likely wires together configuration, the long-running log tailing worker, the matching logic, and the upload/Ticket creation path.
- This is the boundary between the desktop app host and the incident-reporting pipeline.
4. Log monitoring subsystem
- python/tk_incident/tail_worker.py is the file-watching/streaming component.
- It is responsible for following active log files and emitting new lines or log events as they arrive.
- The readme indicates it targets tk-*.log files on the local machine.
5. Incident detection subsystem
- python/tk_incident/matcher.py contains the pattern-detection logic.
- The MVP uses regex-based matching for ERROR|CRITICAL.
- This layer converts raw log lines into “incident candidates” with the information needed to create a Ticket.
6. Ticket creation / upload subsystem
- python/tk_incident/uploader.py is the integration boundary to FPTR/ShotGrid-style backend services.
- It appears to create Tickets, attach the relevant log file, and likely send metadata such as the matched line, timestamp, user, and byte offset.
- This is the only subsystem that should know about remote API details.
7. De-duplication and flood control
- The app uses title-signature de-duplication to avoid creating repeated Tickets.
- The readme defines the title as "<user_login> - <ErrorName or short message>"; if that title already exists, the report is skipped.
- That logic likely sits in the upload path or a closely related coordination layer, because it depends on candidate details plus existing remote state.
8. Process-wide lifecycle / singleton behavior
- python/tk_incident/singleton.py suggests the app enforces a single running instance.
- In a desktop log-watcher, this is important to prevent multiple watchers from creating duplicate Tickets from the same incidents.
- This is a host/process boundary rather than a business-logic layer.
9. Agent abstraction
- python/tk_incident/agent.py likely represents the main application agent or controller object.
- It probably owns the coordination between the bootstrap code, the worker, the matcher, and the uploader.
- In an architecture diagram, this is the central orchestration node inside the app process.
10. End-to-end data flow
- Local tk-*.log files are tailed.
- New lines are passed through regex matching.
- Matching incidents are enriched with context like user, timestamp, path, and offset.
- The uploader creates a Ticket in the backend and attaches the log file.
- Duplicate titles short-circuit the creation path.
11. External boundaries
- The main external system is the FPTR/ShotGrid backend where Tickets are created.
- The app also depends on the local filesystem and log files generated by the client desktop environment.
- The surrounding host is the SGTK/Tk Desktop runtime, which provides the app execution context.
12. Architectural summary
- This repo is a small event-driven desktop integration: filesystem input, pattern matching, remote ticket creation.
- The important boundaries for a diagram are: desktop host/bootstrap, singleton process guard, log tailing, incident matcher, and backend uploader/de-duplication.
Main entry points: uploader.py Uploader · app.py app.py · bootstrap.py Bootstrap · agent.py Agent
Components 15
Toolkit host
Desktop app entry and process control within the Toolkit runtime.
- app.py · Toolkit app entry module.
app.py - info.yml · Toolkit app metadata loaded by the host.
info.yml - Bootstrap · Wires together startup, configuration, and runtime services.
python/tk_incident/bootstrap.py - Singleton · Ensures only one watcher instance runs at a time.
python/tk_incident/singleton.py - Agent · Main in-process controller for the incident reporter.
python/tk_incident/agent.py - App config · App package metadata consumed by the Toolkit loader.
info.yml
Incident pipeline
Core log-watching, matching, and ticket creation flow.
- Tail worker · Follows active tk-*.log files and emits new log lines.
python/tk_incident/tail_worker.py - Matcher · Detects incident-like lines using regex and builds candidates.
python/tk_incident/matcher.py - Uploader · Creates tickets, attaches logs, and talks to the backend API.
python/tk_incident/uploader.py - Dedupe · Skips duplicate reports when a matching ticket title already exists.
python/tk_incident/uploader.py - Candidate · Enriched incident data passed toward ticket creation.
External boundaries
Filesystem and backend systems the app integrates with.
- tk logs · Client-side tk-*.log files on the local machine.
- Filesystem · Local machine storage where log files are read from.
- FPTR backend · Remote ticketing system used to create incident tickets.
- Tk Desktop · SGTK/Toolkit execution environment that hosts the app.
Connections 16
- Tk Desktop → app.py: launches · Toolkit host starts the app entry point.
- app.py → App config: reads · App entry uses Toolkit metadata during loading.
- app.py → Bootstrap: starts · Entry module hands control to startup orchestration.
- Bootstrap → Singleton: guards · Startup checks that only one instance is active.
- Bootstrap → Agent: creates · Bootstrap instantiates the main controller.
- Agent → Tail worker: owns · Agent coordinates the log tailing worker.
- Tail worker → Filesystem: reads · Worker follows local log files from disk.
- Filesystem → tk logs: contains · The filesystem holds the tk log files.
- Tail worker → Matcher: emits lines · New log lines are forwarded for inspection.
- Matcher → Candidate: builds · Matching lines are converted into incident candidates.
- Agent → Uploader: routes · Agent sends incident candidates to the upload path.
- Candidate → Uploader: submits · Candidate details are consumed by ticket creation.
- Uploader → Dedupe: checks · Uploader suppresses repeated tickets by title signature.
- Dedupe → FPTR backend: queries · Duplicate detection depends on existing remote tickets.
- Uploader → FPTR backend: creates · Uploader opens tickets and attaches the log.
- Uploader → tk logs: attaches · Relevant log file is attached to the ticket.