buildgrid.server.logstream.streaming.memory module

class buildgrid.server.logstream.streaming.memory.StreamStorage

Bases: object

Class to store a collection of in-memory text streams.

This provides methods to retrieve a previously-added stream using the resource name for either read or write access, as well as a way to obtain a LogStream message for a stream with a given key.

add_stream(key: str, read_name: str, write_name: str) → None

Add a new stream to the store.

Takes a key and read/write resource names, and creates a new _Stream object with the given key.

Parameters
  • key (str) – The key to associate with the new stream.

  • read_name (str) – The resource name to use for read access to the new stream.

  • write_name (str) – The resource name to use for write access to the new stream.

get_stream(read_name: str) → Optional[buildgrid.server.logstream.streaming.memory._Stream]

Return a stream by its read resource name.

Takes a resource name and returns the _Stream object for a stream with the given name as its resource name for read access.

If no such stream exists, then this method returns None.

Parameters

read_name (str) – The read resource name of the stream to be returned.

get_writeable_stream(write_name: str) → Optional[buildgrid.server.logstream.streaming.memory._Stream]

Return a stream by its write resource name.

Takes a resource name and returns the _Stream object for a stream with the given name as its resource name for write access.

If no such stream exists, then this method returns None.

Parameters

write_name (str) – The write resource name of the stream to be returned.

get_logstream(key: str) → Optional[google.devtools.logstream.v1alpha1.logstream_pb2.LogStream]

Returns a LogStream gRPC object for a specified stream.

Takes a key which maps to a _Stream, and returns a LogStream gRPC message object for that stream.

If there is no string associated with the given key, then this method returns None.

Parameters

key (str) – The key used to store the stream to return a LogStream message for.

finish_stream(stream: buildgrid.server.logstream.streaming.memory._Stream) → None

Commit the stream, and remove it from the store if its unneeded.

A stream is unneeded/completed if it is committed and has no readers currently connected.

Parameters

stream (_Stream) – The stream object to commit and potentially clean up.

remove_reader(resource_name: str) → None

Remove a reader from a stream, and remove the stream if needed.

To keep from indefinitely growing our memory footprint, committed streams with no readers can be deleted.

Parameters

resource_name (str) – The resource name for the stream to remove a reader from.