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

Reduce api/sessionrecording's Reader API and misc. improvements #50883

Open
wants to merge 24 commits into
base: dustin.specker/move-proto-reader-to-api
Choose a base branch
from

Conversation

dustinspecker
Copy link

@dustinspecker dustinspecker commented Jan 8, 2025

This pull request:

  • removes functions from the sessionrecording.Reader API, notable Reset
  • removes unnecessary support code such as a custom gzipReader
  • updates GoDoc
  • use slog.LogValuer

This pull request builds on top of #50501

changelog: reduce api/sessionrecording.Reader API

Before, this was taking an io.ReadCloser, but newGzipReader was always
being used by sessionrecording with io.NopCloser. So, just take an
io.Reader.
After accepting only a io.Reader, gzipReader doesn't make much sense
anymore. Instead, update sessionrecording.Reader to construct a
gzip.Reader with Multistream disabled.
Previously, newGzipWriter took an io.WriteCloser, but the only
time newGzipWriter was being used was with a Closer that did nothing.
So just take an io.Writer instead. This also enables removing the
bufferCloser struct.
This is mostly to help clarify what the different readers do.
Reader.Reset was only being used by tests. Remove Reset from the API, so
it does not need to be supported for consumers. Update tests to not
require Reset usage.
This prevents any unsafe int64 to int conversions.
Before, a session recording reader was being created for each uploaded
part. There are situations where duplicate event indices may be
uploaded. This was causing the test cases to have to de-duplicate
events.

Now, combine all uploaded parts into a single byte slice (bytes.Buffer)
to be read by a single session recording reader. The reader already
knows to drop duplicate event indices.
… struct

This will prevent Go from needing to allocate and zero out 64K for each
invocation of Read. This may possibly reduce the chances of Go doing a
heap allocation.
@dustinspecker dustinspecker marked this pull request as ready for review January 8, 2025 19:41
@github-actions github-actions bot added audit-log Issues related to Teleports Audit Log size/sm labels Jan 8, 2025
@github-actions github-actions bot requested review from kiosion and smallinsky January 8, 2025 19:42
slog.Int64("skipped_events", p.SkippedEvents),
slog.Int64("out_of_order_events", p.OutOfOrderEvents),
slog.Int64("total_events", p.TotalEvents),
)
}

// Close releases reader resources
Copy link
Author

@dustinspecker dustinspecker Jan 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rosstimothy brought up the following on the original pull request.

"Is is possible that gzipReader is assigned after the check on line 129? For instance what if Read is being executed in another goroutine?"

This was true, but is no longer true since sessionrecording.Reader
does this behavior by default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
audit-log Issues related to Teleports Audit Log size/sm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant