def create_log_metric( self, request: logging_metrics.CreateLogMetricRequest = None, *, parent: str = None, metric: logging_metrics.LogMetric = None, retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> logging_metrics.LogMetric: r"""Creates a logs-based metric. Args: request (google.cloud.logging_v2.types.CreateLogMetricRequest): The request object. The parameters to CreateLogMetric. parent (str): Required. The resource name of the project in which to create the metric: :: "projects/[PROJECT_ID]" The new metric must be provided in the request. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. metric (google.cloud.logging_v2.types.LogMetric): Required. The new logs-based metric, which must not have an identifier that already exists. This corresponds to the ``metric`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.logging_v2.types.LogMetric: Describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter in a given time interval. Logs-based metrics can also be used to extract values from logs and create a distribution of the values. The distribution records the statistics of the extracted values along with an optional histogram of the values as specified by the bucket options. """ # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, metric]) if request is not None and has_flattened_params: raise ValueError('If the `request` argument is set, then none of ' 'the individual field arguments should be set.') # Minor optimization to avoid making a copy if the user passes # in a logging_metrics.CreateLogMetricRequest. # There's no risk of modifying the input as we've already verified # there are no flattened fields. if not isinstance(request, logging_metrics.CreateLogMetricRequest): request = logging_metrics.CreateLogMetricRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent if metric is not None: request.metric = metric # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = self._transport._wrapped_methods[ self._transport.create_log_metric] # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("parent", request.parent), )), ) # Send the request. response = rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response
async def create_log_metric( self, request: Union[logging_metrics.CreateLogMetricRequest, dict] = None, *, parent: str = None, metric: logging_metrics.LogMetric = None, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> logging_metrics.LogMetric: r"""Creates a logs-based metric. .. code-block:: python from google.cloud import logging_v2 def sample_create_log_metric(): # Create a client client = logging_v2.MetricsServiceV2Client() # Initialize request argument(s) metric = logging_v2.LogMetric() metric.name = "name_value" metric.filter = "filter_value" request = logging_v2.CreateLogMetricRequest( parent="parent_value", metric=metric, ) # Make the request response = client.create_log_metric(request=request) # Handle the response print(response) Args: request (Union[google.cloud.logging_v2.types.CreateLogMetricRequest, dict]): The request object. The parameters to CreateLogMetric. parent (:class:`str`): Required. The resource name of the project in which to create the metric: :: "projects/[PROJECT_ID]" The new metric must be provided in the request. This corresponds to the ``parent`` field on the ``request`` instance; if ``request`` is provided, this should not be set. metric (:class:`google.cloud.logging_v2.types.LogMetric`): Required. The new logs-based metric, which must not have an identifier that already exists. This corresponds to the ``metric`` field on the ``request`` instance; if ``request`` is provided, this should not be set. retry (google.api_core.retry.Retry): Designation of what errors, if any, should be retried. timeout (float): The timeout for this request. metadata (Sequence[Tuple[str, str]]): Strings which should be sent along with the request as metadata. Returns: google.cloud.logging_v2.types.LogMetric: Describes a logs-based metric. The value of the metric is the number of log entries that match a logs filter in a given time interval. Logs-based metrics can also be used to extract values from logs and create a distribution of the values. The distribution records the statistics of the extracted values along with an optional histogram of the values as specified by the bucket options. """ # Create or coerce a protobuf request object. # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, metric]) if request is not None and has_flattened_params: raise ValueError("If the `request` argument is set, then none of " "the individual field arguments should be set.") request = logging_metrics.CreateLogMetricRequest(request) # If we have keyword arguments corresponding to fields on the # request, apply these. if parent is not None: request.parent = parent if metric is not None: request.metric = metric # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. rpc = gapic_v1.method_async.wrap_method( self._client._transport.create_log_metric, default_timeout=60.0, client_info=DEFAULT_CLIENT_INFO, ) # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata( (("parent", request.parent), )), ) # Send the request. response = await rpc( request, retry=retry, timeout=timeout, metadata=metadata, ) # Done; return the response. return response