Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/google/cloud/errorreporting_v1beta1/services/error_stats_service/async_client.py: 52%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

120 statements  

1# -*- coding: utf-8 -*- 

2# Copyright 2025 Google LLC 

3# 

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

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

6# You may obtain a copy of the License at 

7# 

8# http://www.apache.org/licenses/LICENSE-2.0 

9# 

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

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

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

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

14# limitations under the License. 

15# 

16import logging as std_logging 

17from collections import OrderedDict 

18import re 

19from typing import ( 

20 Dict, 

21 Callable, 

22 Mapping, 

23 MutableMapping, 

24 MutableSequence, 

25 Optional, 

26 Sequence, 

27 Tuple, 

28 Type, 

29 Union, 

30) 

31 

32from google.cloud.errorreporting_v1beta1 import gapic_version as package_version 

33 

34from google.api_core.client_options import ClientOptions 

35from google.api_core import exceptions as core_exceptions 

36from google.api_core import gapic_v1 

37from google.api_core import retry_async as retries 

38from google.auth import credentials as ga_credentials # type: ignore 

39from google.oauth2 import service_account # type: ignore 

40import google.protobuf 

41 

42 

43try: 

44 OptionalRetry = Union[retries.AsyncRetry, gapic_v1.method._MethodDefault, None] 

45except AttributeError: # pragma: NO COVER 

46 OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore 

47 

48from google.cloud.errorreporting_v1beta1.services.error_stats_service import pagers 

49from google.cloud.errorreporting_v1beta1.types import common 

50from google.cloud.errorreporting_v1beta1.types import error_stats_service 

51from .transports.base import ErrorStatsServiceTransport, DEFAULT_CLIENT_INFO 

52from .transports.grpc_asyncio import ErrorStatsServiceGrpcAsyncIOTransport 

53from .client import ErrorStatsServiceClient 

54 

55try: 

56 from google.api_core import client_logging # type: ignore 

57 

58 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER 

59except ImportError: # pragma: NO COVER 

60 CLIENT_LOGGING_SUPPORTED = False 

61 

62_LOGGER = std_logging.getLogger(__name__) 

63 

64 

65class ErrorStatsServiceAsyncClient: 

66 """An API for retrieving and managing error statistics as well 

67 as data for individual events. 

68 """ 

69 

70 _client: ErrorStatsServiceClient 

71 

72 # Copy defaults from the synchronous client for use here. 

73 # Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead. 

74 DEFAULT_ENDPOINT = ErrorStatsServiceClient.DEFAULT_ENDPOINT 

75 DEFAULT_MTLS_ENDPOINT = ErrorStatsServiceClient.DEFAULT_MTLS_ENDPOINT 

76 _DEFAULT_ENDPOINT_TEMPLATE = ErrorStatsServiceClient._DEFAULT_ENDPOINT_TEMPLATE 

77 _DEFAULT_UNIVERSE = ErrorStatsServiceClient._DEFAULT_UNIVERSE 

78 

79 error_group_path = staticmethod(ErrorStatsServiceClient.error_group_path) 

80 parse_error_group_path = staticmethod( 

81 ErrorStatsServiceClient.parse_error_group_path 

82 ) 

83 common_billing_account_path = staticmethod( 

84 ErrorStatsServiceClient.common_billing_account_path 

85 ) 

86 parse_common_billing_account_path = staticmethod( 

87 ErrorStatsServiceClient.parse_common_billing_account_path 

88 ) 

89 common_folder_path = staticmethod(ErrorStatsServiceClient.common_folder_path) 

90 parse_common_folder_path = staticmethod( 

91 ErrorStatsServiceClient.parse_common_folder_path 

92 ) 

93 common_organization_path = staticmethod( 

94 ErrorStatsServiceClient.common_organization_path 

95 ) 

96 parse_common_organization_path = staticmethod( 

97 ErrorStatsServiceClient.parse_common_organization_path 

98 ) 

99 common_project_path = staticmethod(ErrorStatsServiceClient.common_project_path) 

100 parse_common_project_path = staticmethod( 

101 ErrorStatsServiceClient.parse_common_project_path 

102 ) 

103 common_location_path = staticmethod(ErrorStatsServiceClient.common_location_path) 

104 parse_common_location_path = staticmethod( 

105 ErrorStatsServiceClient.parse_common_location_path 

106 ) 

107 

108 @classmethod 

109 def from_service_account_info(cls, info: dict, *args, **kwargs): 

110 """Creates an instance of this client using the provided credentials 

111 info. 

112 

113 Args: 

114 info (dict): The service account private key info. 

115 args: Additional arguments to pass to the constructor. 

116 kwargs: Additional arguments to pass to the constructor. 

117 

118 Returns: 

119 ErrorStatsServiceAsyncClient: The constructed client. 

120 """ 

121 sa_info_func = ( 

122 ErrorStatsServiceClient.from_service_account_info.__func__ # type: ignore 

123 ) 

124 return sa_info_func(ErrorStatsServiceAsyncClient, info, *args, **kwargs) 

125 

126 @classmethod 

127 def from_service_account_file(cls, filename: str, *args, **kwargs): 

128 """Creates an instance of this client using the provided credentials 

129 file. 

130 

131 Args: 

132 filename (str): The path to the service account private key json 

133 file. 

134 args: Additional arguments to pass to the constructor. 

135 kwargs: Additional arguments to pass to the constructor. 

136 

137 Returns: 

138 ErrorStatsServiceAsyncClient: The constructed client. 

139 """ 

140 sa_file_func = ( 

141 ErrorStatsServiceClient.from_service_account_file.__func__ # type: ignore 

142 ) 

143 return sa_file_func(ErrorStatsServiceAsyncClient, filename, *args, **kwargs) 

144 

145 from_service_account_json = from_service_account_file 

146 

147 @classmethod 

148 def get_mtls_endpoint_and_cert_source( 

149 cls, client_options: Optional[ClientOptions] = None 

150 ): 

151 """Return the API endpoint and client cert source for mutual TLS. 

152 

153 The client cert source is determined in the following order: 

154 (1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the 

155 client cert source is None. 

156 (2) if `client_options.client_cert_source` is provided, use the provided one; if the 

157 default client cert source exists, use the default one; otherwise the client cert 

158 source is None. 

159 

160 The API endpoint is determined in the following order: 

161 (1) if `client_options.api_endpoint` if provided, use the provided one. 

162 (2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the 

163 default mTLS endpoint; if the environment variable is "never", use the default API 

164 endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise 

165 use the default API endpoint. 

166 

167 More details can be found at https://google.aip.dev/auth/4114. 

168 

169 Args: 

170 client_options (google.api_core.client_options.ClientOptions): Custom options for the 

171 client. Only the `api_endpoint` and `client_cert_source` properties may be used 

172 in this method. 

173 

174 Returns: 

175 Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the 

176 client cert source to use. 

177 

178 Raises: 

179 google.auth.exceptions.MutualTLSChannelError: If any errors happen. 

180 """ 

181 return ErrorStatsServiceClient.get_mtls_endpoint_and_cert_source(client_options) # type: ignore 

182 

183 @property 

184 def transport(self) -> ErrorStatsServiceTransport: 

185 """Returns the transport used by the client instance. 

186 

187 Returns: 

188 ErrorStatsServiceTransport: The transport used by the client instance. 

189 """ 

190 return self._client.transport 

191 

192 @property 

193 def api_endpoint(self): 

194 """Return the API endpoint used by the client instance. 

195 

196 Returns: 

197 str: The API endpoint used by the client instance. 

198 """ 

199 return self._client._api_endpoint 

200 

201 @property 

202 def universe_domain(self) -> str: 

203 """Return the universe domain used by the client instance. 

204 

205 Returns: 

206 str: The universe domain used 

207 by the client instance. 

208 """ 

209 return self._client._universe_domain 

210 

211 get_transport_class = ErrorStatsServiceClient.get_transport_class 

212 

213 def __init__( 

214 self, 

215 *, 

216 credentials: Optional[ga_credentials.Credentials] = None, 

217 transport: Optional[ 

218 Union[ 

219 str, 

220 ErrorStatsServiceTransport, 

221 Callable[..., ErrorStatsServiceTransport], 

222 ] 

223 ] = "grpc_asyncio", 

224 client_options: Optional[ClientOptions] = None, 

225 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

226 ) -> None: 

227 """Instantiates the error stats service async client. 

228 

229 Args: 

230 credentials (Optional[google.auth.credentials.Credentials]): The 

231 authorization credentials to attach to requests. These 

232 credentials identify the application to the service; if none 

233 are specified, the client will attempt to ascertain the 

234 credentials from the environment. 

235 transport (Optional[Union[str,ErrorStatsServiceTransport,Callable[..., ErrorStatsServiceTransport]]]): 

236 The transport to use, or a Callable that constructs and returns a new transport to use. 

237 If a Callable is given, it will be called with the same set of initialization 

238 arguments as used in the ErrorStatsServiceTransport constructor. 

239 If set to None, a transport is chosen automatically. 

240 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): 

241 Custom options for the client. 

242 

243 1. The ``api_endpoint`` property can be used to override the 

244 default endpoint provided by the client when ``transport`` is 

245 not explicitly provided. Only if this property is not set and 

246 ``transport`` was not explicitly provided, the endpoint is 

247 determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment 

248 variable, which have one of the following values: 

249 "always" (always use the default mTLS endpoint), "never" (always 

250 use the default regular endpoint) and "auto" (auto-switch to the 

251 default mTLS endpoint if client certificate is present; this is 

252 the default value). 

253 

254 2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

255 is "true", then the ``client_cert_source`` property can be used 

256 to provide a client certificate for mTLS transport. If 

257 not provided, the default SSL client certificate will be used if 

258 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

259 set, no client certificate will be used. 

260 

261 3. The ``universe_domain`` property can be used to override the 

262 default "googleapis.com" universe. Note that ``api_endpoint`` 

263 property still takes precedence; and ``universe_domain`` is 

264 currently not supported for mTLS. 

265 

266 client_info (google.api_core.gapic_v1.client_info.ClientInfo): 

267 The client info used to send a user-agent string along with 

268 API requests. If ``None``, then default info will be used. 

269 Generally, you only need to set this if you're developing 

270 your own client library. 

271 

272 Raises: 

273 google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport 

274 creation failed for any reason. 

275 """ 

276 self._client = ErrorStatsServiceClient( 

277 credentials=credentials, 

278 transport=transport, 

279 client_options=client_options, 

280 client_info=client_info, 

281 ) 

282 

283 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor( 

284 std_logging.DEBUG 

285 ): # pragma: NO COVER 

286 _LOGGER.debug( 

287 "Created client `google.devtools.clouderrorreporting_v1beta1.ErrorStatsServiceAsyncClient`.", 

288 extra={ 

289 "serviceName": "google.devtools.clouderrorreporting.v1beta1.ErrorStatsService", 

290 "universeDomain": getattr( 

291 self._client._transport._credentials, "universe_domain", "" 

292 ), 

293 "credentialsType": f"{type(self._client._transport._credentials).__module__}.{type(self._client._transport._credentials).__qualname__}", 

294 "credentialsInfo": getattr( 

295 self.transport._credentials, "get_cred_info", lambda: None 

296 )(), 

297 } 

298 if hasattr(self._client._transport, "_credentials") 

299 else { 

300 "serviceName": "google.devtools.clouderrorreporting.v1beta1.ErrorStatsService", 

301 "credentialsType": None, 

302 }, 

303 ) 

304 

305 async def list_group_stats( 

306 self, 

307 request: Optional[ 

308 Union[error_stats_service.ListGroupStatsRequest, dict] 

309 ] = None, 

310 *, 

311 project_name: Optional[str] = None, 

312 time_range: Optional[error_stats_service.QueryTimeRange] = None, 

313 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

314 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

315 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

316 ) -> pagers.ListGroupStatsAsyncPager: 

317 r"""Lists the specified groups. 

318 

319 .. code-block:: python 

320 

321 # This snippet has been automatically generated and should be regarded as a 

322 # code template only. 

323 # It will require modifications to work: 

324 # - It may require correct/in-range values for request initialization. 

325 # - It may require specifying regional endpoints when creating the service 

326 # client as shown in: 

327 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

328 from google.cloud import errorreporting_v1beta1 

329 

330 async def sample_list_group_stats(): 

331 # Create a client 

332 client = errorreporting_v1beta1.ErrorStatsServiceAsyncClient() 

333 

334 # Initialize request argument(s) 

335 request = errorreporting_v1beta1.ListGroupStatsRequest( 

336 project_name="project_name_value", 

337 ) 

338 

339 # Make the request 

340 page_result = client.list_group_stats(request=request) 

341 

342 # Handle the response 

343 async for response in page_result: 

344 print(response) 

345 

346 Args: 

347 request (Optional[Union[google.cloud.errorreporting_v1beta1.types.ListGroupStatsRequest, dict]]): 

348 The request object. Specifies a set of ``ErrorGroupStats`` to return. 

349 project_name (:class:`str`): 

350 Required. The resource name of the Google Cloud Platform 

351 project. Written as ``projects/{projectID}`` or 

352 ``projects/{projectNumber}``, where ``{projectID}`` and 

353 ``{projectNumber}`` can be found in the `Google Cloud 

354 console <https://support.google.com/cloud/answer/6158840>`__. 

355 It may also include a location, such as 

356 ``projects/{projectID}/locations/{location}`` where 

357 ``{location}`` is a cloud region. 

358 

359 Examples: ``projects/my-project-123``, 

360 ``projects/5551234``, 

361 ``projects/my-project-123/locations/us-central1``, 

362 ``projects/5551234/locations/us-central1``. 

363 

364 For a list of supported locations, see `Supported 

365 Regions <https://cloud.google.com/logging/docs/region-support>`__. 

366 ``global`` is the default when unspecified. Use ``-`` as 

367 a wildcard to request group stats from all regions. 

368 

369 This corresponds to the ``project_name`` field 

370 on the ``request`` instance; if ``request`` is provided, this 

371 should not be set. 

372 time_range (:class:`google.cloud.errorreporting_v1beta1.types.QueryTimeRange`): 

373 Optional. List data for the given time range. If not 

374 set, a default time range is used. The field 

375 [time_range_begin] 

376 [google.devtools.clouderrorreporting.v1beta1.ListGroupStatsResponse.time_range_begin] 

377 in the response will specify the beginning of this time 

378 range. Only [ErrorGroupStats] 

379 [google.devtools.clouderrorreporting.v1beta1.ErrorGroupStats] 

380 with a non-zero count in the given time range are 

381 returned, unless the request contains an explicit 

382 [group_id] 

383 [google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest.group_id] 

384 list. If a [group_id] 

385 [google.devtools.clouderrorreporting.v1beta1.ListGroupStatsRequest.group_id] 

386 list is given, also [ErrorGroupStats] 

387 [google.devtools.clouderrorreporting.v1beta1.ErrorGroupStats] 

388 with zero occurrences are returned. 

389 

390 This corresponds to the ``time_range`` field 

391 on the ``request`` instance; if ``request`` is provided, this 

392 should not be set. 

393 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

394 should be retried. 

395 timeout (float): The timeout for this request. 

396 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

397 sent along with the request as metadata. Normally, each value must be of type `str`, 

398 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

399 be of type `bytes`. 

400 

401 Returns: 

402 google.cloud.errorreporting_v1beta1.services.error_stats_service.pagers.ListGroupStatsAsyncPager: 

403 Contains a set of requested error 

404 group stats. 

405 Iterating over this object will yield 

406 results and resolve additional pages 

407 automatically. 

408 

409 """ 

410 # Create or coerce a protobuf request object. 

411 # - Quick check: If we got a request object, we should *not* have 

412 # gotten any keyword arguments that map to the request. 

413 flattened_params = [project_name, time_range] 

414 has_flattened_params = ( 

415 len([param for param in flattened_params if param is not None]) > 0 

416 ) 

417 if request is not None and has_flattened_params: 

418 raise ValueError( 

419 "If the `request` argument is set, then none of " 

420 "the individual field arguments should be set." 

421 ) 

422 

423 # - Use the request object if provided (there's no risk of modifying the input as 

424 # there are no flattened fields), or create one. 

425 if not isinstance(request, error_stats_service.ListGroupStatsRequest): 

426 request = error_stats_service.ListGroupStatsRequest(request) 

427 

428 # If we have keyword arguments corresponding to fields on the 

429 # request, apply these. 

430 if project_name is not None: 

431 request.project_name = project_name 

432 if time_range is not None: 

433 request.time_range = time_range 

434 

435 # Wrap the RPC method; this adds retry and timeout information, 

436 # and friendly error handling. 

437 rpc = self._client._transport._wrapped_methods[ 

438 self._client._transport.list_group_stats 

439 ] 

440 

441 # Certain fields should be provided within the metadata header; 

442 # add these here. 

443 metadata = tuple(metadata) + ( 

444 gapic_v1.routing_header.to_grpc_metadata( 

445 (("project_name", request.project_name),) 

446 ), 

447 ) 

448 

449 # Validate the universe domain. 

450 self._client._validate_universe_domain() 

451 

452 # Send the request. 

453 response = await rpc( 

454 request, 

455 retry=retry, 

456 timeout=timeout, 

457 metadata=metadata, 

458 ) 

459 

460 # This method is paged; wrap the response in a pager, which provides 

461 # an `__aiter__` convenience method. 

462 response = pagers.ListGroupStatsAsyncPager( 

463 method=rpc, 

464 request=request, 

465 response=response, 

466 retry=retry, 

467 timeout=timeout, 

468 metadata=metadata, 

469 ) 

470 

471 # Done; return the response. 

472 return response 

473 

474 async def list_events( 

475 self, 

476 request: Optional[Union[error_stats_service.ListEventsRequest, dict]] = None, 

477 *, 

478 project_name: Optional[str] = None, 

479 group_id: Optional[str] = None, 

480 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

481 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

482 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

483 ) -> pagers.ListEventsAsyncPager: 

484 r"""Lists the specified events. 

485 

486 .. code-block:: python 

487 

488 # This snippet has been automatically generated and should be regarded as a 

489 # code template only. 

490 # It will require modifications to work: 

491 # - It may require correct/in-range values for request initialization. 

492 # - It may require specifying regional endpoints when creating the service 

493 # client as shown in: 

494 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

495 from google.cloud import errorreporting_v1beta1 

496 

497 async def sample_list_events(): 

498 # Create a client 

499 client = errorreporting_v1beta1.ErrorStatsServiceAsyncClient() 

500 

501 # Initialize request argument(s) 

502 request = errorreporting_v1beta1.ListEventsRequest( 

503 project_name="project_name_value", 

504 group_id="group_id_value", 

505 ) 

506 

507 # Make the request 

508 page_result = client.list_events(request=request) 

509 

510 # Handle the response 

511 async for response in page_result: 

512 print(response) 

513 

514 Args: 

515 request (Optional[Union[google.cloud.errorreporting_v1beta1.types.ListEventsRequest, dict]]): 

516 The request object. Specifies a set of error events to 

517 return. 

518 project_name (:class:`str`): 

519 Required. The resource name of the Google Cloud Platform 

520 project. Written as ``projects/{projectID}`` or 

521 ``projects/{projectID}/locations/{location}``, where 

522 ``{projectID}`` is the `Google Cloud Platform project 

523 ID <https://support.google.com/cloud/answer/6158840>`__ 

524 and ``{location}`` is a Cloud region. 

525 

526 Examples: ``projects/my-project-123``, 

527 ``projects/my-project-123/locations/global``. 

528 

529 For a list of supported locations, see `Supported 

530 Regions <https://cloud.google.com/logging/docs/region-support>`__. 

531 ``global`` is the default when unspecified. 

532 

533 This corresponds to the ``project_name`` field 

534 on the ``request`` instance; if ``request`` is provided, this 

535 should not be set. 

536 group_id (:class:`str`): 

537 Required. The group for which events shall be returned. 

538 The ``group_id`` is a unique identifier for a particular 

539 error group. The identifier is derived from key parts of 

540 the error-log content and is treated as Service Data. 

541 For information about how Service Data is handled, see 

542 `Google Cloud Privacy 

543 Notice <https://cloud.google.com/terms/cloud-privacy-notice>`__. 

544 

545 This corresponds to the ``group_id`` field 

546 on the ``request`` instance; if ``request`` is provided, this 

547 should not be set. 

548 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

549 should be retried. 

550 timeout (float): The timeout for this request. 

551 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

552 sent along with the request as metadata. Normally, each value must be of type `str`, 

553 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

554 be of type `bytes`. 

555 

556 Returns: 

557 google.cloud.errorreporting_v1beta1.services.error_stats_service.pagers.ListEventsAsyncPager: 

558 Contains a set of requested error 

559 events. 

560 Iterating over this object will yield 

561 results and resolve additional pages 

562 automatically. 

563 

564 """ 

565 # Create or coerce a protobuf request object. 

566 # - Quick check: If we got a request object, we should *not* have 

567 # gotten any keyword arguments that map to the request. 

568 flattened_params = [project_name, group_id] 

569 has_flattened_params = ( 

570 len([param for param in flattened_params if param is not None]) > 0 

571 ) 

572 if request is not None and has_flattened_params: 

573 raise ValueError( 

574 "If the `request` argument is set, then none of " 

575 "the individual field arguments should be set." 

576 ) 

577 

578 # - Use the request object if provided (there's no risk of modifying the input as 

579 # there are no flattened fields), or create one. 

580 if not isinstance(request, error_stats_service.ListEventsRequest): 

581 request = error_stats_service.ListEventsRequest(request) 

582 

583 # If we have keyword arguments corresponding to fields on the 

584 # request, apply these. 

585 if project_name is not None: 

586 request.project_name = project_name 

587 if group_id is not None: 

588 request.group_id = group_id 

589 

590 # Wrap the RPC method; this adds retry and timeout information, 

591 # and friendly error handling. 

592 rpc = self._client._transport._wrapped_methods[ 

593 self._client._transport.list_events 

594 ] 

595 

596 # Certain fields should be provided within the metadata header; 

597 # add these here. 

598 metadata = tuple(metadata) + ( 

599 gapic_v1.routing_header.to_grpc_metadata( 

600 (("project_name", request.project_name),) 

601 ), 

602 ) 

603 

604 # Validate the universe domain. 

605 self._client._validate_universe_domain() 

606 

607 # Send the request. 

608 response = await rpc( 

609 request, 

610 retry=retry, 

611 timeout=timeout, 

612 metadata=metadata, 

613 ) 

614 

615 # This method is paged; wrap the response in a pager, which provides 

616 # an `__aiter__` convenience method. 

617 response = pagers.ListEventsAsyncPager( 

618 method=rpc, 

619 request=request, 

620 response=response, 

621 retry=retry, 

622 timeout=timeout, 

623 metadata=metadata, 

624 ) 

625 

626 # Done; return the response. 

627 return response 

628 

629 async def delete_events( 

630 self, 

631 request: Optional[Union[error_stats_service.DeleteEventsRequest, dict]] = None, 

632 *, 

633 project_name: Optional[str] = None, 

634 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

635 timeout: Union[float, object] = gapic_v1.method.DEFAULT, 

636 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (), 

637 ) -> error_stats_service.DeleteEventsResponse: 

638 r"""Deletes all error events of a given project. 

639 

640 .. code-block:: python 

641 

642 # This snippet has been automatically generated and should be regarded as a 

643 # code template only. 

644 # It will require modifications to work: 

645 # - It may require correct/in-range values for request initialization. 

646 # - It may require specifying regional endpoints when creating the service 

647 # client as shown in: 

648 # https://googleapis.dev/python/google-api-core/latest/client_options.html 

649 from google.cloud import errorreporting_v1beta1 

650 

651 async def sample_delete_events(): 

652 # Create a client 

653 client = errorreporting_v1beta1.ErrorStatsServiceAsyncClient() 

654 

655 # Initialize request argument(s) 

656 request = errorreporting_v1beta1.DeleteEventsRequest( 

657 project_name="project_name_value", 

658 ) 

659 

660 # Make the request 

661 response = await client.delete_events(request=request) 

662 

663 # Handle the response 

664 print(response) 

665 

666 Args: 

667 request (Optional[Union[google.cloud.errorreporting_v1beta1.types.DeleteEventsRequest, dict]]): 

668 The request object. Deletes all events in the project. 

669 project_name (:class:`str`): 

670 Required. The resource name of the Google Cloud Platform 

671 project. Written as ``projects/{projectID}`` or 

672 ``projects/{projectID}/locations/{location}``, where 

673 ``{projectID}`` is the `Google Cloud Platform project 

674 ID <https://support.google.com/cloud/answer/6158840>`__ 

675 and ``{location}`` is a Cloud region. 

676 

677 Examples: ``projects/my-project-123``, 

678 ``projects/my-project-123/locations/global``. 

679 

680 For a list of supported locations, see `Supported 

681 Regions <https://cloud.google.com/logging/docs/region-support>`__. 

682 ``global`` is the default when unspecified. 

683 

684 This corresponds to the ``project_name`` field 

685 on the ``request`` instance; if ``request`` is provided, this 

686 should not be set. 

687 retry (google.api_core.retry_async.AsyncRetry): Designation of what errors, if any, 

688 should be retried. 

689 timeout (float): The timeout for this request. 

690 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be 

691 sent along with the request as metadata. Normally, each value must be of type `str`, 

692 but for metadata keys ending with the suffix `-bin`, the corresponding values must 

693 be of type `bytes`. 

694 

695 Returns: 

696 google.cloud.errorreporting_v1beta1.types.DeleteEventsResponse: 

697 Response message for deleting error 

698 events. 

699 

700 """ 

701 # Create or coerce a protobuf request object. 

702 # - Quick check: If we got a request object, we should *not* have 

703 # gotten any keyword arguments that map to the request. 

704 flattened_params = [project_name] 

705 has_flattened_params = ( 

706 len([param for param in flattened_params if param is not None]) > 0 

707 ) 

708 if request is not None and has_flattened_params: 

709 raise ValueError( 

710 "If the `request` argument is set, then none of " 

711 "the individual field arguments should be set." 

712 ) 

713 

714 # - Use the request object if provided (there's no risk of modifying the input as 

715 # there are no flattened fields), or create one. 

716 if not isinstance(request, error_stats_service.DeleteEventsRequest): 

717 request = error_stats_service.DeleteEventsRequest(request) 

718 

719 # If we have keyword arguments corresponding to fields on the 

720 # request, apply these. 

721 if project_name is not None: 

722 request.project_name = project_name 

723 

724 # Wrap the RPC method; this adds retry and timeout information, 

725 # and friendly error handling. 

726 rpc = self._client._transport._wrapped_methods[ 

727 self._client._transport.delete_events 

728 ] 

729 

730 # Certain fields should be provided within the metadata header; 

731 # add these here. 

732 metadata = tuple(metadata) + ( 

733 gapic_v1.routing_header.to_grpc_metadata( 

734 (("project_name", request.project_name),) 

735 ), 

736 ) 

737 

738 # Validate the universe domain. 

739 self._client._validate_universe_domain() 

740 

741 # Send the request. 

742 response = await rpc( 

743 request, 

744 retry=retry, 

745 timeout=timeout, 

746 metadata=metadata, 

747 ) 

748 

749 # Done; return the response. 

750 return response 

751 

752 async def __aenter__(self) -> "ErrorStatsServiceAsyncClient": 

753 return self 

754 

755 async def __aexit__(self, exc_type, exc, tb): 

756 await self.transport.close() 

757 

758 

759DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

760 gapic_version=package_version.__version__ 

761) 

762 

763if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER 

764 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__ 

765 

766 

767__all__ = ("ErrorStatsServiceAsyncClient",)