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

121 statements  

« prev     ^ index     » next       coverage.py v7.2.2, created at 2023-03-26 07:30 +0000

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

2# Copyright 2022 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 .transports.base import LoggingServiceV2Transport, DEFAULT_CLIENT_INFO 

53from .transports.grpc_asyncio import LoggingServiceV2GrpcAsyncIOTransport 

54from .client import LoggingServiceV2Client 

55 

56 

57class LoggingServiceV2AsyncClient: 

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

59 

60 _client: LoggingServiceV2Client 

61 

62 DEFAULT_ENDPOINT = LoggingServiceV2Client.DEFAULT_ENDPOINT 

63 DEFAULT_MTLS_ENDPOINT = LoggingServiceV2Client.DEFAULT_MTLS_ENDPOINT 

64 

65 log_path = staticmethod(LoggingServiceV2Client.log_path) 

66 parse_log_path = staticmethod(LoggingServiceV2Client.parse_log_path) 

67 common_billing_account_path = staticmethod( 

68 LoggingServiceV2Client.common_billing_account_path 

69 ) 

70 parse_common_billing_account_path = staticmethod( 

71 LoggingServiceV2Client.parse_common_billing_account_path 

72 ) 

73 common_folder_path = staticmethod(LoggingServiceV2Client.common_folder_path) 

74 parse_common_folder_path = staticmethod( 

75 LoggingServiceV2Client.parse_common_folder_path 

76 ) 

77 common_organization_path = staticmethod( 

78 LoggingServiceV2Client.common_organization_path 

79 ) 

80 parse_common_organization_path = staticmethod( 

81 LoggingServiceV2Client.parse_common_organization_path 

82 ) 

83 common_project_path = staticmethod(LoggingServiceV2Client.common_project_path) 

84 parse_common_project_path = staticmethod( 

85 LoggingServiceV2Client.parse_common_project_path 

86 ) 

87 common_location_path = staticmethod(LoggingServiceV2Client.common_location_path) 

88 parse_common_location_path = staticmethod( 

89 LoggingServiceV2Client.parse_common_location_path 

90 ) 

91 

92 @classmethod 

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

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

95 info. 

96 

97 Args: 

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

99 args: Additional arguments to pass to the constructor. 

100 kwargs: Additional arguments to pass to the constructor. 

101 

102 Returns: 

103 LoggingServiceV2AsyncClient: The constructed client. 

104 """ 

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

106 

107 @classmethod 

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

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

110 file. 

111 

112 Args: 

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

114 file. 

115 args: Additional arguments to pass to the constructor. 

116 kwargs: Additional arguments to pass to the constructor. 

117 

118 Returns: 

119 LoggingServiceV2AsyncClient: The constructed client. 

120 """ 

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

122 

123 from_service_account_json = from_service_account_file 

124 

125 @classmethod 

126 def get_mtls_endpoint_and_cert_source( 

127 cls, client_options: Optional[ClientOptions] = None 

128 ): 

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

130 

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

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

133 client cert source is None. 

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

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

136 source is None. 

137 

138 The API endpoint is determined in the following order: 

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

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

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

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

143 use the default API endpoint. 

144 

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

146 

147 Args: 

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

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

150 in this method. 

151 

152 Returns: 

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

154 client cert source to use. 

155 

156 Raises: 

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

158 """ 

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

160 

161 @property 

162 def transport(self) -> LoggingServiceV2Transport: 

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

164 

165 Returns: 

166 LoggingServiceV2Transport: The transport used by the client instance. 

167 """ 

168 return self._client.transport 

169 

170 get_transport_class = functools.partial( 

171 type(LoggingServiceV2Client).get_transport_class, type(LoggingServiceV2Client) 

172 ) 

173 

174 def __init__( 

175 self, 

176 *, 

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

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

179 client_options: Optional[ClientOptions] = None, 

180 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, 

181 ) -> None: 

182 """Instantiates the logging service v2 client. 

183 

184 Args: 

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

186 authorization credentials to attach to requests. These 

187 credentials identify the application to the service; if none 

188 are specified, the client will attempt to ascertain the 

189 credentials from the environment. 

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

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

192 automatically. 

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

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

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

196 default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT 

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

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

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

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

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

202 precedence if provided. 

203 (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable 

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

205 to provide client certificate for mutual TLS transport. If 

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

207 present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not 

208 set, no client certificate will be used. 

209 

210 Raises: 

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

212 creation failed for any reason. 

213 """ 

214 self._client = LoggingServiceV2Client( 

215 credentials=credentials, 

216 transport=transport, 

217 client_options=client_options, 

218 client_info=client_info, 

219 ) 

220 

221 async def delete_log( 

222 self, 

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

224 *, 

225 log_name: Optional[str] = None, 

226 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

229 ) -> None: 

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

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

232 entries written shortly before the delete operation might not be 

233 deleted. Entries received after the delete operation with a 

234 timestamp before the operation will be deleted. 

235 

236 .. code-block:: python 

237 

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

239 # code template only. 

240 # It will require modifications to work: 

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

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

243 # client as shown in: 

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

245 from google.cloud import logging_v2 

246 

247 async def sample_delete_log(): 

248 # Create a client 

249 client = logging_v2.LoggingServiceV2AsyncClient() 

250 

251 # Initialize request argument(s) 

252 request = logging_v2.DeleteLogRequest( 

253 log_name="log_name_value", 

254 ) 

255 

256 # Make the request 

257 await client.delete_log(request=request) 

258 

259 Args: 

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

261 The request object. The parameters to DeleteLog. 

262 log_name (:class:`str`): 

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

264 

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

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

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

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

269 

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

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

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

273 

274 For more information about log names, see 

275 [LogEntry][google.logging.v2.LogEntry]. 

276 

277 This corresponds to the ``log_name`` field 

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

279 should not be set. 

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

281 should be retried. 

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

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

284 sent along with the request as metadata. 

285 """ 

286 # Create or coerce a protobuf request object. 

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

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

289 has_flattened_params = any([log_name]) 

290 if request is not None and has_flattened_params: 

291 raise ValueError( 

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

293 "the individual field arguments should be set." 

294 ) 

295 

296 request = logging.DeleteLogRequest(request) 

297 

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

299 # request, apply these. 

300 if log_name is not None: 

301 request.log_name = log_name 

302 

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

304 # and friendly error handling. 

305 rpc = gapic_v1.method_async.wrap_method( 

306 self._client._transport.delete_log, 

307 default_retry=retries.Retry( 

308 initial=0.1, 

309 maximum=60.0, 

310 multiplier=1.3, 

311 predicate=retries.if_exception_type( 

312 core_exceptions.DeadlineExceeded, 

313 core_exceptions.InternalServerError, 

314 core_exceptions.ServiceUnavailable, 

315 ), 

316 deadline=60.0, 

317 ), 

318 default_timeout=60.0, 

319 client_info=DEFAULT_CLIENT_INFO, 

320 ) 

321 

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

323 # add these here. 

324 metadata = tuple(metadata) + ( 

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

326 ) 

327 

328 # Send the request. 

329 await rpc( 

330 request, 

331 retry=retry, 

332 timeout=timeout, 

333 metadata=metadata, 

334 ) 

335 

336 async def write_log_entries( 

337 self, 

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

339 *, 

340 log_name: Optional[str] = None, 

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

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

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

344 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

347 ) -> logging.WriteLogEntriesResponse: 

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

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

350 used, directly or indirectly, by the Logging agent 

351 (fluentd) and all logging libraries configured to use 

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

353 maximum of 1000 different resources (projects, 

354 organizations, billing accounts or folders) 

355 

356 .. code-block:: python 

357 

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

359 # code template only. 

360 # It will require modifications to work: 

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

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

363 # client as shown in: 

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

365 from google.cloud import logging_v2 

366 

367 async def sample_write_log_entries(): 

368 # Create a client 

369 client = logging_v2.LoggingServiceV2AsyncClient() 

370 

371 # Initialize request argument(s) 

372 entries = logging_v2.LogEntry() 

373 entries.log_name = "log_name_value" 

374 

375 request = logging_v2.WriteLogEntriesRequest( 

376 entries=entries, 

377 ) 

378 

379 # Make the request 

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

381 

382 # Handle the response 

383 print(response) 

384 

385 Args: 

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

387 The request object. The parameters to WriteLogEntries. 

388 log_name (:class:`str`): 

389 Optional. A default log resource name that is assigned 

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

391 value for ``log_name``: 

392 

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

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

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

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

397 

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

399 

400 :: 

401 

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

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

404 

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

406 on each project, organization, billing account, or 

407 folder that is receiving new log entries, whether the 

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

409 log entry. 

410 

411 This corresponds to the ``log_name`` field 

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

413 should not be set. 

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

415 Optional. A default monitored resource object that is 

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

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

418 

419 :: 

420 

421 { "type": "gce_instance", 

422 "labels": { 

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

424 

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

426 

427 This corresponds to the ``resource`` field 

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

429 should not be set. 

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

431 Optional. Default labels that are added to the 

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

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

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

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

436 

437 This corresponds to the ``labels`` field 

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

439 should not be set. 

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

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

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

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

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

445 in this list that do not include values for their 

446 corresponding fields. For more information, see the 

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

448 

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

450 in log entries, then this method supplies the current 

451 time or a unique identifier, respectively. The supplied 

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

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

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

455 See the ``entries.list`` method. 

456 

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

458 retention 

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

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

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

462 log entries can still be `exported with 

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

464 

465 To improve throughput and to avoid exceeding the `quota 

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

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

468 several log entries in this list, rather than calling 

469 this method for each individual log entry. 

470 

471 This corresponds to the ``entries`` field 

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

473 should not be set. 

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

475 should be retried. 

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

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

478 sent along with the request as metadata. 

479 

480 Returns: 

481 google.cloud.logging_v2.types.WriteLogEntriesResponse: 

482 Result returned from WriteLogEntries. 

483 """ 

484 # Create or coerce a protobuf request object. 

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

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

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

488 if request is not None and has_flattened_params: 

489 raise ValueError( 

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

491 "the individual field arguments should be set." 

492 ) 

493 

494 request = logging.WriteLogEntriesRequest(request) 

495 

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

497 # request, apply these. 

498 if log_name is not None: 

499 request.log_name = log_name 

500 if resource is not None: 

501 request.resource = resource 

502 

503 if labels: 

504 request.labels.update(labels) 

505 if entries: 

506 request.entries.extend(entries) 

507 

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

509 # and friendly error handling. 

510 rpc = gapic_v1.method_async.wrap_method( 

511 self._client._transport.write_log_entries, 

512 default_retry=retries.Retry( 

513 initial=0.1, 

514 maximum=60.0, 

515 multiplier=1.3, 

516 predicate=retries.if_exception_type( 

517 core_exceptions.DeadlineExceeded, 

518 core_exceptions.InternalServerError, 

519 core_exceptions.ServiceUnavailable, 

520 ), 

521 deadline=60.0, 

522 ), 

523 default_timeout=60.0, 

524 client_info=DEFAULT_CLIENT_INFO, 

525 ) 

526 

527 # Send the request. 

528 response = await rpc( 

529 request, 

530 retry=retry, 

531 timeout=timeout, 

532 metadata=metadata, 

533 ) 

534 

535 # Done; return the response. 

536 return response 

537 

538 async def list_log_entries( 

539 self, 

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

541 *, 

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

543 filter: Optional[str] = None, 

544 order_by: Optional[str] = None, 

545 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

548 ) -> pagers.ListLogEntriesAsyncPager: 

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

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

551 For ways to export log entries, see `Exporting 

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

553 

554 .. code-block:: python 

555 

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

557 # code template only. 

558 # It will require modifications to work: 

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

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

561 # client as shown in: 

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

563 from google.cloud import logging_v2 

564 

565 async def sample_list_log_entries(): 

566 # Create a client 

567 client = logging_v2.LoggingServiceV2AsyncClient() 

568 

569 # Initialize request argument(s) 

570 request = logging_v2.ListLogEntriesRequest( 

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

572 ) 

573 

574 # Make the request 

575 page_result = client.list_log_entries(request=request) 

576 

577 # Handle the response 

578 async for response in page_result: 

579 print(response) 

580 

581 Args: 

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

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

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

585 Required. Names of one or more parent resources from 

586 which to retrieve log entries: 

587 

588 - ``projects/[PROJECT_ID]`` 

589 - ``organizations/[ORGANIZATION_ID]`` 

590 - ``billingAccounts/[BILLING_ACCOUNT_ID]`` 

591 - ``folders/[FOLDER_ID]`` 

592 

593 May alternatively be one or more views: 

594 

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

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

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

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

599 

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

601 to this list. 

602 

603 This corresponds to the ``resource_names`` field 

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

605 should not be set. 

606 filter (:class:`str`): 

607 Optional. A filter that chooses which log entries to 

608 return. See `Advanced Logs 

609 Queries <https://cloud.google.com/logging/docs/view/advanced-queries>`__. 

610 Only log entries that match the filter are returned. An 

611 empty filter matches all log entries in the resources 

612 listed in ``resource_names``. Referencing a parent 

613 resource that is not listed in ``resource_names`` will 

614 cause the filter to return no results. The maximum 

615 length of the filter is 20000 characters. 

616 

617 This corresponds to the ``filter`` field 

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

619 should not be set. 

620 order_by (:class:`str`): 

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

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

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

624 returns entries in order of increasing values of 

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

626 option returns entries in order of decreasing timestamps 

627 (newest first). Entries with equal timestamps are 

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

629 

630 This corresponds to the ``order_by`` field 

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

632 should not be set. 

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

634 should be retried. 

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

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

637 sent along with the request as metadata. 

638 

639 Returns: 

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

641 Result returned from ListLogEntries. 

642 

643 Iterating over this object will yield results and 

644 resolve additional pages automatically. 

645 

646 """ 

647 # Create or coerce a protobuf request object. 

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

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

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

651 if request is not None and has_flattened_params: 

652 raise ValueError( 

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

654 "the individual field arguments should be set." 

655 ) 

656 

657 request = logging.ListLogEntriesRequest(request) 

658 

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

660 # request, apply these. 

661 if filter is not None: 

662 request.filter = filter 

663 if order_by is not None: 

664 request.order_by = order_by 

665 if resource_names: 

666 request.resource_names.extend(resource_names) 

667 

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

669 # and friendly error handling. 

670 rpc = gapic_v1.method_async.wrap_method( 

671 self._client._transport.list_log_entries, 

672 default_retry=retries.Retry( 

673 initial=0.1, 

674 maximum=60.0, 

675 multiplier=1.3, 

676 predicate=retries.if_exception_type( 

677 core_exceptions.DeadlineExceeded, 

678 core_exceptions.InternalServerError, 

679 core_exceptions.ServiceUnavailable, 

680 ), 

681 deadline=60.0, 

682 ), 

683 default_timeout=60.0, 

684 client_info=DEFAULT_CLIENT_INFO, 

685 ) 

686 

687 # Send the request. 

688 response = await rpc( 

689 request, 

690 retry=retry, 

691 timeout=timeout, 

692 metadata=metadata, 

693 ) 

694 

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

696 # an `__aiter__` convenience method. 

697 response = pagers.ListLogEntriesAsyncPager( 

698 method=rpc, 

699 request=request, 

700 response=response, 

701 metadata=metadata, 

702 ) 

703 

704 # Done; return the response. 

705 return response 

706 

707 async def list_monitored_resource_descriptors( 

708 self, 

709 request: Optional[ 

710 Union[logging.ListMonitoredResourceDescriptorsRequest, dict] 

711 ] = None, 

712 *, 

713 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

716 ) -> pagers.ListMonitoredResourceDescriptorsAsyncPager: 

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

718 used by Logging. 

719 

720 .. code-block:: python 

721 

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

723 # code template only. 

724 # It will require modifications to work: 

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

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

727 # client as shown in: 

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

729 from google.cloud import logging_v2 

730 

731 async def sample_list_monitored_resource_descriptors(): 

732 # Create a client 

733 client = logging_v2.LoggingServiceV2AsyncClient() 

734 

735 # Initialize request argument(s) 

736 request = logging_v2.ListMonitoredResourceDescriptorsRequest( 

737 ) 

738 

739 # Make the request 

740 page_result = client.list_monitored_resource_descriptors(request=request) 

741 

742 # Handle the response 

743 async for response in page_result: 

744 print(response) 

745 

746 Args: 

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

748 The request object. The parameters to 

749 ListMonitoredResourceDescriptors 

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

751 should be retried. 

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

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

754 sent along with the request as metadata. 

755 

756 Returns: 

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

758 Result returned from 

759 ListMonitoredResourceDescriptors. 

760 Iterating over this object will yield 

761 results and resolve additional pages 

762 automatically. 

763 

764 """ 

765 # Create or coerce a protobuf request object. 

766 request = logging.ListMonitoredResourceDescriptorsRequest(request) 

767 

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

769 # and friendly error handling. 

770 rpc = gapic_v1.method_async.wrap_method( 

771 self._client._transport.list_monitored_resource_descriptors, 

772 default_retry=retries.Retry( 

773 initial=0.1, 

774 maximum=60.0, 

775 multiplier=1.3, 

776 predicate=retries.if_exception_type( 

777 core_exceptions.DeadlineExceeded, 

778 core_exceptions.InternalServerError, 

779 core_exceptions.ServiceUnavailable, 

780 ), 

781 deadline=60.0, 

782 ), 

783 default_timeout=60.0, 

784 client_info=DEFAULT_CLIENT_INFO, 

785 ) 

786 

787 # Send the request. 

788 response = await rpc( 

789 request, 

790 retry=retry, 

791 timeout=timeout, 

792 metadata=metadata, 

793 ) 

794 

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

796 # an `__aiter__` convenience method. 

797 response = pagers.ListMonitoredResourceDescriptorsAsyncPager( 

798 method=rpc, 

799 request=request, 

800 response=response, 

801 metadata=metadata, 

802 ) 

803 

804 # Done; return the response. 

805 return response 

806 

807 async def list_logs( 

808 self, 

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

810 *, 

811 parent: Optional[str] = None, 

812 retry: OptionalRetry = gapic_v1.method.DEFAULT, 

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

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

815 ) -> pagers.ListLogsAsyncPager: 

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

817 or billing accounts. Only logs that have entries are 

818 listed. 

819 

820 .. code-block:: python 

821 

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

823 # code template only. 

824 # It will require modifications to work: 

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

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

827 # client as shown in: 

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

829 from google.cloud import logging_v2 

830 

831 async def sample_list_logs(): 

832 # Create a client 

833 client = logging_v2.LoggingServiceV2AsyncClient() 

834 

835 # Initialize request argument(s) 

836 request = logging_v2.ListLogsRequest( 

837 parent="parent_value", 

838 ) 

839 

840 # Make the request 

841 page_result = client.list_logs(request=request) 

842 

843 # Handle the response 

844 async for response in page_result: 

845 print(response) 

846 

847 Args: 

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

849 The request object. The parameters to ListLogs. 

850 parent (:class:`str`): 

851 Required. The resource name that owns the logs: 

852 

853 - ``projects/[PROJECT_ID]`` 

854 - ``organizations/[ORGANIZATION_ID]`` 

855 - ``billingAccounts/[BILLING_ACCOUNT_ID]`` 

856 - ``folders/[FOLDER_ID]`` 

857 

858 This corresponds to the ``parent`` field 

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

860 should not be set. 

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

862 should be retried. 

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

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

865 sent along with the request as metadata. 

866 

867 Returns: 

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

869 Result returned from ListLogs. 

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 __aenter__(self): 

1031 return self 

1032 

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

1034 await self.transport.close() 

1035 

1036 

1037DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( 

1038 gapic_version=package_version.__version__ 

1039) 

1040 

1041 

1042__all__ = ("LoggingServiceV2AsyncClient",)