Esempio n. 1
0
    def flush_events(self, events):
        """
        Send events to the backend.

        :param events: Events bulk
        :type events: list

        :return: True if flush was successful. False otherwise
        :rtype: bool
        """
        bulk = self._build_bulk(events)
        try:
            response = self._client.post('events',
                                         '/events/bulk',
                                         self._apikey,
                                         body=bulk,
                                         extra_headers=self._metadata)
            if not 200 <= response.status_code < 300:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            _LOGGER.error(
                'Error posting events because an exception was raised by the HTTPClient'
            )
            _LOGGER.debug('Error: ', exc_info=True)
            raise APIException('Events not flushed properly.') from exc
Esempio n. 2
0
    def fetch_segment(self, segment_name, change_number):
        """
        Fetch splits from backend.

        :param segment_name: Name of the segment to fetch changes for.
        :type segment_name: str
        :param change_number: Last known timestamp of a split modification.
        :type change_number: int

        :return: Json representation of a segmentChange response.
        :rtype: dict
        """
        try:
            response = self._client.get(
                'sdk',
                '/segmentChanges/{segment_name}'.format(segment_name=segment_name),
                self._apikey,
                {'since': change_number}
            )

            if 200 <= response.status_code < 300:
                return json.loads(response.body)
            else:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            _LOGGER.error(
                'Error fetching %s because an exception was raised by the HTTPClient',
                segment_name
            )
            _LOGGER.debug('Error: ', exc_info=True)
            raise_from(APIException('Segments not fetched properly.'), exc)
Esempio n. 3
0
    def fetch_splits(self, change_number):
        """
        Fetch splits from backend.

        :param changeNumber: Last known timestamp of a split modification.
        :type changeNumber: int

        :return: Json representation of a splitChanges response.
        :rtype: dict
        """
        try:
            response = self._client.get('sdk',
                                        '/splitChanges',
                                        self._apikey,
                                        extra_headers=self._metadata,
                                        query={'since': change_number})
            if 200 <= response.status_code < 300:
                return json.loads(response.body)
            else:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            _LOGGER.error(
                'Error fetching splits because an exception was raised by the HTTPClient'
            )
            _LOGGER.debug('Error: ', exc_info=True)
            raise_from(APIException('Splits not fetched correctly.'), exc)
Esempio n. 4
0
    def fetch_splits(self, change_number, fetch_options):
        """
        Fetch splits from backend.

        :param change_number: Last known timestamp of a split modification.
        :type change_number: int

        :param fetch_options: Fetch options for getting split definitions.
        :type fetch_options: splitio.api.commons.FetchOptions

        :return: Json representation of a splitChanges response.
        :rtype: dict
        """
        try:
            query, extra_headers = build_fetch(change_number, fetch_options,
                                               self._metadata)
            response = self._client.get(
                'sdk',
                '/splitChanges',
                self._apikey,
                extra_headers=extra_headers,
                query=query,
            )
            if 200 <= response.status_code < 300:
                return json.loads(response.body)
            else:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            _LOGGER.error(
                'Error fetching splits because an exception was raised by the HTTPClient'
            )
            _LOGGER.debug('Error: ', exc_info=True)
            raise APIException('Splits not fetched correctly.') from exc
Esempio n. 5
0
 def run(x):
     run._calls += 1
     if run._calls == 1:
         return {'splits': [], 'since': -1, 'till': -1}
     if run._calls == 2:
         return {'splits': [], 'since': -1, 'till': -1}
     raise APIException("something broke")
Esempio n. 6
0
 def sync_all(self):
     """Synchronize all split data."""
     try:
         self._split_synchronizers.split_sync.synchronize_splits(None)
     except APIException as exc:
         _LOGGER.error('Failed syncing splits')
         raise APIException('Failed to sync splits') from exc
Esempio n. 7
0
 def sync_all(self):
     """Synchronize all split data."""
     try:
         self.synchronize_splits(None)
         if not self._synchronize_segments():
             _LOGGER.error('Failed syncing segments')
             raise RuntimeError('Failed syncing segments')
     except APIException as exc:
         _LOGGER.error('Failed syncing splits')
         raise_from(APIException('Failed to sync splits'), exc)
Esempio n. 8
0
    def flush_impressions(self, impressions):
        """
        Send impressions to the backend.

        :param impressions: Impressions bulk
        :type impressions: list
        """
        bulk = self._build_bulk(impressions)
        try:
            response = self._client.post('events',
                                         '/testImpressions/bulk',
                                         self._apikey,
                                         body=bulk,
                                         extra_headers=self._metadata)
            if not 200 <= response.status_code < 300:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            self._logger.error('Http client is throwing exceptions')
            self._logger.debug('Error: ', exc_info=True)
            raise_from(APIException('Impressions not flushed properly.'), exc)
Esempio n. 9
0
    def authenticate(self):
        """
        Perform authentication.

        :return: Json representation of an authentication.
        :rtype: splitio.models.token.Token
        """
        try:
            response = self._client.get('auth',
                                        '/auth',
                                        self._apikey,
                                        extra_headers=self._metadata)
            if 200 <= response.status_code < 300:
                payload = json.loads(response.body)
                return from_raw(payload)
            else:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            _LOGGER.error('Exception raised while authenticating')
            _LOGGER.debug('Exception information: ', exc_info=True)
            raise_from(APIException('Could not perform authentication.'), exc)
Esempio n. 10
0
    def fetch_splits(self, change_number):
        """
        Fetch splits from backend.

        :param changeNumber: Last known timestamp of a split modification.
        :type changeNumber: int

        :return: Json representation of a splitChanges response.
        :rtype: dict
        """
        try:
            response = self._client.get('sdk', '/splitChanges', self._apikey,
                                        {'since': change_number})
            if 200 <= response.status_code < 300:
                return json.loads(response.body)
            else:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            self._logger.error('Http client is throwing exceptions')
            self._logger.debug('Error: ', exc_info=True)
            raise_from(APIException('Splits not fetched correctly.'), exc)
Esempio n. 11
0
    def flush_gauges(self, gauges):
        """
        Submit gauges to the backend.

        :param gauges: Gauges measured to be sent to the backend.
        :type gauges: List
        """
        bulk = self._build_gauges(gauges)
        try:
            response = self._client.post('events',
                                         '/metrics/gauge',
                                         self._apikey,
                                         body=bulk,
                                         extra_headers=self._metadata)
            if not 200 <= response.status_code < 300:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            _LOGGER.error(
                'Error posting gauges because an exception was raised by the HTTPClient'
            )
            _LOGGER.debug('Error: ', exc_info=True)
            raise_from(APIException('Gauges not flushed correctly.'), exc)
Esempio n. 12
0
    def flush_latencies(self, latencies):
        """
        Submit latencies to the backend.

        :param latencies: List of latency buckets with their respective count.
        :type latencies: list
        """
        bulk = self._build_latencies(latencies)
        try:
            response = self._client.post('events',
                                         '/metrics/times',
                                         self._apikey,
                                         body=bulk,
                                         extra_headers=self._metadata)
            if not 200 <= response.status_code < 300:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            _LOGGER.error(
                'Error posting latencies because an exception was raised by the HTTPClient'
            )
            _LOGGER.debug('Error: ', exc_info=True)
            raise_from(APIException('Latencies not flushed correctly.'), exc)
Esempio n. 13
0
    def flush_impressions(self, impressions):
        """
        Send impressions to the backend.

        :param impressions: Impressions bulk
        :type impressions: list
        """
        bulk = self._build_bulk(impressions)
        try:
            response = self._client.post('events',
                                         '/testImpressions/bulk',
                                         self._apikey,
                                         body=bulk,
                                         extra_headers=self._metadata)
            if not 200 <= response.status_code < 300:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            _LOGGER.error(
                'Error posting impressions because an exception was raised by the HTTPClient'
            )
            _LOGGER.debug('Error: ', exc_info=True)
            raise APIException('Impressions not flushed properly.') from exc
Esempio n. 14
0
    def flush_counters(self, counters):
        """
        Submit counters to the backend.

        :param counters: Counters measured to be sent to the backend.
        :type counters: List
        """
        bulk = self._build_counters(counters)
        try:
            response = self._client.post(
                'events',
                '/metrics/counters',
                self._apikey,
                body=bulk,
                extra_headers=self._metadata
            )
            if not 200 <= response.status_code < 300:
                raise APIException(response.body, response.status_code)
        except HttpClientException as exc:
            self._logger.error('Http client is throwing exceptions')
            self._logger.debug('Error: ', exc_info=True)
            raise_from(APIException('Counters not flushed correctly.'), exc)
Esempio n. 15
0
 def run(x, c):
     raise APIException("something broke")
Esempio n. 16
0
 def handler_sync(change_number):
     raise APIException('some')