Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/logging_v2/services/logging_service_v2/async_client.py: 43%

142 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 functools 

18import re 

19from typing import ( 

20 Dict, 

21 Mapping, 

22 MutableMapping, 

23 MutableSequence, 

24 Optional, 

25 AsyncIterable, 

26 Awaitable, 

27 AsyncIterator, 

28 Sequence, 

29 Tuple, 

30 Type, 

31 Union, 

32) 

33 

34from google.cloud.logging_v2 import gapic_version as package_version 

35 

36from google.api_core.client_options import ClientOptions 

37from google.api_core import exceptions as core_exceptions 

38from google.api_core import gapic_v1 

39from google.api_core import retry as retries 

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

41from google.oauth2 import service_account # type: ignore 

42 

43try: 

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

45except AttributeError: # pragma: NO COVER 

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

47 

48from google.api import monitored_resource_pb2 # type: ignore 

49from google.cloud.logging_v2.services.logging_service_v2 import pagers 

50from google.cloud.logging_v2.types import log_entry 

51from google.cloud.logging_v2.types import logging 

52from google.longrunning import operations_pb2 # type: ignore 

53from .transports.base import LoggingServiceV2Transport, DEFAULT_CLIENT_INFO 

54from .transports.grpc_asyncio import LoggingServiceV2GrpcAsyncIOTransport 

55from .client import LoggingServiceV2Client 

56 

57 

58class LoggingServiceV2AsyncClient: 

59 """Service for ingesting and querying logs.""" 

60 

61 _client: LoggingServiceV2Client 

62 

63 DEFAULT_ENDPOINT = LoggingServiceV2Client.DEFAULT_ENDPOINT 

64 DEFAULT_MTLS_ENDPOINT = LoggingServiceV2Client.DEFAULT_MTLS_ENDPOINT 

65 

66 log_path = staticmethod(LoggingServiceV2Client.log_path) 

67 parse_log_path = staticmethod(LoggingServiceV2Client.parse_log_path) 

68 common_billing_account_path = staticmethod( 

69 LoggingServiceV2Client.common_billing_account_path 

70 ) 

71 parse_common_billing_account_path = staticmethod( 

72 LoggingServiceV2Client.parse_common_billing_account_path 

73 ) 

74 common_folder_path = staticmethod(LoggingServiceV2Client.common_folder_path) 

75 parse_common_folder_path = staticmethod( 

76 LoggingServiceV2Client.parse_common_folder_path 

77 ) 

78 common_organization_path = staticmethod( 

79 LoggingServiceV2Client.common_organization_path 

80 ) 

81 parse_common_organization_path = staticmethod( 

82 LoggingServiceV2Client.parse_common_organization_path 

83 ) 

84 common_project_path = staticmethod(LoggingServiceV2Client.common_project_path) 

85 parse_common_project_path = staticmethod( 

86 LoggingServiceV2Client.parse_common_project_path 

87 ) 

88 common_location_path = staticmethod(LoggingServiceV2Client.common_location_path) 

89 parse_common_location_path = staticmethod( 

90 LoggingServiceV2Client.parse_common_location_path 

91 ) 

92 

93 @classmethod 

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

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

96 info. 

97 

98 Args: 

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

100 args: Additional arguments to pass to the constructor. 

101 kwargs: Additional arguments to pass to the constructor. 

102 

103 Returns: 

104 LoggingServiceV2AsyncClient: The constructed client. 

105 """ 

106 return LoggingServiceV2Client.from_service_account_info.__func__(LoggingServiceV2AsyncClient, info, *args, **kwargs) # type: ignore 

107 

108 @classmethod 

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

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

111 file. 

112 

113 Args: 

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

115 file. 

116 args: Additional arguments to pass to the constructor. 

117 kwargs: Additional arguments to pass to the constructor. 

118 

119 Returns: 

120 LoggingServiceV2AsyncClient: The constructed client. 

121 """ 

122 return LoggingServiceV2Client.from_service_account_file.__func__(LoggingServiceV2AsyncClient, filename, *args, **kwargs) # type: ignore 

123 

124 from_service_account_json = from_service_account_file 

125 

126 @classmethod 

127 def get_mtls_endpoint_and_cert_source( 

128 cls, client_options: Optional[ClientOptions] = None 

129 ): 

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

131 

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

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

134 client cert source is None. 

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

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

137 source is None. 

138 

139 The API endpoint is determined in the following order: 

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

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

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

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

144 use the default API endpoint. 

145 

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

147 

148 Args: 

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

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

151 in this method. 

152 

153 Returns: 

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

155 client cert source to use. 

156 

157 Raises: 

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

159 """ 

160 return LoggingServiceV2Client.get_mtls_endpoint_and_cert_source(client_options) # type: ignore 

161 

162 @property 

163 def transport(self) -> LoggingServiceV2Transport: 

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

165 

166 Returns: 

167 LoggingServiceV2Transport: The transport used by the client instance. 

168 """ 

169 return self._client.transport 

170 

171 get_transport_class = functools.partial( 

172 type(LoggingServiceV2Client).get_transport_class, type(LoggingServiceV2Client) 

173 ) 

174 

175 def __init__( 

176 self, 

177 *, 

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

179 transport: Union[str, LoggingServiceV2Transport] = "grpc_asyncio", 

180 client_options: Optional[ClientOptions] = None, 

181 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

182 ) -> None: 

183 """Instantiates the logging service v2 client. 

184 

185 Args: 

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

187 authorization credentials to attach to requests. These 

188 credentials identify the application to the service; if none 

189 are specified, the client will attempt to ascertain the 

190 credentials from the environment. 

191 transport (Union[str, ~.LoggingServiceV2Transport]): The 

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

193 automatically. 

194 client_options (ClientOptions): Custom options for the client. It 

195 won't take effect if a ``transport`` instance is provided. 

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

197 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 

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

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

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

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

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

203 precedence if provided. 

204 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

206 to provide client certificate for mutual TLS transport. If 

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

208 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

209 set, no client certificate will be used. 

210 

211 Raises: 

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

213 creation failed for any reason. 

214 """ 

215 self._client = LoggingServiceV2Client( 

216 credentials=credentials, 

217 transport=transport, 

218 client_options=client_options, 

219 client_info=client_info, 

220 ) 

221 

222 async def delete_log( 

223 self, 

224 request: Optional[Union[logging.DeleteLogRequest, dict]] = None, 

225 *, 

226 log_name: Optional[str] = None, 

227 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

230 ) -> None: 

231 r"""Deletes all the log entries in a log for the \_Default Log 

232 Bucket. The log reappears if it receives new entries. Log 

233 entries written shortly before the delete operation might not be 

234 deleted. Entries received after the delete operation with a 

235 timestamp before the operation will be deleted. 

236 

237 .. code-block:: python 

238 

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

240 # code template only. 

241 # It will require modifications to work: 

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

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

244 # client as shown in: 

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

246 from google.cloud import logging_v2 

247 

248 async def sample_delete_log(): 

249 # Create a client 

250 client = logging_v2.LoggingServiceV2AsyncClient() 

251 

252 # Initialize request argument(s) 

253 request = logging_v2.DeleteLogRequest( 

254 log_name="log_name_value", 

255 ) 

256 

257 # Make the request 

258 await client.delete_log(request=request) 

259 

260 Args: 

261 request (Optional[Union[google.cloud.logging_v2.types.DeleteLogRequest, dict]]): 

262 The request object. The parameters to DeleteLog. 

263 log_name (:class:`str`): 

264 Required. The resource name of the log to delete: 

265 

266 - ``projects/[PROJECT_ID]/logs/[LOG_ID]`` 

267 - ``organizations/[ORGANIZATION_ID]/logs/[LOG_ID]`` 

268 - ``billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]`` 

269 - ``folders/[FOLDER_ID]/logs/[LOG_ID]`` 

270 

271 ``[LOG_ID]`` must be URL-encoded. For example, 

272 ``"projects/my-project-id/logs/syslog"``, 

273 ``"organizations/123/logs/cloudaudit.googleapis.com%2Factivity"``. 

274 

275 For more information about log names, see 

276 [LogEntry][google.logging.v2.LogEntry]. 

277 

278 This corresponds to the ``log_name`` field 

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

280 should not be set. 

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

282 should be retried. 

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

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

285 sent along with the request as metadata. 

286 """ 

287 # Create or coerce a protobuf request object. 

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

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

290 has_flattened_params = any([log_name]) 

291 if request is not None and has_flattened_params: 

292 raise ValueError( 

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

294 "the individual field arguments should be set." 

295 ) 

296 

297 request = logging.DeleteLogRequest(request) 

298 

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

300 # request, apply these. 

301 if log_name is not None: 

302 request.log_name = log_name 

303 

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

305 # and friendly error handling. 

306 rpc = gapic_v1.method_async.wrap_method( 

307 self._client._transport.delete_log, 

308 default_retry=retries.Retry( 

309 initial=0.1, 

310 maximum=60.0, 

311 multiplier=1.3, 

312 predicate=retries.if_exception_type( 

313 core_exceptions.DeadlineExceeded, 

314 core_exceptions.InternalServerError, 

315 core_exceptions.ServiceUnavailable, 

316 ), 

317 deadline=60.0, 

318 ), 

319 default_timeout=60.0, 

320 client_info=DEFAULT_CLIENT_INFO, 

321 ) 

322 

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

324 # add these here. 

325 metadata = tuple(metadata) + ( 

326 gapic_v1.routing_header.to_grpc_metadata((("log_name", request.log_name),)), 

327 ) 

328 

329 # Send the request. 

330 await rpc( 

331 request, 

332 retry=retry, 

333 timeout=timeout, 

334 metadata=metadata, 

335 ) 

336 

337 async def write_log_entries( 

338 self, 

339 request: Optional[Union[logging.WriteLogEntriesRequest, dict]] = None, 

340 *, 

341 log_name: Optional[str] = None, 

342 resource: Optional[monitored_resource_pb2.MonitoredResource] = None, 

343 labels: Optional[MutableMapping[str, str]] = None, 

344 entries: Optional[MutableSequence[log_entry.LogEntry]] = None, 

345 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

348 ) -> logging.WriteLogEntriesResponse: 

349 r"""Writes log entries to Logging. This API method is the 

350 only way to send log entries to Logging. This method is 

351 used, directly or indirectly, by the Logging agent 

352 (fluentd) and all logging libraries configured to use 

353 Logging. A single request may contain log entries for a 

354 maximum of 1000 different resources (projects, 

355 organizations, billing accounts or folders) 

356 

357 .. code-block:: python 

358 

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

360 # code template only. 

361 # It will require modifications to work: 

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

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

364 # client as shown in: 

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

366 from google.cloud import logging_v2 

367 

368 async def sample_write_log_entries(): 

369 # Create a client 

370 client = logging_v2.LoggingServiceV2AsyncClient() 

371 

372 # Initialize request argument(s) 

373 entries = logging_v2.LogEntry() 

374 entries.log_name = "log_name_value" 

375 

376 request = logging_v2.WriteLogEntriesRequest( 

377 entries=entries, 

378 ) 

379 

380 # Make the request 

381 response = await client.write_log_entries(request=request) 

382 

383 # Handle the response 

384 print(response) 

385 

386 Args: 

387 request (Optional[Union[google.cloud.logging_v2.types.WriteLogEntriesRequest, dict]]): 

388 The request object. The parameters to WriteLogEntries. 

389 log_name (:class:`str`): 

390 Optional. A default log resource name that is assigned 

391 to all log entries in ``entries`` that do not specify a 

392 value for ``log_name``: 

393 

394 - ``projects/[PROJECT_ID]/logs/[LOG_ID]`` 

395 - ``organizations/[ORGANIZATION_ID]/logs/[LOG_ID]`` 

396 - ``billingAccounts/[BILLING_ACCOUNT_ID]/logs/[LOG_ID]`` 

397 - ``folders/[FOLDER_ID]/logs/[LOG_ID]`` 

398 

399 ``[LOG_ID]`` must be URL-encoded. For example: 

400 

401 :: 

402 

403 "projects/my-project-id/logs/syslog" 

404 "organizations/123/logs/cloudaudit.googleapis.com%2Factivity" 

405 

406 The permission ``logging.logEntries.create`` is needed 

407 on each project, organization, billing account, or 

408 folder that is receiving new log entries, whether the 

409 resource is specified in ``logName`` or in an individual 

410 log entry. 

411 

412 This corresponds to the ``log_name`` field 

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

414 should not be set. 

415 resource (:class:`google.api.monitored_resource_pb2.MonitoredResource`): 

416 Optional. A default monitored resource object that is 

417 assigned to all log entries in ``entries`` that do not 

418 specify a value for ``resource``. Example: 

419 

420 :: 

421 

422 { "type": "gce_instance", 

423 "labels": { 

424 "zone": "us-central1-a", "instance_id": "00000000000000000000" }} 

425 

426 See [LogEntry][google.logging.v2.LogEntry]. 

427 

428 This corresponds to the ``resource`` field 

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

430 should not be set. 

431 labels (:class:`MutableMapping[str, str]`): 

432 Optional. Default labels that are added to the 

433 ``labels`` field of all log entries in ``entries``. If a 

434 log entry already has a label with the same key as a 

435 label in this parameter, then the log entry's label is 

436 not changed. See [LogEntry][google.logging.v2.LogEntry]. 

437 

438 This corresponds to the ``labels`` field 

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

440 should not be set. 

441 entries (:class:`MutableSequence[google.cloud.logging_v2.types.LogEntry]`): 

442 Required. The log entries to send to Logging. The order 

443 of log entries in this list does not matter. Values 

444 supplied in this method's ``log_name``, ``resource``, 

445 and ``labels`` fields are copied into those log entries 

446 in this list that do not include values for their 

447 corresponding fields. For more information, see the 

448 [LogEntry][google.logging.v2.LogEntry] type. 

449 

450 If the ``timestamp`` or ``insert_id`` fields are missing 

451 in log entries, then this method supplies the current 

452 time or a unique identifier, respectively. The supplied 

453 values are chosen so that, among the log entries that 

454 did not supply their own values, the entries earlier in 

455 the list will sort before the entries later in the list. 

456 See the ``entries.list`` method. 

457 

458 Log entries with timestamps that are more than the `logs 

459 retention 

460 period <https://cloud.google.com/logging/quotas>`__ in 

461 the past or more than 24 hours in the future will not be 

462 available when calling ``entries.list``. However, those 

463 log entries can still be `exported with 

464 LogSinks <https://cloud.google.com/logging/docs/api/tasks/exporting-logs>`__. 

465 

466 To improve throughput and to avoid exceeding the `quota 

467 limit <https://cloud.google.com/logging/quotas>`__ for 

468 calls to ``entries.write``, you should try to include 

469 several log entries in this list, rather than calling 

470 this method for each individual log entry. 

471 

472 This corresponds to the ``entries`` field 

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

474 should not be set. 

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

476 should be retried. 

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

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

479 sent along with the request as metadata. 

480 

481 Returns: 

482 google.cloud.logging_v2.types.WriteLogEntriesResponse: 

483 Result returned from WriteLogEntries. 

484 """ 

485 # Create or coerce a protobuf request object. 

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

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

488 has_flattened_params = any([log_name, resource, labels, entries]) 

489 if request is not None and has_flattened_params: 

490 raise ValueError( 

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

492 "the individual field arguments should be set." 

493 ) 

494 

495 request = logging.WriteLogEntriesRequest(request) 

496 

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

498 # request, apply these. 

499 if log_name is not None: 

500 request.log_name = log_name 

501 if resource is not None: 

502 request.resource = resource 

503 

504 if labels: 

505 request.labels.update(labels) 

506 if entries: 

507 request.entries.extend(entries) 

508 

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

510 # and friendly error handling. 

511 rpc = gapic_v1.method_async.wrap_method( 

512 self._client._transport.write_log_entries, 

513 default_retry=retries.Retry( 

514 initial=0.1, 

515 maximum=60.0, 

516 multiplier=1.3, 

517 predicate=retries.if_exception_type( 

518 core_exceptions.DeadlineExceeded, 

519 core_exceptions.InternalServerError, 

520 core_exceptions.ServiceUnavailable, 

521 ), 

522 deadline=60.0, 

523 ), 

524 default_timeout=60.0, 

525 client_info=DEFAULT_CLIENT_INFO, 

526 ) 

527 

528 # Send the request. 

529 response = await rpc( 

530 request, 

531 retry=retry, 

532 timeout=timeout, 

533 metadata=metadata, 

534 ) 

535 

536 # Done; return the response. 

537 return response 

538 

539 async def list_log_entries( 

540 self, 

541 request: Optional[Union[logging.ListLogEntriesRequest, dict]] = None, 

542 *, 

543 resource_names: Optional[MutableSequence[str]] = None, 

544 filter: Optional[str] = None, 

545 order_by: Optional[str] = None, 

546 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

549 ) -> pagers.ListLogEntriesAsyncPager: 

550 r"""Lists log entries. Use this method to retrieve log entries that 

551 originated from a project/folder/organization/billing account. 

552 For ways to export log entries, see `Exporting 

553 Logs <https://cloud.google.com/logging/docs/export>`__. 

554 

555 .. code-block:: python 

556 

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

558 # code template only. 

559 # It will require modifications to work: 

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

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

562 # client as shown in: 

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

564 from google.cloud import logging_v2 

565 

566 async def sample_list_log_entries(): 

567 # Create a client 

568 client = logging_v2.LoggingServiceV2AsyncClient() 

569 

570 # Initialize request argument(s) 

571 request = logging_v2.ListLogEntriesRequest( 

572 resource_names=['resource_names_value1', 'resource_names_value2'], 

573 ) 

574 

575 # Make the request 

576 page_result = client.list_log_entries(request=request) 

577 

578 # Handle the response 

579 async for response in page_result: 

580 print(response) 

581 

582 Args: 

583 request (Optional[Union[google.cloud.logging_v2.types.ListLogEntriesRequest, dict]]): 

584 The request object. The parameters to ``ListLogEntries``. 

585 resource_names (:class:`MutableSequence[str]`): 

586 Required. Names of one or more parent resources from 

587 which to retrieve log entries: 

588 

589 - ``projects/[PROJECT_ID]`` 

590 - ``organizations/[ORGANIZATION_ID]`` 

591 - ``billingAccounts/[BILLING_ACCOUNT_ID]`` 

592 - ``folders/[FOLDER_ID]`` 

593 

594 May alternatively be one or more views: 

595 

596 - ``projects/[PROJECT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

597 - ``organizations/[ORGANIZATION_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

598 - ``billingAccounts/[BILLING_ACCOUNT_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

599 - ``folders/[FOLDER_ID]/locations/[LOCATION_ID]/buckets/[BUCKET_ID]/views/[VIEW_ID]`` 

600 

601 Projects listed in the ``project_ids`` field are added 

602 to this list. A maximum of 100 resources may be 

603 specified in a single request. 

604 

605 This corresponds to the ``resource_names`` field 

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

607 should not be set. 

608 filter (:class:`str`): 

609 Optional. Only log entries that match the filter are 

610 returned. An empty filter matches all log entries in the 

611 resources listed in ``resource_names``. Referencing a 

612 parent resource that is not listed in ``resource_names`` 

613 will cause the filter to return no results. The maximum 

614 length of a filter is 20,000 characters. 

615 

616 This corresponds to the ``filter`` field 

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

618 should not be set. 

619 order_by (:class:`str`): 

620 Optional. How the results should be sorted. Presently, 

621 the only permitted values are ``"timestamp asc"`` 

622 (default) and ``"timestamp desc"``. The first option 

623 returns entries in order of increasing values of 

624 ``LogEntry.timestamp`` (oldest first), and the second 

625 option returns entries in order of decreasing timestamps 

626 (newest first). Entries with equal timestamps are 

627 returned in order of their ``insert_id`` values. 

628 

629 This corresponds to the ``order_by`` field 

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

631 should not be set. 

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

633 should be retried. 

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

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

636 sent along with the request as metadata. 

637 

638 Returns: 

639 google.cloud.logging_v2.services.logging_service_v2.pagers.ListLogEntriesAsyncPager: 

640 Result returned from ListLogEntries. 

641 

642 Iterating over this object will yield results and 

643 resolve additional pages automatically. 

644 

645 """ 

646 # Create or coerce a protobuf request object. 

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

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

649 has_flattened_params = any([resource_names, filter, order_by]) 

650 if request is not None and has_flattened_params: 

651 raise ValueError( 

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

653 "the individual field arguments should be set." 

654 ) 

655 

656 request = logging.ListLogEntriesRequest(request) 

657 

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

659 # request, apply these. 

660 if filter is not None: 

661 request.filter = filter 

662 if order_by is not None: 

663 request.order_by = order_by 

664 if resource_names: 

665 request.resource_names.extend(resource_names) 

666 

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

668 # and friendly error handling. 

669 rpc = gapic_v1.method_async.wrap_method( 

670 self._client._transport.list_log_entries, 

671 default_retry=retries.Retry( 

672 initial=0.1, 

673 maximum=60.0, 

674 multiplier=1.3, 

675 predicate=retries.if_exception_type( 

676 core_exceptions.DeadlineExceeded, 

677 core_exceptions.InternalServerError, 

678 core_exceptions.ServiceUnavailable, 

679 ), 

680 deadline=60.0, 

681 ), 

682 default_timeout=60.0, 

683 client_info=DEFAULT_CLIENT_INFO, 

684 ) 

685 

686 # Send the request. 

687 response = await rpc( 

688 request, 

689 retry=retry, 

690 timeout=timeout, 

691 metadata=metadata, 

692 ) 

693 

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

695 # an `__aiter__` convenience method. 

696 response = pagers.ListLogEntriesAsyncPager( 

697 method=rpc, 

698 request=request, 

699 response=response, 

700 metadata=metadata, 

701 ) 

702 

703 # Done; return the response. 

704 return response 

705 

706 async def list_monitored_resource_descriptors( 

707 self, 

708 request: Optional[ 

709 Union[logging.ListMonitoredResourceDescriptorsRequest, dict] 

710 ] = None, 

711 *, 

712 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

715 ) -> pagers.ListMonitoredResourceDescriptorsAsyncPager: 

716 r"""Lists the descriptors for monitored resource types 

717 used by Logging. 

718 

719 .. code-block:: python 

720 

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

722 # code template only. 

723 # It will require modifications to work: 

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

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

726 # client as shown in: 

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

728 from google.cloud import logging_v2 

729 

730 async def sample_list_monitored_resource_descriptors(): 

731 # Create a client 

732 client = logging_v2.LoggingServiceV2AsyncClient() 

733 

734 # Initialize request argument(s) 

735 request = logging_v2.ListMonitoredResourceDescriptorsRequest( 

736 ) 

737 

738 # Make the request 

739 page_result = client.list_monitored_resource_descriptors(request=request) 

740 

741 # Handle the response 

742 async for response in page_result: 

743 print(response) 

744 

745 Args: 

746 request (Optional[Union[google.cloud.logging_v2.types.ListMonitoredResourceDescriptorsRequest, dict]]): 

747 The request object. The parameters to 

748 ListMonitoredResourceDescriptors 

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

750 should be retried. 

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

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

753 sent along with the request as metadata. 

754 

755 Returns: 

756 google.cloud.logging_v2.services.logging_service_v2.pagers.ListMonitoredResourceDescriptorsAsyncPager: 

757 Result returned from 

758 ListMonitoredResourceDescriptors. 

759 Iterating over this object will yield 

760 results and resolve additional pages 

761 automatically. 

762 

763 """ 

764 # Create or coerce a protobuf request object. 

765 request = logging.ListMonitoredResourceDescriptorsRequest(request) 

766 

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

768 # and friendly error handling. 

769 rpc = gapic_v1.method_async.wrap_method( 

770 self._client._transport.list_monitored_resource_descriptors, 

771 default_retry=retries.Retry( 

772 initial=0.1, 

773 maximum=60.0, 

774 multiplier=1.3, 

775 predicate=retries.if_exception_type( 

776 core_exceptions.DeadlineExceeded, 

777 core_exceptions.InternalServerError, 

778 core_exceptions.ServiceUnavailable, 

779 ), 

780 deadline=60.0, 

781 ), 

782 default_timeout=60.0, 

783 client_info=DEFAULT_CLIENT_INFO, 

784 ) 

785 

786 # Send the request. 

787 response = await rpc( 

788 request, 

789 retry=retry, 

790 timeout=timeout, 

791 metadata=metadata, 

792 ) 

793 

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

795 # an `__aiter__` convenience method. 

796 response = pagers.ListMonitoredResourceDescriptorsAsyncPager( 

797 method=rpc, 

798 request=request, 

799 response=response, 

800 metadata=metadata, 

801 ) 

802 

803 # Done; return the response. 

804 return response 

805 

806 async def list_logs( 

807 self, 

808 request: Optional[Union[logging.ListLogsRequest, dict]] = None, 

809 *, 

810 parent: Optional[str] = None, 

811 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

814 ) -> pagers.ListLogsAsyncPager: 

815 r"""Lists the logs in projects, organizations, folders, 

816 or billing accounts. Only logs that have entries are 

817 listed. 

818 

819 .. code-block:: python 

820 

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

822 # code template only. 

823 # It will require modifications to work: 

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

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

826 # client as shown in: 

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

828 from google.cloud import logging_v2 

829 

830 async def sample_list_logs(): 

831 # Create a client 

832 client = logging_v2.LoggingServiceV2AsyncClient() 

833 

834 # Initialize request argument(s) 

835 request = logging_v2.ListLogsRequest( 

836 parent="parent_value", 

837 ) 

838 

839 # Make the request 

840 page_result = client.list_logs(request=request) 

841 

842 # Handle the response 

843 async for response in page_result: 

844 print(response) 

845 

846 Args: 

847 request (Optional[Union[google.cloud.logging_v2.types.ListLogsRequest, dict]]): 

848 The request object. The parameters to ListLogs. 

849 parent (:class:`str`): 

850 Required. The resource name to list logs for: 

851 

852 - ``projects/[PROJECT_ID]`` 

853 - ``organizations/[ORGANIZATION_ID]`` 

854 - ``billingAccounts/[BILLING_ACCOUNT_ID]`` 

855 - ``folders/[FOLDER_ID]`` 

856 

857 This corresponds to the ``parent`` field 

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

859 should not be set. 

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

861 should be retried. 

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

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

864 sent along with the request as metadata. 

865 

866 Returns: 

867 google.cloud.logging_v2.services.logging_service_v2.pagers.ListLogsAsyncPager: 

868 Result returned from ListLogs. 

869 

870 Iterating over this object will yield 

871 results and resolve additional pages 

872 automatically. 

873 

874 """ 

875 # Create or coerce a protobuf request object. 

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

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

878 has_flattened_params = any([parent]) 

879 if request is not None and has_flattened_params: 

880 raise ValueError( 

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

882 "the individual field arguments should be set." 

883 ) 

884 

885 request = logging.ListLogsRequest(request) 

886 

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

888 # request, apply these. 

889 if parent is not None: 

890 request.parent = parent 

891 

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

893 # and friendly error handling. 

894 rpc = gapic_v1.method_async.wrap_method( 

895 self._client._transport.list_logs, 

896 default_retry=retries.Retry( 

897 initial=0.1, 

898 maximum=60.0, 

899 multiplier=1.3, 

900 predicate=retries.if_exception_type( 

901 core_exceptions.DeadlineExceeded, 

902 core_exceptions.InternalServerError, 

903 core_exceptions.ServiceUnavailable, 

904 ), 

905 deadline=60.0, 

906 ), 

907 default_timeout=60.0, 

908 client_info=DEFAULT_CLIENT_INFO, 

909 ) 

910 

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

912 # add these here. 

913 metadata = tuple(metadata) + ( 

914 gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), 

915 ) 

916 

917 # Send the request. 

918 response = await rpc( 

919 request, 

920 retry=retry, 

921 timeout=timeout, 

922 metadata=metadata, 

923 ) 

924 

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

926 # an `__aiter__` convenience method. 

927 response = pagers.ListLogsAsyncPager( 

928 method=rpc, 

929 request=request, 

930 response=response, 

931 metadata=metadata, 

932 ) 

933 

934 # Done; return the response. 

935 return response 

936 

937 def tail_log_entries( 

938 self, 

939 requests: Optional[AsyncIterator[logging.TailLogEntriesRequest]] = None, 

940 *, 

941 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

944 ) -> Awaitable[AsyncIterable[logging.TailLogEntriesResponse]]: 

945 r"""Streaming read of log entries as they are ingested. 

946 Until the stream is terminated, it will continue reading 

947 logs. 

948 

949 .. code-block:: python 

950 

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

952 # code template only. 

953 # It will require modifications to work: 

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

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

956 # client as shown in: 

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

958 from google.cloud import logging_v2 

959 

960 async def sample_tail_log_entries(): 

961 # Create a client 

962 client = logging_v2.LoggingServiceV2AsyncClient() 

963 

964 # Initialize request argument(s) 

965 request = logging_v2.TailLogEntriesRequest( 

966 resource_names=['resource_names_value1', 'resource_names_value2'], 

967 ) 

968 

969 # This method expects an iterator which contains 

970 # 'logging_v2.TailLogEntriesRequest' objects 

971 # Here we create a generator that yields a single `request` for 

972 # demonstrative purposes. 

973 requests = [request] 

974 

975 def request_generator(): 

976 for request in requests: 

977 yield request 

978 

979 # Make the request 

980 stream = await client.tail_log_entries(requests=request_generator()) 

981 

982 # Handle the response 

983 async for response in stream: 

984 print(response) 

985 

986 Args: 

987 requests (AsyncIterator[`google.cloud.logging_v2.types.TailLogEntriesRequest`]): 

988 The request object AsyncIterator. The parameters to ``TailLogEntries``. 

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

990 should be retried. 

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

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

993 sent along with the request as metadata. 

994 

995 Returns: 

996 AsyncIterable[google.cloud.logging_v2.types.TailLogEntriesResponse]: 

997 Result returned from TailLogEntries. 

998 """ 

999 

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

1001 # and friendly error handling. 

1002 rpc = gapic_v1.method_async.wrap_method( 

1003 self._client._transport.tail_log_entries, 

1004 default_retry=retries.Retry( 

1005 initial=0.1, 

1006 maximum=60.0, 

1007 multiplier=1.3, 

1008 predicate=retries.if_exception_type( 

1009 core_exceptions.DeadlineExceeded, 

1010 core_exceptions.InternalServerError, 

1011 core_exceptions.ServiceUnavailable, 

1012 ), 

1013 deadline=3600.0, 

1014 ), 

1015 default_timeout=3600.0, 

1016 client_info=DEFAULT_CLIENT_INFO, 

1017 ) 

1018 

1019 # Send the request. 

1020 response = rpc( 

1021 requests, 

1022 retry=retry, 

1023 timeout=timeout, 

1024 metadata=metadata, 

1025 ) 

1026 

1027 # Done; return the response. 

1028 return response 

1029 

1030 async def list_operations( 

1031 self, 

1032 request: Optional[operations_pb2.ListOperationsRequest] = None, 

1033 *, 

1034 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1037 ) -> operations_pb2.ListOperationsResponse: 

1038 r"""Lists operations that match the specified filter in the request. 

1039 

1040 Args: 

1041 request (:class:`~.operations_pb2.ListOperationsRequest`): 

1042 The request object. Request message for 

1043 `ListOperations` method. 

1044 retry (google.api_core.retry.Retry): Designation of what errors, 

1045 if any, should be retried. 

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

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

1048 sent along with the request as metadata. 

1049 Returns: 

1050 ~.operations_pb2.ListOperationsResponse: 

1051 Response message for ``ListOperations`` method. 

1052 """ 

1053 # Create or coerce a protobuf request object. 

1054 # The request isn't a proto-plus wrapped type, 

1055 # so it must be constructed via keyword expansion. 

1056 if isinstance(request, dict): 

1057 request = operations_pb2.ListOperationsRequest(**request) 

1058 

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

1060 # and friendly error handling. 

1061 rpc = gapic_v1.method.wrap_method( 

1062 self._client._transport.list_operations, 

1063 default_timeout=None, 

1064 client_info=DEFAULT_CLIENT_INFO, 

1065 ) 

1066 

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

1068 # add these here. 

1069 metadata = tuple(metadata) + ( 

1070 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1071 ) 

1072 

1073 # Send the request. 

1074 response = await rpc( 

1075 request, 

1076 retry=retry, 

1077 timeout=timeout, 

1078 metadata=metadata, 

1079 ) 

1080 

1081 # Done; return the response. 

1082 return response 

1083 

1084 async def get_operation( 

1085 self, 

1086 request: Optional[operations_pb2.GetOperationRequest] = None, 

1087 *, 

1088 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1091 ) -> operations_pb2.Operation: 

1092 r"""Gets the latest state of a long-running operation. 

1093 

1094 Args: 

1095 request (:class:`~.operations_pb2.GetOperationRequest`): 

1096 The request object. Request message for 

1097 `GetOperation` method. 

1098 retry (google.api_core.retry.Retry): Designation of what errors, 

1099 if any, should be retried. 

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

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

1102 sent along with the request as metadata. 

1103 Returns: 

1104 ~.operations_pb2.Operation: 

1105 An ``Operation`` object. 

1106 """ 

1107 # Create or coerce a protobuf request object. 

1108 # The request isn't a proto-plus wrapped type, 

1109 # so it must be constructed via keyword expansion. 

1110 if isinstance(request, dict): 

1111 request = operations_pb2.GetOperationRequest(**request) 

1112 

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

1114 # and friendly error handling. 

1115 rpc = gapic_v1.method.wrap_method( 

1116 self._client._transport.get_operation, 

1117 default_timeout=None, 

1118 client_info=DEFAULT_CLIENT_INFO, 

1119 ) 

1120 

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

1122 # add these here. 

1123 metadata = tuple(metadata) + ( 

1124 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1125 ) 

1126 

1127 # Send the request. 

1128 response = await rpc( 

1129 request, 

1130 retry=retry, 

1131 timeout=timeout, 

1132 metadata=metadata, 

1133 ) 

1134 

1135 # Done; return the response. 

1136 return response 

1137 

1138 async def cancel_operation( 

1139 self, 

1140 request: Optional[operations_pb2.CancelOperationRequest] = None, 

1141 *, 

1142 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

1145 ) -> None: 

1146 r"""Starts asynchronous cancellation on a long-running operation. 

1147 

1148 The server makes a best effort to cancel the operation, but success 

1149 is not guaranteed. If the server doesn't support this method, it returns 

1150 `google.rpc.Code.UNIMPLEMENTED`. 

1151 

1152 Args: 

1153 request (:class:`~.operations_pb2.CancelOperationRequest`): 

1154 The request object. Request message for 

1155 `CancelOperation` method. 

1156 retry (google.api_core.retry.Retry): Designation of what errors, 

1157 if any, should be retried. 

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

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

1160 sent along with the request as metadata. 

1161 Returns: 

1162 None 

1163 """ 

1164 # Create or coerce a protobuf request object. 

1165 # The request isn't a proto-plus wrapped type, 

1166 # so it must be constructed via keyword expansion. 

1167 if isinstance(request, dict): 

1168 request = operations_pb2.CancelOperationRequest(**request) 

1169 

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

1171 # and friendly error handling. 

1172 rpc = gapic_v1.method.wrap_method( 

1173 self._client._transport.cancel_operation, 

1174 default_timeout=None, 

1175 client_info=DEFAULT_CLIENT_INFO, 

1176 ) 

1177 

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

1179 # add these here. 

1180 metadata = tuple(metadata) + ( 

1181 gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), 

1182 ) 

1183 

1184 # Send the request. 

1185 await rpc( 

1186 request, 

1187 retry=retry, 

1188 timeout=timeout, 

1189 metadata=metadata, 

1190 ) 

1191 

1192 async def __aenter__(self) -> "LoggingServiceV2AsyncClient": 

1193 return self 

1194 

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

1196 await self.transport.close() 

1197 

1198 

1199DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

1200 gapic_version=package_version.__version__ 

1201) 

1202 

1203 

1204__all__ = ("LoggingServiceV2AsyncClient",)