buildgrid.server.server module

buildgrid.server.server.load_tls_server_credentials(server_key=None, server_cert=None, client_certs=None)

Looks-up and loads TLS server gRPC credentials.

Every private and public keys are expected to be PEM-encoded.

Parameters
  • server_key (str) – private server key file path.

  • server_cert (str) – public server certificate file path.

  • client_certs (str) – public client certificates file path.

Returns

The credentials for use for a TLS-encrypted gRPC server channel.

Return type

ServerCredentials

class buildgrid.server.server.Server(max_workers=None, monitor=False, mon_endpoint_type=<MonitoringOutputType.STDOUT: 'stdout'>, mon_endpoint_location=None, mon_serialisation_format=<MonitoringOutputFormat.JSON: 'json'>, mon_metric_prefix='', mon_tag_format=<StatsDTagFormat.NONE: 'none'>, auth_method=<AuthMetadataMethod.NONE: 'none'>, auth_secret=None, auth_jwks_url=None, auth_audience=None, auth_jwks_fetch_minutes=None, auth_algorithm=<AuthMetadataAlgorithm.UNSPECIFIED: 'unspecified'>, enable_server_reflection=True)

Bases: object

Creates a BuildGrid server instance.

The Server class binds together all the gRPC services.

start(*, on_server_start_cb: Optional[Callable] = None, port_assigned_callback: Optional[Callable] = None)None

Starts the BuildGrid server.

BuildGrid server startup consists of 3 stages,

  1. Starting logging and monitoring

This step starts up the logging coroutine, the periodic status metrics coroutine, and the monitoring bus’ publishing subprocess. Since this step involves forking, anything not fork-safe needs to be done after this step.

  1. Instantiate gRPC

This step instantiates the gRPC server, and tells all the instances which have been attached to the server to instantiate their gRPC objects. It is also responsible for creating the various service objects and connecting them to the server and the instances.

After this step, gRPC core is running and its no longer safe to fork the process.

  1. Start instances

Several of BuildGrid’s services use background threads that need to be explicitly started when BuildGrid starts up. Rather than doing this at configuration parsing time, this step provides a hook for services to start up in a more organised fashion.

  1. Start the gRPC server

The final step is starting up the gRPC server. The callback passed in via on_server_start_cb is executed in this step once the server has started. After this point BuildGrid is ready to serve requests.

The final thing done by this method is adding a SIGTERM handler which calls the Server.stop method to the event loop, and then that loop is started up using run_forever().

Parameters
  • on_server_start_cb (Callable) – Callback function to execute once the gRPC server has started up.

  • port_assigned_callback (Callable) – Callback function to execute once the gRPC server has started up. The mapping of addresses to ports is passed to this callback.

stop()

Stops the BuildGrid server.

add_port(address, credentials)

Adds a port to the server.

Must be called before the server starts. If a credentials object exists, it will make a secure port.

Parameters
  • address (str) – The address with port number.

  • credentials (grpc.ChannelCredentials) – Credentials object.

Returns

Number of the bound port.

Return type

int

Raises

PermissionDeniedError – If socket binding fails.

add_execution_instance(instance, instance_name)

Adds an ExecutionInstance to the service.

If no service exists, it creates one.

Parameters
  • instance (ExecutionInstance) – Instance to add.

  • instance_name (str) – Instance name.

add_bots_interface(instance, instance_name)

Adds a BotsInterface to the service.

If no service exists, it creates one.

Parameters
  • instance (BotsInterface) – Instance to add.

  • instance_name (str) – Instance name.

add_operations_instance(instance, instance_name)

Adds an OperationsInstance to the service.

If no service exists, it creates one.

Parameters
  • instance (OperationsInstance) – Instance to add.

  • instance_name (str) – Instance name.

add_reference_storage_instance(instance, instance_name)

Adds a ReferenceCache to the service.

If no service exists, it creates one.

Parameters
  • instance (ReferenceCache) – Instance to add.

  • instance_name (str) – Instance name.

add_action_cache_instance(instance, instance_name)

Adds a ReferenceCache to the service.

If no service exists, it creates one.

Parameters
  • instance (ReferenceCache) – Instance to add.

  • instance_name (str) – Instance name.

add_cas_instance(instance, instance_name)

Adds a ContentAddressableStorageInstance to the service.

If no service exists, it creates one.

Parameters
  • instance (ReferenceCache) – Instance to add.

  • instance_name (str) – Instance name.

add_bytestream_instance(instance, instance_name)

Adds a ByteStreamInstance to the service.

If no service exists, it creates one.

Parameters
  • instance (ByteStreamInstance) – Instance to add.

  • instance_name (str) – Instance name.

add_logstream_instance(instance, instance_name)

Adds a LogStreamInstance to the service.

If no service exists, it creates one.

Parameters
  • instance (LogStreamInstance) – Instance to add.

  • instance_name (str) – The name of the instance being added.

add_build_events_storage(storage_backend)

Adds a BuildEventStreamStorage to the server.

This is used to decide whether to create the Build Events services in the server. No instance name is passed in since the Build Events protocol has no support for instance names.

property is_instrumented