async def test_report_async(transport: str = 'grpc_asyncio', request_type=service_controller.ReportRequest): client = ServiceControllerAsyncClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.report), '__call__') as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( service_controller.ReportResponse( service_config_id='service_config_id_value', service_rollout_id='service_rollout_id_value', )) response = await client.report(request) # Establish that the underlying gRPC stub method was called. assert len(call.mock_calls) _, args, _ = call.mock_calls[0] assert args[0] == service_controller.ReportRequest() # Establish that the response is the type that we expect. assert isinstance(response, service_controller.ReportResponse) assert response.service_config_id == 'service_config_id_value' assert response.service_rollout_id == 'service_rollout_id_value'
def report( self, request: service_controller.ReportRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> service_controller.ReportResponse: r"""Reports operation results to Google Service Control, such as logs and metrics. It should be called after an operation is completed. If feasible, the client should aggregate reporting data for up to 5 seconds to reduce API traffic. Limiting aggregation to 5 seconds is to reduce data loss during client crashes. Clients should carefully choose the aggregation time window to avoid data loss risk more than 0.01% for business and compliance reasons. NOTE: the [ReportRequest][google.api.servicecontrol.v1.ReportRequest] has the size limit (wire-format byte size) of 1MB. This method requires the ``servicemanagement.services.report`` permission on the specified service. For more information, see `Google Cloud IAM <https://cloud.google.com/iam>`__. Args: request (google.cloud.servicecontrol_v1.types.ReportRequest): The request object. Request message for the Report method. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.servicecontrol_v1.types.ReportResponse: Response message for the Report method. """ # Create or coerce a protobuf request object. # Minor optimization to avoid making a copy if the user passes # in a service_controller.ReportRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, service_controller.ReportRequest): request = service_controller.ReportRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[self._transport.report] # Send the request. response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response
def test_report_empty_call(): # This test is a coverage failsafe to make sure that totally empty calls, # i.e. request == None and no flattened fields passed, work. client = ServiceControllerClient( credentials=ga_credentials.AnonymousCredentials(), transport="grpc", ) # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object(type(client.transport.report), "__call__") as call: client.report() call.assert_called() _, args, _ = call.mock_calls[0] assert args[0] == service_controller.ReportRequest()
async def report(self, request: service_controller.ReportRequest = None, *, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> service_controller.ReportResponse: r"""Reports operation results to Google Service Control, such as logs and metrics. It should be called after an operation is completed. If feasible, the client should aggregate reporting data for up to 5 seconds to reduce API traffic. Limiting aggregation to 5 seconds is to reduce data loss during client crashes. Clients should carefully choose the aggregation time window to avoid data loss risk more than 0.01% for business and compliance reasons. NOTE: the [ReportRequest][google.api.servicecontrol.v1.ReportRequest] has the size limit (wire-format byte size) of 1MB. This method requires the ``servicemanagement.services.report`` permission on the specified service. For more information, see `Google Cloud IAM <https://cloud.google.com/iam>`__. Args: request (:class:`google.cloud.servicecontrol_v1.types.ReportRequest`): The request object. Request message for the Report method. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.servicecontrol_v1.types.ReportResponse: Response message for the Report method. """ # Create or coerce a protobuf request object. request = service_controller.ReportRequest(request) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.report, default_timeout=16.0, client_info=DEFAULT_CLIENT_INFO, ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response