Coverage for /builds/BuildGrid/buildgrid/buildgrid/server/introspection/service.py: 100.00%

21 statements  

« prev     ^ index     » next       coverage.py v7.4.1, created at 2025-08-20 14:29 +0000

1# Copyright (C) 2024 Bloomberg LP 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# <http://www.apache.org/licenses/LICENSE-2.0> 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15""" 

16IntrospectionService 

17==================== 

18 

19Definition of a IntrospectionService used for introspection and querying 

20of BuildGrid's internal state. 

21 

22""" 

23 

24 

25from typing import cast 

26 

27import grpc 

28 

29from buildgrid._protos.build.buildgrid.introspection_pb2 import ( 

30 DESCRIPTOR, 

31 GetOperationFiltersRequest, 

32 ListWorkersRequest, 

33 ListWorkersResponse, 

34 OperationFilters, 

35 OperationStats, 

36 OperationStatsRequest, 

37) 

38from buildgrid._protos.build.buildgrid.introspection_pb2_grpc import ( 

39 IntrospectionServicer, 

40 add_IntrospectionServicer_to_server, 

41) 

42from buildgrid.server.decorators import rpc 

43from buildgrid.server.introspection.instance import IntrospectionInstance 

44from buildgrid.server.servicer import InstancedServicer 

45 

46 

47class IntrospectionService(IntrospectionServicer, InstancedServicer[IntrospectionInstance]): 

48 SERVICE_NAME = "Introspection" 

49 REGISTER_METHOD = add_IntrospectionServicer_to_server 

50 FULL_NAME = DESCRIPTOR.services_by_name["Introspection"].full_name 

51 

52 @rpc(instance_getter=lambda r: cast(str, r.instance_name)) 

53 def ListWorkers(self, request: ListWorkersRequest, context: grpc.ServicerContext) -> ListWorkersResponse: 

54 return self.current_instance.list_workers(request) 

55 

56 @rpc(instance_getter=lambda r: cast(str, r.instance_name)) 

57 def GetOperationFilters( 

58 self, request: GetOperationFiltersRequest, context: grpc.ServicerContext 

59 ) -> OperationFilters: 

60 return self.current_instance.get_operation_filters() 

61 

62 @rpc(instance_getter=lambda r: cast(str, r.instance_name)) 

63 def GetOperationStats(self, request: OperationStatsRequest, context: grpc.ServicerContext) -> OperationStats: 

64 return self.current_instance.get_operation_stats(request)