def test(self):

        self.assertEqual(self.aesq.query(), self.query_result)

        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        self.mock_es.search.assert_called_with(
            index='logstash-2016.01.01',
            body={
                'filter': trc.get_clause(),
                'size': 0,
                'aggs': {
                    'apis': {
                        'terms': {
                            'field': 'rails.controller#action.raw',
                            'size': 0
                        },
                        'aggs': {
                            'stats': {
                                'extended_stats': {
                                    'field': 'backend_processing_time'
                                }
                            }
                        }
                    }
                }
            }
        )
    def query(self):

        if self._result is not None:
            return self._result

        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        body = {
            'filter': trc.get_clause(),
            'size': 0,
            'aggs': {
                'apis': {
                    'terms': {
                        'field': 'rails.controller#action.raw',
                        'size': 0
                    },
                    'aggs': {
                        'stats': {
                            'extended_stats': {
                                'field': 'backend_processing_time'
                            }
                        }
                    }
                }
            }
        }
        result = self.get_es().search(index=self.get_index_name(), body=body)
        logger.info(result)

        obj = result.get('aggregations', {})
        obj = obj.get('apis', {})
        self._result = obj.get('buckets', [])

        return self._result
    def query(self):

        if self._result is not None:
            return self._result

        es = self.get_es()
        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        rc = RangeClause(
            'backend_status_code',
            min_val=self.status_code_class,
            max_val=self.status_code_class + 100
        )
        body = {
            'filter': {
                'bool': {
                    'filter': [
                        trc.get_clause(),
                        rc.get_clause()
                    ]
                }
            }
        }
        result = es.count(index=self.get_index_name(), body=body)
        logger.info(result)
        self._result = result.get('count', 0)

        return self._result
    def test_call(self):

        self.assertEqual(self.rcq.query(), 1)

        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        self.mock_es.count.assert_called_with(
            index='logstash-2016.01.01',
            body={'filter': trc.get_clause()}
        )
Exemple #5
0
    def test_when_only_end_time(self):

        now = datetime.utcnow()
        trc = TimeRangeClause(end_time=now)
        self.assertEqual(
            trc.get_clause(),
            {'range': {
                'timestamp': {
                    'lt': timegm(now.timetuple()) * 1000
                }
            }})
    def test_when_begin_time_and_end_time(self):

        now = datetime.utcnow()
        one_hour_ago = now - timedelta(hours=1)
        trc = TimeRangeClause(begin_time=one_hour_ago, end_time=now)
        self.assertEqual(
            trc.get_clause(),
            {
                "range": {
                    "timestamp": {"gte": timegm(one_hour_ago.timetuple()) * 1000, "lt": timegm(now.timetuple()) * 1000}
                }
            },
        )
    def query(self):

        if self._result is not None:
            return self._result

        es = self.get_es()
        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        body = {"filter": trc.get_clause(), "aggs": {"avg_resp_time": {"avg": {"field": "backend_processing_time"}}}}
        result = es.search(index=self.get_index_name(), body=body)
        logger.info(result)
        self._result = result["aggregations"]["avg_resp_time"]["value"]

        return self._result
    def query(self):

        if self._result is not None:
            return self._result

        es = self.get_es()
        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        body = {'filter': trc.get_clause()}
        result = es.count(index=self.get_index_name(), body=body)
        logger.info(result)
        self._result = result.get('count', 0)

        return self._result
Exemple #9
0
    def test_when_begin_time_and_end_time(self):

        now = datetime.utcnow()
        one_hour_ago = now - timedelta(hours=1)
        trc = TimeRangeClause(begin_time=one_hour_ago, end_time=now)
        self.assertEqual(
            trc.get_clause(), {
                'range': {
                    'timestamp': {
                        'gte': timegm(one_hour_ago.timetuple()) * 1000,
                        'lt': timegm(now.timetuple()) * 1000
                    }
                }
            })
    def test_call(self):

        self.assertEqual(self.sccq.query(), 1)

        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        rc = RangeClause('backend_status_code', min_val=200, max_val=300)
        self.mock_es.count.assert_called_with(
            index='logstash-2016.01.01',
            body={
                'filter': {
                    'bool': {'filter': [trc.get_clause(), rc.get_clause()]}
                }
            }
        )
    def get_satisfied_request_count(self):

        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        rc = RangeClause(
            'backend_processing_time', max_val=self.apdex_threshold)
        body = {
            'filter': {
                'bool': {
                    'filter': [trc.get_clause(),
                               rc.get_clause()]
                }
            }
        }
        result = self.get_es().count(index=self.get_index_name(), body=body)
        logger.info('satisifed: %s', result)

        return result.get('count', 0)
    def test_call(self):

        self.assertEqual(self.artq.query(), 1.0)

        trc = TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at)
        self.mock_es.search.assert_called_with(
            index='logstash-2016.01.01',
            body = {
                'filter': trc.get_clause(),
                'aggs': {
                    'avg_resp_time': {
                        'avg': {
                            'field': 'backend_processing_time'
                        }
                    }
                }
            }
        )
    def test_when_only_end_time(self):

        now = datetime.utcnow()
        trc = TimeRangeClause(end_time=now)
        self.assertEqual(trc.get_clause(), {"range": {"timestamp": {"lt": timegm(now.timetuple()) * 1000}}})