Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DO NOT MERGE demonstrate Reset removal and updated tests #50875

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions lib/events/filesessions/fileasync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -665,19 +665,24 @@ func readStream(ctx context.Context, t *testing.T, uploadID string, uploader *ev
parts, err := uploader.GetParts(uploadID)
require.NoError(t, err)

var outEvents []apievents.AuditEvent
var reader *events.ProtoReader
for i, part := range parts {
if i == 0 {
reader = events.NewProtoReader(bytes.NewReader(part))
} else {
err := reader.Reset(bytes.NewReader(part))
require.NoError(t, err)
}
out, err := reader.ReadAll(ctx)
require.NoError(t, err, "part crash %#v", part)

outEvents = append(outEvents, out...)
// combine all uploaded parts to create the session recording content
var sessionRecordingContent bytes.Buffer
for _, part := range parts {
bytesWritten, err := sessionRecordingContent.Write(part)
require.NoError(t, err, "error writing part bytes to session recording content")
require.Equal(t, len(part), bytesWritten, "not all bytes were written to session recording content")
}

// Note: it is possible for duplicate event indices to be encountered in cases where the upload process
// encounters an error such as the connection being termianted, since the upload process will retry uploading
// those events for a successful upload. This is not an issue because session recording reader knows to drop
// events found with an event index already read.
reader := events.NewProtoReader(&sessionRecordingContent)

outEvents, err := reader.ReadAll(ctx)
require.NoError(t, err, "error reading all session recording content")

require.NoError(t, reader.Close(), "error closing session recording reader")

return outEvents
}
18 changes: 0 additions & 18 deletions lib/events/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -1002,24 +1002,6 @@ func (r *ProtoReader) Close() error {
return nil
}

// Reset sets reader to read from the new reader
// without resetting the stats, could be used
// to deduplicate the events
func (r *ProtoReader) Reset(reader io.Reader) error {
if r.error != nil {
return r.error
}
if r.gzipReader != nil {
if r.error = r.gzipReader.Close(); r.error != nil {
return trace.Wrap(r.error)
}
r.gzipReader = nil
}
r.reader = reader
r.state = protoReaderStateInit
return nil
}

func (r *ProtoReader) setError(err error) error {
r.state = protoReaderStateError
r.error = err
Expand Down
Loading