Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/errorreporting_v1beta1/services/error_stats_service/client.py: 42%

194 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-08 06:45 +0000

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

2# Copyright 2023 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# 

16from collections import OrderedDict 

17import os 

18import re 

19from typing import ( 

20 Dict, 

21 Mapping, 

22 MutableMapping, 

23 MutableSequence, 

24 Optional, 

25 Sequence, 

26 Tuple, 

27 Type, 

28 Union, 

29 cast, 

30) 

31 

32from google.cloud.errorreporting_v1beta1 import gapic_version as package_version 

33 

34from google.api_core import client_options as client_options_lib 

35from google.api_core import exceptions as core_exceptions 

36from google.api_core import gapic_v1 

37from google.api_core import retry as retries 

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

39from google.auth.transport import mtls # type: ignore 

40from google.auth.transport.grpc import SslCredentials # type: ignore 

41from google.auth.exceptions import MutualTLSChannelError # type: ignore 

42from google.oauth2 import service_account # type: ignore 

43 

44try: 

45 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault] 

46except AttributeError: # pragma: NO COVER 

47 OptionalRetry = Union[retries.Retry, object] # type: ignore 

48 

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

50from google.cloud.errorreporting_v1beta1.types import common 

51from google.cloud.errorreporting_v1beta1.types import error_stats_service 

52from .transports.base import ErrorStatsServiceTransport, DEFAULT_CLIENT_INFO 

53from .transports.grpc import ErrorStatsServiceGrpcTransport 

54from .transports.grpc_asyncio import ErrorStatsServiceGrpcAsyncIOTransport 

55from .transports.rest import ErrorStatsServiceRestTransport 

56 

57 

58class ErrorStatsServiceClientMeta(type): 

59 """Metaclass for the ErrorStatsService client. 

60 

61 This provides class-level methods for building and retrieving 

62 support objects (e.g. transport) without polluting the client instance 

63 objects. 

64 """ 

65 

66 _transport_registry = ( 

67 OrderedDict() 

68 ) # type: Dict[str, Type[ErrorStatsServiceTransport]] 

69 _transport_registry["grpc"] = ErrorStatsServiceGrpcTransport 

70 _transport_registry["grpc_asyncio"] = ErrorStatsServiceGrpcAsyncIOTransport 

71 _transport_registry["rest"] = ErrorStatsServiceRestTransport 

72 

73 def get_transport_class( 

74 cls, 

75 label: Optional[str] = None, 

76 ) -> Type[ErrorStatsServiceTransport]: 

77 """Returns an appropriate transport class. 

78 

79 Args: 

80 label: The name of the desired transport. If none is 

81 provided, then the first transport in the registry is used. 

82 

83 Returns: 

84 The transport class to use. 

85 """ 

86 # If a specific transport is requested, return that one. 

87 if label: 

88 return cls._transport_registry[label] 

89 

90 # No transport is requested; return the default (that is, the first one 

91 # in the dictionary). 

92 return next(iter(cls._transport_registry.values())) 

93 

94 

95class ErrorStatsServiceClient(metaclass=ErrorStatsServiceClientMeta): 

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

97 as data for individual events. 

98 """ 

99 

100 @staticmethod 

101 def _get_default_mtls_endpoint(api_endpoint): 

102 """Converts api endpoint to mTLS endpoint. 

103 

104 Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to 

105 "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. 

106 Args: 

107 api_endpoint (Optional[str]): the api endpoint to convert. 

108 Returns: 

109 str: converted mTLS api endpoint. 

110 """ 

111 if not api_endpoint: 

112 return api_endpoint 

113 

114 mtls_endpoint_re = re.compile( 

115 r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?" 

116 ) 

117 

118 m = mtls_endpoint_re.match(api_endpoint) 

119 name, mtls, sandbox, googledomain = m.groups() 

120 if mtls or not googledomain: 

121 return api_endpoint 

122 

123 if sandbox: 

124 return api_endpoint.replace( 

125 "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" 

126 ) 

127 

128 return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") 

129 

130 DEFAULT_ENDPOINT = "clouderrorreporting.googleapis.com" 

131 DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore 

132 DEFAULT_ENDPOINT 

133 ) 

134 

135 @classmethod 

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

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

138 info. 

139 

140 Args: 

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

142 args: Additional arguments to pass to the constructor. 

143 kwargs: Additional arguments to pass to the constructor. 

144 

145 Returns: 

146 ErrorStatsServiceClient: The constructed client. 

147 """ 

148 credentials = service_account.Credentials.from_service_account_info(info) 

149 kwargs["credentials"] = credentials 

150 return cls(*args, **kwargs) 

151 

152 @classmethod 

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

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

155 file. 

156 

157 Args: 

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

159 file. 

160 args: Additional arguments to pass to the constructor. 

161 kwargs: Additional arguments to pass to the constructor. 

162 

163 Returns: 

164 ErrorStatsServiceClient: The constructed client. 

165 """ 

166 credentials = service_account.Credentials.from_service_account_file(filename) 

167 kwargs["credentials"] = credentials 

168 return cls(*args, **kwargs) 

169 

170 from_service_account_json = from_service_account_file 

171 

172 @property 

173 def transport(self) -> ErrorStatsServiceTransport: 

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

175 

176 Returns: 

177 ErrorStatsServiceTransport: The transport used by the client 

178 instance. 

179 """ 

180 return self._transport 

181 

182 @staticmethod 

183 def error_group_path( 

184 project: str, 

185 group: str, 

186 ) -> str: 

187 """Returns a fully-qualified error_group string.""" 

188 return "projects/{project}/groups/{group}".format( 

189 project=project, 

190 group=group, 

191 ) 

192 

193 @staticmethod 

194 def parse_error_group_path(path: str) -> Dict[str, str]: 

195 """Parses a error_group path into its component segments.""" 

196 m = re.match(r"^projects/(?P<project>.+?)/groups/(?P<group>.+?)$", path) 

197 return m.groupdict() if m else {} 

198 

199 @staticmethod 

200 def common_billing_account_path( 

201 billing_account: str, 

202 ) -> str: 

203 """Returns a fully-qualified billing_account string.""" 

204 return "billingAccounts/{billing_account}".format( 

205 billing_account=billing_account, 

206 ) 

207 

208 @staticmethod 

209 def parse_common_billing_account_path(path: str) -> Dict[str, str]: 

210 """Parse a billing_account path into its component segments.""" 

211 m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path) 

212 return m.groupdict() if m else {} 

213 

214 @staticmethod 

215 def common_folder_path( 

216 folder: str, 

217 ) -> str: 

218 """Returns a fully-qualified folder string.""" 

219 return "folders/{folder}".format( 

220 folder=folder, 

221 ) 

222 

223 @staticmethod 

224 def parse_common_folder_path(path: str) -> Dict[str, str]: 

225 """Parse a folder path into its component segments.""" 

226 m = re.match(r"^folders/(?P<folder>.+?)$", path) 

227 return m.groupdict() if m else {} 

228 

229 @staticmethod 

230 def common_organization_path( 

231 organization: str, 

232 ) -> str: 

233 """Returns a fully-qualified organization string.""" 

234 return "organizations/{organization}".format( 

235 organization=organization, 

236 ) 

237 

238 @staticmethod 

239 def parse_common_organization_path(path: str) -> Dict[str, str]: 

240 """Parse a organization path into its component segments.""" 

241 m = re.match(r"^organizations/(?P<organization>.+?)$", path) 

242 return m.groupdict() if m else {} 

243 

244 @staticmethod 

245 def common_project_path( 

246 project: str, 

247 ) -> str: 

248 """Returns a fully-qualified project string.""" 

249 return "projects/{project}".format( 

250 project=project, 

251 ) 

252 

253 @staticmethod 

254 def parse_common_project_path(path: str) -> Dict[str, str]: 

255 """Parse a project path into its component segments.""" 

256 m = re.match(r"^projects/(?P<project>.+?)$", path) 

257 return m.groupdict() if m else {} 

258 

259 @staticmethod 

260 def common_location_path( 

261 project: str, 

262 location: str, 

263 ) -> str: 

264 """Returns a fully-qualified location string.""" 

265 return "projects/{project}/locations/{location}".format( 

266 project=project, 

267 location=location, 

268 ) 

269 

270 @staticmethod 

271 def parse_common_location_path(path: str) -> Dict[str, str]: 

272 """Parse a location path into its component segments.""" 

273 m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path) 

274 return m.groupdict() if m else {} 

275 

276 @classmethod 

277 def get_mtls_endpoint_and_cert_source( 

278 cls, client_options: Optional[client_options_lib.ClientOptions] = None 

279 ): 

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

281 

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

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

284 client cert source is None. 

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

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

287 source is None. 

288 

289 The API endpoint is determined in the following order: 

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

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

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

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

294 use the default API endpoint. 

295 

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

297 

298 Args: 

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

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

301 in this method. 

302 

303 Returns: 

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

305 client cert source to use. 

306 

307 Raises: 

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

309 """ 

310 if client_options is None: 

311 client_options = client_options_lib.ClientOptions() 

312 use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") 

313 use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") 

314 if use_client_cert not in ("true", "false"): 

315 raise ValueError( 

316 "Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`" 

317 ) 

318 if use_mtls_endpoint not in ("auto", "never", "always"): 

319 raise MutualTLSChannelError( 

320 "Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`" 

321 ) 

322 

323 # Figure out the client cert source to use. 

324 client_cert_source = None 

325 if use_client_cert == "true": 

326 if client_options.client_cert_source: 

327 client_cert_source = client_options.client_cert_source 

328 elif mtls.has_default_client_cert_source(): 

329 client_cert_source = mtls.default_client_cert_source() 

330 

331 # Figure out which api endpoint to use. 

332 if client_options.api_endpoint is not None: 

333 api_endpoint = client_options.api_endpoint 

334 elif use_mtls_endpoint == "always" or ( 

335 use_mtls_endpoint == "auto" and client_cert_source 

336 ): 

337 api_endpoint = cls.DEFAULT_MTLS_ENDPOINT 

338 else: 

339 api_endpoint = cls.DEFAULT_ENDPOINT 

340 

341 return api_endpoint, client_cert_source 

342 

343 def __init__( 

344 self, 

345 *, 

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

347 transport: Optional[Union[str, ErrorStatsServiceTransport]] = None, 

348 client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None, 

349 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

350 ) -> None: 

351 """Instantiates the error stats service client. 

352 

353 Args: 

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

355 authorization credentials to attach to requests. These 

356 credentials identify the application to the service; if none 

357 are specified, the client will attempt to ascertain the 

358 credentials from the environment. 

359 transport (Union[str, ErrorStatsServiceTransport]): The 

360 transport to use. If set to None, a transport is chosen 

361 automatically. 

362 client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]): Custom options for the 

363 client. It won't take effect if a ``transport`` instance is provided. 

364 (1) The ``api_endpoint`` property can be used to override the 

365 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 

366 environment variable can also be used to override the endpoint: 

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

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

369 default mTLS endpoint if client certificate is present, this is 

370 the default value). However, the ``api_endpoint`` property takes 

371 precedence if provided. 

372 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

374 to provide client certificate for mutual TLS transport. If 

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

376 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

377 set, no client certificate will be used. 

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

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

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

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

382 your own client library. 

383 

384 Raises: 

385 google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport 

386 creation failed for any reason. 

387 """ 

388 if isinstance(client_options, dict): 

389 client_options = client_options_lib.from_dict(client_options) 

390 if client_options is None: 

391 client_options = client_options_lib.ClientOptions() 

392 client_options = cast(client_options_lib.ClientOptions, client_options) 

393 

394 api_endpoint, client_cert_source_func = self.get_mtls_endpoint_and_cert_source( 

395 client_options 

396 ) 

397 

398 api_key_value = getattr(client_options, "api_key", None) 

399 if api_key_value and credentials: 

400 raise ValueError( 

401 "client_options.api_key and credentials are mutually exclusive" 

402 ) 

403 

404 # Save or instantiate the transport. 

405 # Ordinarily, we provide the transport, but allowing a custom transport 

406 # instance provides an extensibility point for unusual situations. 

407 if isinstance(transport, ErrorStatsServiceTransport): 

408 # transport is a ErrorStatsServiceTransport instance. 

409 if credentials or client_options.credentials_file or api_key_value: 

410 raise ValueError( 

411 "When providing a transport instance, " 

412 "provide its credentials directly." 

413 ) 

414 if client_options.scopes: 

415 raise ValueError( 

416 "When providing a transport instance, provide its scopes " 

417 "directly." 

418 ) 

419 self._transport = transport 

420 else: 

421 import google.auth._default # type: ignore 

422 

423 if api_key_value and hasattr( 

424 google.auth._default, "get_api_key_credentials" 

425 ): 

426 credentials = google.auth._default.get_api_key_credentials( 

427 api_key_value 

428 ) 

429 

430 Transport = type(self).get_transport_class(transport) 

431 self._transport = Transport( 

432 credentials=credentials, 

433 credentials_file=client_options.credentials_file, 

434 host=api_endpoint, 

435 scopes=client_options.scopes, 

436 client_cert_source_for_mtls=client_cert_source_func, 

437 quota_project_id=client_options.quota_project_id, 

438 client_info=client_info, 

439 always_use_jwt_access=True, 

440 api_audience=client_options.api_audience, 

441 ) 

442 

443 def list_group_stats( 

444 self, 

445 request: Optional[ 

446 Union[error_stats_service.ListGroupStatsRequest, dict] 

447 ] = None, 

448 *, 

449 project_name: Optional[str] = None, 

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

451 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

453 metadata: Sequence[Tuple[str, str]] = (), 

454 ) -> pagers.ListGroupStatsPager: 

455 r"""Lists the specified groups. 

456 

457 .. code-block:: python 

458 

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

460 # code template only. 

461 # It will require modifications to work: 

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

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

464 # client as shown in: 

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

466 from google.cloud import errorreporting_v1beta1 

467 

468 def sample_list_group_stats(): 

469 # Create a client 

470 client = errorreporting_v1beta1.ErrorStatsServiceClient() 

471 

472 # Initialize request argument(s) 

473 request = errorreporting_v1beta1.ListGroupStatsRequest( 

474 project_name="project_name_value", 

475 ) 

476 

477 # Make the request 

478 page_result = client.list_group_stats(request=request) 

479 

480 # Handle the response 

481 for response in page_result: 

482 print(response) 

483 

484 Args: 

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

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

487 project_name (str): 

488 Required. The resource name of the Google Cloud Platform 

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

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

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

492 Console <https://support.google.com/cloud/answer/6158840>`__. 

493 

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

495 ``projects/5551234``. 

496 

497 This corresponds to the ``project_name`` field 

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

499 should not be set. 

500 time_range (google.cloud.errorreporting_v1beta1.types.QueryTimeRange): 

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

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

503 time_range_begin in the response will specify the 

504 beginning of this time range. Only ErrorGroupStats with 

505 a non-zero count in the given time range are returned, 

506 unless the request contains an explicit group_id list. 

507 If a group_id list is given, also ErrorGroupStats with 

508 zero occurrences are returned. 

509 

510 This corresponds to the ``time_range`` field 

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

512 should not be set. 

513 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

514 should be retried. 

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

516 metadata (Sequence[Tuple[str, str]]): Strings which should be 

517 sent along with the request as metadata. 

518 

519 Returns: 

520 google.cloud.errorreporting_v1beta1.services.error_stats_service.pagers.ListGroupStatsPager: 

521 Contains a set of requested error 

522 group stats. 

523 Iterating over this object will yield 

524 results and resolve additional pages 

525 automatically. 

526 

527 """ 

528 # Create or coerce a protobuf request object. 

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

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

531 has_flattened_params = any([project_name, time_range]) 

532 if request is not None and has_flattened_params: 

533 raise ValueError( 

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

535 "the individual field arguments should be set." 

536 ) 

537 

538 # Minor optimization to avoid making a copy if the user passes 

539 # in a error_stats_service.ListGroupStatsRequest. 

540 # There's no risk of modifying the input as we've already verified 

541 # there are no flattened fields. 

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

543 request = error_stats_service.ListGroupStatsRequest(request) 

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

545 # request, apply these. 

546 if project_name is not None: 

547 request.project_name = project_name 

548 if time_range is not None: 

549 request.time_range = time_range 

550 

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

552 # and friendly error handling. 

553 rpc = self._transport._wrapped_methods[self._transport.list_group_stats] 

554 

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

556 # add these here. 

557 metadata = tuple(metadata) + ( 

558 gapic_v1.routing_header.to_grpc_metadata( 

559 (("project_name", request.project_name),) 

560 ), 

561 ) 

562 

563 # Send the request. 

564 response = rpc( 

565 request, 

566 retry=retry, 

567 timeout=timeout, 

568 metadata=metadata, 

569 ) 

570 

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

572 # an `__iter__` convenience method. 

573 response = pagers.ListGroupStatsPager( 

574 method=rpc, 

575 request=request, 

576 response=response, 

577 metadata=metadata, 

578 ) 

579 

580 # Done; return the response. 

581 return response 

582 

583 def list_events( 

584 self, 

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

586 *, 

587 project_name: Optional[str] = None, 

588 group_id: Optional[str] = None, 

589 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

591 metadata: Sequence[Tuple[str, str]] = (), 

592 ) -> pagers.ListEventsPager: 

593 r"""Lists the specified events. 

594 

595 .. code-block:: python 

596 

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

598 # code template only. 

599 # It will require modifications to work: 

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

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

602 # client as shown in: 

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

604 from google.cloud import errorreporting_v1beta1 

605 

606 def sample_list_events(): 

607 # Create a client 

608 client = errorreporting_v1beta1.ErrorStatsServiceClient() 

609 

610 # Initialize request argument(s) 

611 request = errorreporting_v1beta1.ListEventsRequest( 

612 project_name="project_name_value", 

613 group_id="group_id_value", 

614 ) 

615 

616 # Make the request 

617 page_result = client.list_events(request=request) 

618 

619 # Handle the response 

620 for response in page_result: 

621 print(response) 

622 

623 Args: 

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

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

626 return. 

627 project_name (str): 

628 Required. The resource name of the Google Cloud Platform 

629 project. Written as ``projects/{projectID}``, where 

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

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

632 

633 Example: ``projects/my-project-123``. 

634 

635 This corresponds to the ``project_name`` field 

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

637 should not be set. 

638 group_id (str): 

639 Required. The group for which events 

640 shall be returned. 

641 

642 This corresponds to the ``group_id`` field 

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

644 should not be set. 

645 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

646 should be retried. 

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

648 metadata (Sequence[Tuple[str, str]]): Strings which should be 

649 sent along with the request as metadata. 

650 

651 Returns: 

652 google.cloud.errorreporting_v1beta1.services.error_stats_service.pagers.ListEventsPager: 

653 Contains a set of requested error 

654 events. 

655 Iterating over this object will yield 

656 results and resolve additional pages 

657 automatically. 

658 

659 """ 

660 # Create or coerce a protobuf request object. 

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

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

663 has_flattened_params = any([project_name, group_id]) 

664 if request is not None and has_flattened_params: 

665 raise ValueError( 

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

667 "the individual field arguments should be set." 

668 ) 

669 

670 # Minor optimization to avoid making a copy if the user passes 

671 # in a error_stats_service.ListEventsRequest. 

672 # There's no risk of modifying the input as we've already verified 

673 # there are no flattened fields. 

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

675 request = error_stats_service.ListEventsRequest(request) 

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

677 # request, apply these. 

678 if project_name is not None: 

679 request.project_name = project_name 

680 if group_id is not None: 

681 request.group_id = group_id 

682 

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

684 # and friendly error handling. 

685 rpc = self._transport._wrapped_methods[self._transport.list_events] 

686 

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

688 # add these here. 

689 metadata = tuple(metadata) + ( 

690 gapic_v1.routing_header.to_grpc_metadata( 

691 (("project_name", request.project_name),) 

692 ), 

693 ) 

694 

695 # Send the request. 

696 response = rpc( 

697 request, 

698 retry=retry, 

699 timeout=timeout, 

700 metadata=metadata, 

701 ) 

702 

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

704 # an `__iter__` convenience method. 

705 response = pagers.ListEventsPager( 

706 method=rpc, 

707 request=request, 

708 response=response, 

709 metadata=metadata, 

710 ) 

711 

712 # Done; return the response. 

713 return response 

714 

715 def delete_events( 

716 self, 

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

718 *, 

719 project_name: Optional[str] = None, 

720 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

722 metadata: Sequence[Tuple[str, str]] = (), 

723 ) -> error_stats_service.DeleteEventsResponse: 

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

725 

726 .. code-block:: python 

727 

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

729 # code template only. 

730 # It will require modifications to work: 

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

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

733 # client as shown in: 

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

735 from google.cloud import errorreporting_v1beta1 

736 

737 def sample_delete_events(): 

738 # Create a client 

739 client = errorreporting_v1beta1.ErrorStatsServiceClient() 

740 

741 # Initialize request argument(s) 

742 request = errorreporting_v1beta1.DeleteEventsRequest( 

743 project_name="project_name_value", 

744 ) 

745 

746 # Make the request 

747 response = client.delete_events(request=request) 

748 

749 # Handle the response 

750 print(response) 

751 

752 Args: 

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

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

755 project_name (str): 

756 Required. The resource name of the Google Cloud Platform 

757 project. Written as ``projects/{projectID}``, where 

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

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

760 

761 Example: ``projects/my-project-123``. 

762 

763 This corresponds to the ``project_name`` field 

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

765 should not be set. 

766 retry (google.api_core.retry.Retry): Designation of what errors, if any, 

767 should be retried. 

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

769 metadata (Sequence[Tuple[str, str]]): Strings which should be 

770 sent along with the request as metadata. 

771 

772 Returns: 

773 google.cloud.errorreporting_v1beta1.types.DeleteEventsResponse: 

774 Response message for deleting error 

775 events. 

776 

777 """ 

778 # Create or coerce a protobuf request object. 

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

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

781 has_flattened_params = any([project_name]) 

782 if request is not None and has_flattened_params: 

783 raise ValueError( 

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

785 "the individual field arguments should be set." 

786 ) 

787 

788 # Minor optimization to avoid making a copy if the user passes 

789 # in a error_stats_service.DeleteEventsRequest. 

790 # There's no risk of modifying the input as we've already verified 

791 # there are no flattened fields. 

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

793 request = error_stats_service.DeleteEventsRequest(request) 

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

795 # request, apply these. 

796 if project_name is not None: 

797 request.project_name = project_name 

798 

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

800 # and friendly error handling. 

801 rpc = self._transport._wrapped_methods[self._transport.delete_events] 

802 

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

804 # add these here. 

805 metadata = tuple(metadata) + ( 

806 gapic_v1.routing_header.to_grpc_metadata( 

807 (("project_name", request.project_name),) 

808 ), 

809 ) 

810 

811 # Send the request. 

812 response = rpc( 

813 request, 

814 retry=retry, 

815 timeout=timeout, 

816 metadata=metadata, 

817 ) 

818 

819 # Done; return the response. 

820 return response 

821 

822 def __enter__(self) -> "ErrorStatsServiceClient": 

823 return self 

824 

825 def __exit__(self, type, value, traceback): 

826 """Releases underlying transport's resources. 

827 

828 .. warning:: 

829 ONLY use as a context manager if the transport is NOT shared 

830 with other clients! Exiting the with block will CLOSE the transport 

831 and may cause errors in other clients! 

832 """ 

833 self.transport.close() 

834 

835 

836DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

837 gapic_version=package_version.__version__ 

838) 

839 

840 

841__all__ = ("ErrorStatsServiceClient",)