Beispiel #1
0
    def test_create_time_series(self):
        channel = ChannelStub()
        client = monitoring_v3.MetricServiceClient(channel=channel)

        # Setup Request
        name = client.project_path('[PROJECT]')
        time_series = []

        client.create_time_series(name, time_series)

        assert len(channel.requests) == 1
        expected_request = metric_service_pb2.CreateTimeSeriesRequest(
            name=name, time_series=time_series)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Beispiel #2
0
    def test_create_time_series(self):
        channel = ChannelStub()
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = monitoring_v3.MetricServiceClient()

        # Setup Request
        name = client.project_path("[PROJECT]")
        time_series = []

        client.create_time_series(name, time_series)

        assert len(channel.requests) == 1
        expected_request = metric_service_pb2.CreateTimeSeriesRequest(
            name=name, time_series=time_series)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Beispiel #3
0
    def create_time_series(
        self,
        name,
        time_series,
        retry=google.api_core.gapic_v1.method.DEFAULT,
        timeout=google.api_core.gapic_v1.method.DEFAULT,
        metadata=None,
    ):
        """
        Creates or adds data to one or more time series.
        The response is empty if all time series in the request were written.
        If any time series could not be written, a corresponding failure message is
        included in the error response.

        Example:
            >>> from google.cloud import monitoring_v3
            >>>
            >>> client = monitoring_v3.MetricServiceClient()
            >>>
            >>> name = client.project_path('[PROJECT]')
            >>>
            >>> # TODO: Initialize `time_series`:
            >>> time_series = []
            >>>
            >>> client.create_time_series(name, time_series)

        Args:
            name (str): The project on which to execute the request. The format is
                ``"projects/{project_id_or_number}"``.
            time_series (list[Union[dict, ~google.cloud.monitoring_v3.types.TimeSeries]]): The new data to be added to a list of time series. Adds at most one data
                point to each of several time series. The new data point must be more
                recent than any other point in its time series. Each ``TimeSeries``
                value must fully specify a unique time series by supplying all label
                values for the metric and the monitored resource.

                The maximum number of ``TimeSeries`` objects per ``Create`` request is
                200.

                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.monitoring_v3.types.TimeSeries`
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will
                be retried using a default configuration.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        # Wrap the transport method to add retry and timeout logic.
        if "create_time_series" not in self._inner_api_calls:
            self._inner_api_calls[
                "create_time_series"] = google.api_core.gapic_v1.method.wrap_method(
                    self.transport.create_time_series,
                    default_retry=self._method_configs["CreateTimeSeries"].
                    retry,
                    default_timeout=self._method_configs["CreateTimeSeries"].
                    timeout,
                    client_info=self._client_info,
                )

        request = metric_service_pb2.CreateTimeSeriesRequest(
            name=name,
            time_series=time_series,
        )
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        try:
            routing_header = [("name", name)]
        except AttributeError:
            pass
        else:
            routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
                routing_header)
            metadata.append(routing_metadata)

        self._inner_api_calls["create_time_series"](request,
                                                    retry=retry,
                                                    timeout=timeout,
                                                    metadata=metadata)
    def create_time_series(self,
                           name,
                           time_series,
                           retry=google.api_core.gapic_v1.method.DEFAULT,
                           timeout=google.api_core.gapic_v1.method.DEFAULT,
                           metadata=None):
        """
        Creates or adds data to one or more time series.
        The response is empty if all time series in the request were written.
        If any time series could not be written, a corresponding failure message is
        included in the error response.

        Example:
            >>> from google.cloud import monitoring_v3
            >>>
            >>> client = monitoring_v3.MetricServiceClient()
            >>>
            >>> name = client.project_path('[PROJECT]')
            >>>
            >>> # TODO: Initialize ``time_series``:
            >>> time_series = []
            >>>
            >>> client.create_time_series(name, time_series)

        Args:
            name (str): The project on which to execute the request. The format is
                ``\"projects/{project_id_or_number}\"``.
            time_series (list[Union[dict, ~google.cloud.monitoring_v3.types.TimeSeries]]): The new data to be added to a list of time series.
                Adds at most one data point to each of several time series.  The new data
                point must be more recent than any other point in its time series.  Each
                ``TimeSeries`` value must fully specify a unique time series by supplying
                all label values for the metric and the monitored resource.
                If a dict is provided, it must be of the same form as the protobuf
                message :class:`~google.cloud.monitoring_v3.types.TimeSeries`
            retry (Optional[google.api_core.retry.Retry]):  A retry object used
                to retry requests. If ``None`` is specified, requests will not
                be retried.
            timeout (Optional[float]): The amount of time, in seconds, to wait
                for the request to complete. Note that if ``retry`` is
                specified, the timeout applies to each individual attempt.
            metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
                that is provided to the method.

        Raises:
            google.api_core.exceptions.GoogleAPICallError: If the request
                    failed for any reason.
            google.api_core.exceptions.RetryError: If the request failed due
                    to a retryable error and retry attempts failed.
            ValueError: If the parameters are invalid.
        """
        if metadata is None:
            metadata = []
        metadata = list(metadata)
        request = metric_service_pb2.CreateTimeSeriesRequest(
            name=name,
            time_series=time_series,
        )
        self._create_time_series(request,
                                 retry=retry,
                                 timeout=timeout,
                                 metadata=metadata)