buildgrid.server.build_events.storage module
- exception buildgrid.server.build_events.storage.DuplicateStreamError
Bases:
ExceptionError when encountering a name collision between event streams.
- class buildgrid.server.build_events.storage.BuildEventStream(stream_id: StreamId)
Bases:
objectInternal representation of a stream of OrderedBuildEvents.
This class provides in-memory storage of the events in a given Build Event Stream. Many of these Build Event Streams may relate to the same build, or even to the same invocation of a tool.
- Parameters:
stream_id (StreamId) – A gRPC message defining the ID of this stream.
- publish_event(event: OrderedBuildEvent) None
Publish an
OrderedBuildEventinto the stream.- Parameters:
event (OrderedBuildEvent) – The event to publish to the stream. This is an
OrderedBuildEventmessage from thepublish_build_eventproto.
- query_events(query: str | None = None) Iterator[OrderedBuildEvent]
Query the contents of this stream.
Filter the contents of the event stream by some query, returning an iterator of matching OrderedBuildEvents.
Note
The filtering functionality of this method is currently not implemented, and the iterator returned contains all the events in the stream no matter what query is used.
- Parameters:
query (str) – The filter string to use when querying events.
- to_grpc_message() BuildEventStream
Convert this object to a
BuildEventStreamgRPC message.This method converts this internal event stream representation into a
QueryEventStreamsResponse.BuildEventStreamgRPC message, as defined in thequery_build_eventsproto.
- class buildgrid.server.build_events.storage.BuildEventStreamStorage
Bases:
InstanceIn-memory storage of Build Event Streams.
This class stores a collection of Build Event Streams, and handles both creation of new streams and querying the streams which already exist based on their stream ID. Streams are stored in-memory and are lost on service restart, so shouldn’t be relied on as a source of persistent data when using this storage class.
This class is similar to the
.*Instanceclasses used by other BuildGrid services, in that it is instantiated by the config parser and used by a.*Serviceclass instantiated by the server class. Unlike the other instance classes however, this class doesn’t have aninstance_nameattribute due to the Build Events protos not having the concept of multiple instances.- SERVICE_NAME: ClassVar[str] = 'BuildEvents'
The expected FULL_NAME of the Service which will wrap this instance. This value should be declared on the class of any Instance implementations.
- new_stream(stream_id: StreamId) BuildEventStream
Create and return a new
BuildEventStreamwith the given ID.This method creates a new
BuildEventStreamwith the givenStreamId, and returns it. If a stream with that ID already exists in thisBuildEventStreamStorage, then aDuplicateStreamErroris raised.- Parameters:
stream_id (StreamId) – The gRPC StreamId message containing the ID of the stream to create.
- get_stream(stream_id: StreamId) BuildEventStream
Return a
BuildEventStreamwith the given stream ID.This method takes a stream ID, converts it to a stream key, and returns the stream with that key if one exists.
This method will create a new
BuildEventStreamif one with the given ID doesn’t exist.- Parameters:
stream_id (StreamId) – The StreamID message from an event to get the
BuildEventStreamfor.- Returns:
A
BuildEventStreamwith the given ID, or None.
- get_matching_streams(stream_key_regex: str) list[BuildEventStream]
Return a list of event streams which match the given key pattern.
This method takes a regular expression as a string, and returns a list of
BuildEventStreamobjects whose stream key (based on the events’ StreamId) matches the regex.- Parameters:
stream_key_regex (str) – A regular expression to use to find matching streams.
- Returns:
List of
BuildEventStreamobjects which have a key matching the given regex.