1# -*- coding: utf-8 -*-
2# Copyright 2025 Google LLC
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import logging
17import json # type: ignore
18
19from google.auth.transport.requests import AuthorizedSession # type: ignore
20from google.auth import credentials as ga_credentials # type: ignore
21from google.api_core import exceptions as core_exceptions
22from google.api_core import retry as retries
23from google.api_core import rest_helpers
24from google.api_core import rest_streaming
25from google.api_core import gapic_v1
26import google.protobuf
27
28from google.protobuf import json_format
29
30from requests import __version__ as requests_version
31import dataclasses
32from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
33import warnings
34
35
36from google.cloud.errorreporting_v1beta1.types import error_stats_service
37
38
39from .rest_base import _BaseErrorStatsServiceRestTransport
40from .base import DEFAULT_CLIENT_INFO as BASE_DEFAULT_CLIENT_INFO
41
42try:
43 OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
44except AttributeError: # pragma: NO COVER
45 OptionalRetry = Union[retries.Retry, object, None] # type: ignore
46
47try:
48 from google.api_core import client_logging # type: ignore
49
50 CLIENT_LOGGING_SUPPORTED = True # pragma: NO COVER
51except ImportError: # pragma: NO COVER
52 CLIENT_LOGGING_SUPPORTED = False
53
54_LOGGER = logging.getLogger(__name__)
55
56DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
57 gapic_version=BASE_DEFAULT_CLIENT_INFO.gapic_version,
58 grpc_version=None,
59 rest_version=f"requests@{requests_version}",
60)
61
62if hasattr(DEFAULT_CLIENT_INFO, "protobuf_runtime_version"): # pragma: NO COVER
63 DEFAULT_CLIENT_INFO.protobuf_runtime_version = google.protobuf.__version__
64
65
66class ErrorStatsServiceRestInterceptor:
67 """Interceptor for ErrorStatsService.
68
69 Interceptors are used to manipulate requests, request metadata, and responses
70 in arbitrary ways.
71 Example use cases include:
72 * Logging
73 * Verifying requests according to service or custom semantics
74 * Stripping extraneous information from responses
75
76 These use cases and more can be enabled by injecting an
77 instance of a custom subclass when constructing the ErrorStatsServiceRestTransport.
78
79 .. code-block:: python
80 class MyCustomErrorStatsServiceInterceptor(ErrorStatsServiceRestInterceptor):
81 def pre_delete_events(self, request, metadata):
82 logging.log(f"Received request: {request}")
83 return request, metadata
84
85 def post_delete_events(self, response):
86 logging.log(f"Received response: {response}")
87 return response
88
89 def pre_list_events(self, request, metadata):
90 logging.log(f"Received request: {request}")
91 return request, metadata
92
93 def post_list_events(self, response):
94 logging.log(f"Received response: {response}")
95 return response
96
97 def pre_list_group_stats(self, request, metadata):
98 logging.log(f"Received request: {request}")
99 return request, metadata
100
101 def post_list_group_stats(self, response):
102 logging.log(f"Received response: {response}")
103 return response
104
105 transport = ErrorStatsServiceRestTransport(interceptor=MyCustomErrorStatsServiceInterceptor())
106 client = ErrorStatsServiceClient(transport=transport)
107
108
109 """
110
111 def pre_delete_events(
112 self,
113 request: error_stats_service.DeleteEventsRequest,
114 metadata: Sequence[Tuple[str, Union[str, bytes]]],
115 ) -> Tuple[
116 error_stats_service.DeleteEventsRequest, Sequence[Tuple[str, Union[str, bytes]]]
117 ]:
118 """Pre-rpc interceptor for delete_events
119
120 Override in a subclass to manipulate the request or metadata
121 before they are sent to the ErrorStatsService server.
122 """
123 return request, metadata
124
125 def post_delete_events(
126 self, response: error_stats_service.DeleteEventsResponse
127 ) -> error_stats_service.DeleteEventsResponse:
128 """Post-rpc interceptor for delete_events
129
130 DEPRECATED. Please use the `post_delete_events_with_metadata`
131 interceptor instead.
132
133 Override in a subclass to read or manipulate the response
134 after it is returned by the ErrorStatsService server but before
135 it is returned to user code. This `post_delete_events` interceptor runs
136 before the `post_delete_events_with_metadata` interceptor.
137 """
138 return response
139
140 def post_delete_events_with_metadata(
141 self,
142 response: error_stats_service.DeleteEventsResponse,
143 metadata: Sequence[Tuple[str, Union[str, bytes]]],
144 ) -> Tuple[
145 error_stats_service.DeleteEventsResponse,
146 Sequence[Tuple[str, Union[str, bytes]]],
147 ]:
148 """Post-rpc interceptor for delete_events
149
150 Override in a subclass to read or manipulate the response or metadata after it
151 is returned by the ErrorStatsService server but before it is returned to user code.
152
153 We recommend only using this `post_delete_events_with_metadata`
154 interceptor in new development instead of the `post_delete_events` interceptor.
155 When both interceptors are used, this `post_delete_events_with_metadata` interceptor runs after the
156 `post_delete_events` interceptor. The (possibly modified) response returned by
157 `post_delete_events` will be passed to
158 `post_delete_events_with_metadata`.
159 """
160 return response, metadata
161
162 def pre_list_events(
163 self,
164 request: error_stats_service.ListEventsRequest,
165 metadata: Sequence[Tuple[str, Union[str, bytes]]],
166 ) -> Tuple[
167 error_stats_service.ListEventsRequest, Sequence[Tuple[str, Union[str, bytes]]]
168 ]:
169 """Pre-rpc interceptor for list_events
170
171 Override in a subclass to manipulate the request or metadata
172 before they are sent to the ErrorStatsService server.
173 """
174 return request, metadata
175
176 def post_list_events(
177 self, response: error_stats_service.ListEventsResponse
178 ) -> error_stats_service.ListEventsResponse:
179 """Post-rpc interceptor for list_events
180
181 DEPRECATED. Please use the `post_list_events_with_metadata`
182 interceptor instead.
183
184 Override in a subclass to read or manipulate the response
185 after it is returned by the ErrorStatsService server but before
186 it is returned to user code. This `post_list_events` interceptor runs
187 before the `post_list_events_with_metadata` interceptor.
188 """
189 return response
190
191 def post_list_events_with_metadata(
192 self,
193 response: error_stats_service.ListEventsResponse,
194 metadata: Sequence[Tuple[str, Union[str, bytes]]],
195 ) -> Tuple[
196 error_stats_service.ListEventsResponse, Sequence[Tuple[str, Union[str, bytes]]]
197 ]:
198 """Post-rpc interceptor for list_events
199
200 Override in a subclass to read or manipulate the response or metadata after it
201 is returned by the ErrorStatsService server but before it is returned to user code.
202
203 We recommend only using this `post_list_events_with_metadata`
204 interceptor in new development instead of the `post_list_events` interceptor.
205 When both interceptors are used, this `post_list_events_with_metadata` interceptor runs after the
206 `post_list_events` interceptor. The (possibly modified) response returned by
207 `post_list_events` will be passed to
208 `post_list_events_with_metadata`.
209 """
210 return response, metadata
211
212 def pre_list_group_stats(
213 self,
214 request: error_stats_service.ListGroupStatsRequest,
215 metadata: Sequence[Tuple[str, Union[str, bytes]]],
216 ) -> Tuple[
217 error_stats_service.ListGroupStatsRequest,
218 Sequence[Tuple[str, Union[str, bytes]]],
219 ]:
220 """Pre-rpc interceptor for list_group_stats
221
222 Override in a subclass to manipulate the request or metadata
223 before they are sent to the ErrorStatsService server.
224 """
225 return request, metadata
226
227 def post_list_group_stats(
228 self, response: error_stats_service.ListGroupStatsResponse
229 ) -> error_stats_service.ListGroupStatsResponse:
230 """Post-rpc interceptor for list_group_stats
231
232 DEPRECATED. Please use the `post_list_group_stats_with_metadata`
233 interceptor instead.
234
235 Override in a subclass to read or manipulate the response
236 after it is returned by the ErrorStatsService server but before
237 it is returned to user code. This `post_list_group_stats` interceptor runs
238 before the `post_list_group_stats_with_metadata` interceptor.
239 """
240 return response
241
242 def post_list_group_stats_with_metadata(
243 self,
244 response: error_stats_service.ListGroupStatsResponse,
245 metadata: Sequence[Tuple[str, Union[str, bytes]]],
246 ) -> Tuple[
247 error_stats_service.ListGroupStatsResponse,
248 Sequence[Tuple[str, Union[str, bytes]]],
249 ]:
250 """Post-rpc interceptor for list_group_stats
251
252 Override in a subclass to read or manipulate the response or metadata after it
253 is returned by the ErrorStatsService server but before it is returned to user code.
254
255 We recommend only using this `post_list_group_stats_with_metadata`
256 interceptor in new development instead of the `post_list_group_stats` interceptor.
257 When both interceptors are used, this `post_list_group_stats_with_metadata` interceptor runs after the
258 `post_list_group_stats` interceptor. The (possibly modified) response returned by
259 `post_list_group_stats` will be passed to
260 `post_list_group_stats_with_metadata`.
261 """
262 return response, metadata
263
264
265@dataclasses.dataclass
266class ErrorStatsServiceRestStub:
267 _session: AuthorizedSession
268 _host: str
269 _interceptor: ErrorStatsServiceRestInterceptor
270
271
272class ErrorStatsServiceRestTransport(_BaseErrorStatsServiceRestTransport):
273 """REST backend synchronous transport for ErrorStatsService.
274
275 An API for retrieving and managing error statistics as well
276 as data for individual events.
277
278 This class defines the same methods as the primary client, so the
279 primary client can load the underlying transport implementation
280 and call it.
281
282 It sends JSON representations of protocol buffers over HTTP/1.1
283 """
284
285 def __init__(
286 self,
287 *,
288 host: str = "clouderrorreporting.googleapis.com",
289 credentials: Optional[ga_credentials.Credentials] = None,
290 credentials_file: Optional[str] = None,
291 scopes: Optional[Sequence[str]] = None,
292 client_cert_source_for_mtls: Optional[Callable[[], Tuple[bytes, bytes]]] = None,
293 quota_project_id: Optional[str] = None,
294 client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
295 always_use_jwt_access: Optional[bool] = False,
296 url_scheme: str = "https",
297 interceptor: Optional[ErrorStatsServiceRestInterceptor] = None,
298 api_audience: Optional[str] = None,
299 ) -> None:
300 """Instantiate the transport.
301
302 Args:
303 host (Optional[str]):
304 The hostname to connect to (default: 'clouderrorreporting.googleapis.com').
305 credentials (Optional[google.auth.credentials.Credentials]): The
306 authorization credentials to attach to requests. These
307 credentials identify the application to the service; if none
308 are specified, the client will attempt to ascertain the
309 credentials from the environment.
310
311 credentials_file (Optional[str]): Deprecated. A file with credentials that can
312 be loaded with :func:`google.auth.load_credentials_from_file`.
313 This argument is ignored if ``channel`` is provided. This argument will be
314 removed in the next major version of this library.
315 scopes (Optional(Sequence[str])): A list of scopes. This argument is
316 ignored if ``channel`` is provided.
317 client_cert_source_for_mtls (Callable[[], Tuple[bytes, bytes]]): Client
318 certificate to configure mutual TLS HTTP channel. It is ignored
319 if ``channel`` is provided.
320 quota_project_id (Optional[str]): An optional project to use for billing
321 and quota.
322 client_info (google.api_core.gapic_v1.client_info.ClientInfo):
323 The client info used to send a user-agent string along with
324 API requests. If ``None``, then default info will be used.
325 Generally, you only need to set this if you are developing
326 your own client library.
327 always_use_jwt_access (Optional[bool]): Whether self signed JWT should
328 be used for service account credentials.
329 url_scheme: the protocol scheme for the API endpoint. Normally
330 "https", but for testing or local servers,
331 "http" can be specified.
332 """
333 # Run the base constructor
334 # TODO(yon-mg): resolve other ctor params i.e. scopes, quota, etc.
335 # TODO: When custom host (api_endpoint) is set, `scopes` must *also* be set on the
336 # credentials object
337 super().__init__(
338 host=host,
339 credentials=credentials,
340 client_info=client_info,
341 always_use_jwt_access=always_use_jwt_access,
342 url_scheme=url_scheme,
343 api_audience=api_audience,
344 )
345 self._session = AuthorizedSession(
346 self._credentials, default_host=self.DEFAULT_HOST
347 )
348 if client_cert_source_for_mtls:
349 self._session.configure_mtls_channel(client_cert_source_for_mtls)
350 self._interceptor = interceptor or ErrorStatsServiceRestInterceptor()
351 self._prep_wrapped_messages(client_info)
352
353 class _DeleteEvents(
354 _BaseErrorStatsServiceRestTransport._BaseDeleteEvents, ErrorStatsServiceRestStub
355 ):
356 def __hash__(self):
357 return hash("ErrorStatsServiceRestTransport.DeleteEvents")
358
359 @staticmethod
360 def _get_response(
361 host,
362 metadata,
363 query_params,
364 session,
365 timeout,
366 transcoded_request,
367 body=None,
368 ):
369 uri = transcoded_request["uri"]
370 method = transcoded_request["method"]
371 headers = dict(metadata)
372 headers["Content-Type"] = "application/json"
373 response = getattr(session, method)(
374 "{host}{uri}".format(host=host, uri=uri),
375 timeout=timeout,
376 headers=headers,
377 params=rest_helpers.flatten_query_params(query_params, strict=True),
378 )
379 return response
380
381 def __call__(
382 self,
383 request: error_stats_service.DeleteEventsRequest,
384 *,
385 retry: OptionalRetry = gapic_v1.method.DEFAULT,
386 timeout: Optional[float] = None,
387 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
388 ) -> error_stats_service.DeleteEventsResponse:
389 r"""Call the delete events method over HTTP.
390
391 Args:
392 request (~.error_stats_service.DeleteEventsRequest):
393 The request object. Deletes all events in the project.
394 retry (google.api_core.retry.Retry): Designation of what errors, if any,
395 should be retried.
396 timeout (float): The timeout for this request.
397 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
398 sent along with the request as metadata. Normally, each value must be of type `str`,
399 but for metadata keys ending with the suffix `-bin`, the corresponding values must
400 be of type `bytes`.
401
402 Returns:
403 ~.error_stats_service.DeleteEventsResponse:
404 Response message for deleting error
405 events.
406
407 """
408
409 http_options = (
410 _BaseErrorStatsServiceRestTransport._BaseDeleteEvents._get_http_options()
411 )
412
413 request, metadata = self._interceptor.pre_delete_events(request, metadata)
414 transcoded_request = _BaseErrorStatsServiceRestTransport._BaseDeleteEvents._get_transcoded_request(
415 http_options, request
416 )
417
418 # Jsonify the query params
419 query_params = _BaseErrorStatsServiceRestTransport._BaseDeleteEvents._get_query_params_json(
420 transcoded_request
421 )
422
423 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
424 logging.DEBUG
425 ): # pragma: NO COVER
426 request_url = "{host}{uri}".format(
427 host=self._host, uri=transcoded_request["uri"]
428 )
429 method = transcoded_request["method"]
430 try:
431 request_payload = type(request).to_json(request)
432 except:
433 request_payload = None
434 http_request = {
435 "payload": request_payload,
436 "requestMethod": method,
437 "requestUrl": request_url,
438 "headers": dict(metadata),
439 }
440 _LOGGER.debug(
441 f"Sending request for google.devtools.clouderrorreporting_v1beta1.ErrorStatsServiceClient.DeleteEvents",
442 extra={
443 "serviceName": "google.devtools.clouderrorreporting.v1beta1.ErrorStatsService",
444 "rpcName": "DeleteEvents",
445 "httpRequest": http_request,
446 "metadata": http_request["headers"],
447 },
448 )
449
450 # Send the request
451 response = ErrorStatsServiceRestTransport._DeleteEvents._get_response(
452 self._host,
453 metadata,
454 query_params,
455 self._session,
456 timeout,
457 transcoded_request,
458 )
459
460 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
461 # subclass.
462 if response.status_code >= 400:
463 raise core_exceptions.from_http_response(response)
464
465 # Return the response
466 resp = error_stats_service.DeleteEventsResponse()
467 pb_resp = error_stats_service.DeleteEventsResponse.pb(resp)
468
469 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
470
471 resp = self._interceptor.post_delete_events(resp)
472 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
473 resp, _ = self._interceptor.post_delete_events_with_metadata(
474 resp, response_metadata
475 )
476 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
477 logging.DEBUG
478 ): # pragma: NO COVER
479 try:
480 response_payload = error_stats_service.DeleteEventsResponse.to_json(
481 response
482 )
483 except:
484 response_payload = None
485 http_response = {
486 "payload": response_payload,
487 "headers": dict(response.headers),
488 "status": response.status_code,
489 }
490 _LOGGER.debug(
491 "Received response for google.devtools.clouderrorreporting_v1beta1.ErrorStatsServiceClient.delete_events",
492 extra={
493 "serviceName": "google.devtools.clouderrorreporting.v1beta1.ErrorStatsService",
494 "rpcName": "DeleteEvents",
495 "metadata": http_response["headers"],
496 "httpResponse": http_response,
497 },
498 )
499 return resp
500
501 class _ListEvents(
502 _BaseErrorStatsServiceRestTransport._BaseListEvents, ErrorStatsServiceRestStub
503 ):
504 def __hash__(self):
505 return hash("ErrorStatsServiceRestTransport.ListEvents")
506
507 @staticmethod
508 def _get_response(
509 host,
510 metadata,
511 query_params,
512 session,
513 timeout,
514 transcoded_request,
515 body=None,
516 ):
517 uri = transcoded_request["uri"]
518 method = transcoded_request["method"]
519 headers = dict(metadata)
520 headers["Content-Type"] = "application/json"
521 response = getattr(session, method)(
522 "{host}{uri}".format(host=host, uri=uri),
523 timeout=timeout,
524 headers=headers,
525 params=rest_helpers.flatten_query_params(query_params, strict=True),
526 )
527 return response
528
529 def __call__(
530 self,
531 request: error_stats_service.ListEventsRequest,
532 *,
533 retry: OptionalRetry = gapic_v1.method.DEFAULT,
534 timeout: Optional[float] = None,
535 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
536 ) -> error_stats_service.ListEventsResponse:
537 r"""Call the list events method over HTTP.
538
539 Args:
540 request (~.error_stats_service.ListEventsRequest):
541 The request object. Specifies a set of error events to
542 return.
543 retry (google.api_core.retry.Retry): Designation of what errors, if any,
544 should be retried.
545 timeout (float): The timeout for this request.
546 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
547 sent along with the request as metadata. Normally, each value must be of type `str`,
548 but for metadata keys ending with the suffix `-bin`, the corresponding values must
549 be of type `bytes`.
550
551 Returns:
552 ~.error_stats_service.ListEventsResponse:
553 Contains a set of requested error
554 events.
555
556 """
557
558 http_options = (
559 _BaseErrorStatsServiceRestTransport._BaseListEvents._get_http_options()
560 )
561
562 request, metadata = self._interceptor.pre_list_events(request, metadata)
563 transcoded_request = _BaseErrorStatsServiceRestTransport._BaseListEvents._get_transcoded_request(
564 http_options, request
565 )
566
567 # Jsonify the query params
568 query_params = _BaseErrorStatsServiceRestTransport._BaseListEvents._get_query_params_json(
569 transcoded_request
570 )
571
572 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
573 logging.DEBUG
574 ): # pragma: NO COVER
575 request_url = "{host}{uri}".format(
576 host=self._host, uri=transcoded_request["uri"]
577 )
578 method = transcoded_request["method"]
579 try:
580 request_payload = type(request).to_json(request)
581 except:
582 request_payload = None
583 http_request = {
584 "payload": request_payload,
585 "requestMethod": method,
586 "requestUrl": request_url,
587 "headers": dict(metadata),
588 }
589 _LOGGER.debug(
590 f"Sending request for google.devtools.clouderrorreporting_v1beta1.ErrorStatsServiceClient.ListEvents",
591 extra={
592 "serviceName": "google.devtools.clouderrorreporting.v1beta1.ErrorStatsService",
593 "rpcName": "ListEvents",
594 "httpRequest": http_request,
595 "metadata": http_request["headers"],
596 },
597 )
598
599 # Send the request
600 response = ErrorStatsServiceRestTransport._ListEvents._get_response(
601 self._host,
602 metadata,
603 query_params,
604 self._session,
605 timeout,
606 transcoded_request,
607 )
608
609 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
610 # subclass.
611 if response.status_code >= 400:
612 raise core_exceptions.from_http_response(response)
613
614 # Return the response
615 resp = error_stats_service.ListEventsResponse()
616 pb_resp = error_stats_service.ListEventsResponse.pb(resp)
617
618 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
619
620 resp = self._interceptor.post_list_events(resp)
621 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
622 resp, _ = self._interceptor.post_list_events_with_metadata(
623 resp, response_metadata
624 )
625 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
626 logging.DEBUG
627 ): # pragma: NO COVER
628 try:
629 response_payload = error_stats_service.ListEventsResponse.to_json(
630 response
631 )
632 except:
633 response_payload = None
634 http_response = {
635 "payload": response_payload,
636 "headers": dict(response.headers),
637 "status": response.status_code,
638 }
639 _LOGGER.debug(
640 "Received response for google.devtools.clouderrorreporting_v1beta1.ErrorStatsServiceClient.list_events",
641 extra={
642 "serviceName": "google.devtools.clouderrorreporting.v1beta1.ErrorStatsService",
643 "rpcName": "ListEvents",
644 "metadata": http_response["headers"],
645 "httpResponse": http_response,
646 },
647 )
648 return resp
649
650 class _ListGroupStats(
651 _BaseErrorStatsServiceRestTransport._BaseListGroupStats,
652 ErrorStatsServiceRestStub,
653 ):
654 def __hash__(self):
655 return hash("ErrorStatsServiceRestTransport.ListGroupStats")
656
657 @staticmethod
658 def _get_response(
659 host,
660 metadata,
661 query_params,
662 session,
663 timeout,
664 transcoded_request,
665 body=None,
666 ):
667 uri = transcoded_request["uri"]
668 method = transcoded_request["method"]
669 headers = dict(metadata)
670 headers["Content-Type"] = "application/json"
671 response = getattr(session, method)(
672 "{host}{uri}".format(host=host, uri=uri),
673 timeout=timeout,
674 headers=headers,
675 params=rest_helpers.flatten_query_params(query_params, strict=True),
676 )
677 return response
678
679 def __call__(
680 self,
681 request: error_stats_service.ListGroupStatsRequest,
682 *,
683 retry: OptionalRetry = gapic_v1.method.DEFAULT,
684 timeout: Optional[float] = None,
685 metadata: Sequence[Tuple[str, Union[str, bytes]]] = (),
686 ) -> error_stats_service.ListGroupStatsResponse:
687 r"""Call the list group stats method over HTTP.
688
689 Args:
690 request (~.error_stats_service.ListGroupStatsRequest):
691 The request object. Specifies a set of ``ErrorGroupStats`` to return.
692 retry (google.api_core.retry.Retry): Designation of what errors, if any,
693 should be retried.
694 timeout (float): The timeout for this request.
695 metadata (Sequence[Tuple[str, Union[str, bytes]]]): Key/value pairs which should be
696 sent along with the request as metadata. Normally, each value must be of type `str`,
697 but for metadata keys ending with the suffix `-bin`, the corresponding values must
698 be of type `bytes`.
699
700 Returns:
701 ~.error_stats_service.ListGroupStatsResponse:
702 Contains a set of requested error
703 group stats.
704
705 """
706
707 http_options = (
708 _BaseErrorStatsServiceRestTransport._BaseListGroupStats._get_http_options()
709 )
710
711 request, metadata = self._interceptor.pre_list_group_stats(
712 request, metadata
713 )
714 transcoded_request = _BaseErrorStatsServiceRestTransport._BaseListGroupStats._get_transcoded_request(
715 http_options, request
716 )
717
718 # Jsonify the query params
719 query_params = _BaseErrorStatsServiceRestTransport._BaseListGroupStats._get_query_params_json(
720 transcoded_request
721 )
722
723 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
724 logging.DEBUG
725 ): # pragma: NO COVER
726 request_url = "{host}{uri}".format(
727 host=self._host, uri=transcoded_request["uri"]
728 )
729 method = transcoded_request["method"]
730 try:
731 request_payload = type(request).to_json(request)
732 except:
733 request_payload = None
734 http_request = {
735 "payload": request_payload,
736 "requestMethod": method,
737 "requestUrl": request_url,
738 "headers": dict(metadata),
739 }
740 _LOGGER.debug(
741 f"Sending request for google.devtools.clouderrorreporting_v1beta1.ErrorStatsServiceClient.ListGroupStats",
742 extra={
743 "serviceName": "google.devtools.clouderrorreporting.v1beta1.ErrorStatsService",
744 "rpcName": "ListGroupStats",
745 "httpRequest": http_request,
746 "metadata": http_request["headers"],
747 },
748 )
749
750 # Send the request
751 response = ErrorStatsServiceRestTransport._ListGroupStats._get_response(
752 self._host,
753 metadata,
754 query_params,
755 self._session,
756 timeout,
757 transcoded_request,
758 )
759
760 # In case of error, raise the appropriate core_exceptions.GoogleAPICallError exception
761 # subclass.
762 if response.status_code >= 400:
763 raise core_exceptions.from_http_response(response)
764
765 # Return the response
766 resp = error_stats_service.ListGroupStatsResponse()
767 pb_resp = error_stats_service.ListGroupStatsResponse.pb(resp)
768
769 json_format.Parse(response.content, pb_resp, ignore_unknown_fields=True)
770
771 resp = self._interceptor.post_list_group_stats(resp)
772 response_metadata = [(k, str(v)) for k, v in response.headers.items()]
773 resp, _ = self._interceptor.post_list_group_stats_with_metadata(
774 resp, response_metadata
775 )
776 if CLIENT_LOGGING_SUPPORTED and _LOGGER.isEnabledFor(
777 logging.DEBUG
778 ): # pragma: NO COVER
779 try:
780 response_payload = (
781 error_stats_service.ListGroupStatsResponse.to_json(response)
782 )
783 except:
784 response_payload = None
785 http_response = {
786 "payload": response_payload,
787 "headers": dict(response.headers),
788 "status": response.status_code,
789 }
790 _LOGGER.debug(
791 "Received response for google.devtools.clouderrorreporting_v1beta1.ErrorStatsServiceClient.list_group_stats",
792 extra={
793 "serviceName": "google.devtools.clouderrorreporting.v1beta1.ErrorStatsService",
794 "rpcName": "ListGroupStats",
795 "metadata": http_response["headers"],
796 "httpResponse": http_response,
797 },
798 )
799 return resp
800
801 @property
802 def delete_events(
803 self,
804 ) -> Callable[
805 [error_stats_service.DeleteEventsRequest],
806 error_stats_service.DeleteEventsResponse,
807 ]:
808 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
809 # In C++ this would require a dynamic_cast
810 return self._DeleteEvents(self._session, self._host, self._interceptor) # type: ignore
811
812 @property
813 def list_events(
814 self,
815 ) -> Callable[
816 [error_stats_service.ListEventsRequest], error_stats_service.ListEventsResponse
817 ]:
818 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
819 # In C++ this would require a dynamic_cast
820 return self._ListEvents(self._session, self._host, self._interceptor) # type: ignore
821
822 @property
823 def list_group_stats(
824 self,
825 ) -> Callable[
826 [error_stats_service.ListGroupStatsRequest],
827 error_stats_service.ListGroupStatsResponse,
828 ]:
829 # The return type is fine, but mypy isn't sophisticated enough to determine what's going on here.
830 # In C++ this would require a dynamic_cast
831 return self._ListGroupStats(self._session, self._host, self._interceptor) # type: ignore
832
833 @property
834 def kind(self) -> str:
835 return "rest"
836
837 def close(self):
838 self._session.close()
839
840
841__all__ = ("ErrorStatsServiceRestTransport",)