Skip to content

`GetOperation()`: return associated `RequestMetadata`

Santiago Gil requested to merge santigl/list-operations-request-metadata into master

Before raising this MR, consider whether the following are required, and complete if so:

  • Unit tests
  • Metrics TO-DO
  • Documentation update(s)

If not required, please explain in brief why not.

Description

Problem

The REAPI defines the RequestMetadata message that can be attached to any gRPC request. It is used by clients to report the following values to BuildGrid: a tool name and version, an invocation_id, and a correlated-invocations-id.

BuildGrid stores that data in the SQL database (as part of the Operation model), and it is possible to query operations filtering by those values (for example, to find all Operations with a given invocation_id). However, there is currently no way of fetching those entries for a known Operation.

Such a feature is needed for bgd-browser#10 (closed), where the view for a particular Operation needs to link to other operations with the same invocation/correlated-invocations id.

Solution

This extends the OperationsService.GetOperation() servicer to return a RequestMetadata message as part of the trailing metadata sent to the client.

To allow the gRPC servicer to have access to the necessary data, these changes add getters to the DataStore and Scheduler interfaces.

They also extend the bgd operations command with an option to print the metadata returned by the server.

Changes proposed in this merge request:

  • DataStore: add get_operation_request_metadata_by_name() to the interface
    • Implement it for SQLDataStore
    • Implement a dummy method for MemoryDataStore (RequestMetadata values are not stored for this implementation)
  • Scheduler: add get_operation_request_metadata() getter
  • Refactor request_metadata_utils.py helpers to make them more general and increase reusability
  • cmd_operation.py: add --show_request_metadata option to bgd operation status to display RequestMetadata messages returned by the server
  • Add unit tests

Validation

The new --show_request_metadata option in bgd operation status can be used to verify that the metadata returned corresponds to the values attached by the client in its request:

> bgd operation status "/46107117-3457-4210-b837-cf0a1255c4d5" --show-request-metadata
Queued: /46107117-3457-4210-b837-cf0a1255c4d5: Waiting for execution (stage=2)
Request metadata: [tool_name="recc", tool_version="b34e7ea", action_id="", tool_invocation_id="host:21878", correlated_invocations_id=""]

Issues addressed

Related to bgd-browser#10 (closed)

Edited by Santiago Gil

Merge request reports