def test_request_parameters_maximal(self): from google.cloud.monitoring_v3 import MetricServiceClient from google.cloud.monitoring_v3 import types from google.cloud.monitoring_v3.gapic import enums T0 = datetime.datetime(2016, 4, 7, 2, 0, 0) T1 = datetime.datetime(2016, 4, 7, 2, 30, 0) ALIGNER = 'ALIGN_DELTA' MINUTES, SECONDS, PERIOD_IN_SECONDS = 1, 30, 90 REDUCER = 'REDUCE_MEAN' FIELD1, FIELD2 = 'resource.zone', 'metric.instance_name' PAGE_SIZE = 100 channel = ChannelStub() client = MetricServiceClient(channel=channel) query = self._make_one(client, PROJECT, METRIC_TYPE) query = query.select_interval(start_time=T0, end_time=T1) query = query.align(ALIGNER, minutes=MINUTES, seconds=SECONDS) query = query.reduce(REDUCER, FIELD1, FIELD2) actual = query._build_query_params(headers_only=True, page_size=PAGE_SIZE) expected = { 'name': 'projects/%s' % PROJECT, 'filter_': 'metric.type = "{type}"'.format(type=METRIC_TYPE), 'interval': self._make_interval(T1, T0), 'aggregation': types.Aggregation( per_series_aligner=ALIGNER, alignment_period={'seconds': PERIOD_IN_SECONDS}, cross_series_reducer=REDUCER, group_by_fields=[FIELD1, FIELD2], ), 'view': enums.ListTimeSeriesRequest.TimeSeriesView.HEADERS, 'page_size': PAGE_SIZE, } self.assertEqual(actual, expected)
def _build_query_params(self, headers_only=False, page_size=None): """Return key-value pairs for the list_time_series API call. :type headers_only: bool :param headers_only: Whether to omit the point data from the :class:`~google.cloud.monitoring_v3.types.TimeSeries` objects. :type page_size: int :param page_size: (Optional) The maximum number of points in each page of results from this request. Non-positive values are ignored. Defaults to a sensible value set by the API. """ params = {"name": self._project_path, "filter_": self.filter} params["interval"] = types.TimeInterval() params["interval"].end_time.FromDatetime(self._end_time) if self._start_time: params["interval"].start_time.FromDatetime(self._start_time) if ( self._per_series_aligner or self._alignment_period_seconds or self._cross_series_reducer or self._group_by_fields ): params["aggregation"] = types.Aggregation( per_series_aligner=self._per_series_aligner, cross_series_reducer=self._cross_series_reducer, group_by_fields=self._group_by_fields, alignment_period={"seconds": self._alignment_period_seconds}, ) if headers_only: params["view"] = enums.ListTimeSeriesRequest.TimeSeriesView.HEADERS else: params["view"] = enums.ListTimeSeriesRequest.TimeSeriesView.FULL if page_size is not None: params["page_size"] = page_size return params
def _build_query_params(self, headers_only=False, page_size=None): """Return key-value pairs for the list_time_series API call. :type headers_only: bool :param headers_only: Whether to omit the point data from the :class:`~google.cloud.monitoring_v3.types.TimeSeries` objects. :type page_size: int :param page_size: (Optional) A limit on the number of points to return per page. """ params = {'name': self._project_path, 'filter_': self.filter} params['interval'] = types.TimeInterval() params['interval'].end_time.FromDatetime(self._end_time) if self._start_time: params['interval'].start_time.FromDatetime(self._start_time) if (self._per_series_aligner or self._alignment_period_seconds or self._cross_series_reducer or self._group_by_fields): params['aggregation'] = types.Aggregation( per_series_aligner=self._per_series_aligner, cross_series_reducer=self._cross_series_reducer, group_by_fields=self._group_by_fields, alignment_period={'seconds': self._alignment_period_seconds}, ) if headers_only: params['view'] = enums.ListTimeSeriesRequest.TimeSeriesView.HEADERS else: params['view'] = enums.ListTimeSeriesRequest.TimeSeriesView.FULL if page_size is not None: params['page_size'] = page_size return params