Files
teleport/lib/terminal
Ryan ClarkandZac Bergquist 33bab284f8 Add a new API for session recording playback (#58116)
* Add a new API for session recording playback

* Mark the old endpoint as deprecated

* Capture channel references during the lock to avoid data races

* Update lib/web/recordingplayback.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Update lib/web/recordingplayback.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Update lib/web/recordingplayback.go

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>

* Define the request/response type constants separately

* Add a comment about the return type of processEvent

* Remove deprecation comment for ttyplayback endpoint

* Combine the time window validation checks

* Use trace.LimitExceeded

* Use require.ErrorContains

* Use t.Context()

* Use a better check for checking if a context is done

* Use t.Cleanup instead

* Import slices

* Fix error assertion

* Rename closeWebSocket to sendCloseMessage

* Add a test with a resize event mid-way through

* Rename activeTask -> cancelActiveTask

* Remove close message type

* Add comment about eventRequested channel

* Do not log normal websocket close errors

* Close the websocket connection in the tests properly

* Use Mutex instead of RWMutex

* Add debug log if we receive a non-binary message

* Add a type for requestType and responseType enums

* Clarify the comments for the start/stop event types

* Lock the websocket before reading

* Add a comment for active tasks

* Use session.UnmarshalTerminalParams for resizing, log error

* Change buffered events to bufferedEvent, add clarifying comment

* Fix types in test

* Wrap error

* go mod tidy all

* Satisfy the american spell checker

* Close the response body in tests

* Linting - use require.Len instead

* Remove mutex, fix test assertions

* Fix year in license

* Refactor the websocket to remove the mutex and use one goroutine for writing messages

* Add a wait group for streamEvents

* Rename to logWebsocketError

* Send a bad parameter error back if getting an unsupported event type

* Simplify needNewStream

* Update license year

* Close the websocket with a CloseUnsupportedData message on non-binary messages

* Gracefully handle the websocket closure

* Add tests for unsupported request, non-binary message and graceful websocket closing

* Remove mockClient.close()

* Fix data races and wait group reuse errors

* go mod tidy all

* Use time.Duration and rename timestamp to timeOffset

* Fix typo

* Add timeout for sending close message

* Change error to warn

* Remove unneeded nil check

* Add a debug log if we get something other than a close acknowledgement from the websocket

* Change VtStateToANSI to accept a bytes.Buffer to avoid multiple allocations

* Change inTimeRange logic

* Return session ID missing error through the websocket

* Correctly convert time.Duration <-> milliseconds where needed

* Cleanup the websocket graceful close at the handler level

* Fix tests to use durations

* Use a single wait group

* Change closeSent to be set by writeLoop

* Remove whitespace

* Debug log websocket errors

* Fix ANSI tests

* Remove string return from VtStateToANSI

* Ws -> WS

* Remove nested structs

* Remove unused stuff

* Move already sent check to inside the mutex lock

* Move the message encoding/decoding and other stuff to a separate file

* Use buf.Bytes(), duh

* Use the first resize event as the initial cols/rows of the session recording

* Use the main context for the stream so it isn't cancelled on each fetch request

* Remove newline

* Fix screen encoding to use response header size, not request

* Use better detection of initial size of terminal, add test for it

* Do not set hasSeenPrintEvent to true when dealing with resizes, only print events

---------

Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
2025-09-08 15:55:04 +00:00
..