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(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 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()}
        )
示例#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
示例#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()]}
                }
            }
        )
示例#11
0
    def query(self):

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

        field = 'backend_processing_time'
        conditions = [
            TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at),
            ExistClause('rails.controller#action'),
            TermClause('domain_name', 'api.thekono.com'),
            RangeClause(field, 0)
        ]
        body = {
            'query': {
                'bool': {
                    'filter': [c.get_clause() for c in conditions]
                }
            },
            'size': 0,
            'aggs': {
                'avg_resp_time': {
                    'avg': {
                        'field': field
                    }
                }
            }
        }
        result = self.get_es().search(index=self.get_index_name(), body=body)
        logger.info(result)
        self._result = result['aggregations']['avg_resp_time']['value']

        return self._result
    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'
                        }
                    }
                }
            }
        )
示例#14
0
    def query(self):

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

        conds = [
            TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at),
            ExistClause('rails.controller#action'),
            TermClause('domain_name', 'api.thekono.com'),
            RangeClause('backend_processing_time', 0)
        ]
        body = {'query': {'bool': {'filter': [c.get_clause() for c in conds]}}}
        result = self.get_es().count(index=self.get_index_name(), body=body)
        logger.info(result)
        self._result = result.get('count', 0)

        return self._result
示例#15
0
    def get_tolerating_request_count(self):

        conditions = [
            TimeRangeClause(begin_time=self.begin_at, end_time=self.end_at),
            ExistClause('rails.controller#action'),
            TermClause('domain_name', 'api.thekono.com'),
            RangeClause('backend_processing_time',
                        min_val=self.apdex_threshold,
                        max_val=self.apdex_threshold * 4)
        ]
        body = {'query': {'bool': {'filter': []}}}
        body['query']['bool']['filter'] = [c.get_clause() for c in conditions]

        result = self.get_es().count(index=self.get_index_name(), body=body)
        logger.info('tolerating: %s', result)

        return result.get('count', 0)
示例#16
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={
                'query': {
                    'bool': {
                        'filter': [{
                            'range': {
                                'timestamp': {
                                    'gte': 1451606400000,
                                    'lt': 1451692800000
                                }
                            }
                        }, {
                            'exists': {
                                'field': 'rails.controller#action'
                            }
                        }, {
                            'term': {
                                'domain_name': 'api.thekono.com'
                            }
                        }, {
                            'range': {
                                'backend_processing_time': {
                                    'gte': 0
                                }
                            }
                        }]
                    }
                },
                'size': 0,
                '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}}})