コード例 #1
0
    def test_envs_from_api(self, get_mock):
        response_mock = mock.Mock(status_code=200)
        response_mock.json.return_value = {
            "METRICS_BACKEND": "logstash",
            "METRICS_ELASTICSEARCH_HOST": "http://easearch.com",
            "METRICS_LOGSTASH_HOST": "logstash.com",
        }
        get_mock.return_value = response_mock

        app = {"name": "appname"}

        backend = get_backend(app, "token")
        self.assertIsInstance(backend, ElasticSearch)
コード例 #2
0
    def test_envs_from_api(self, get_mock):
        response_mock = Mock(status_code=200)
        response_mock.json.return_value = {
            "METRICS_BACKEND": "logstash",
            "METRICS_ELASTICSEARCH_HOST": "http://easearch.com",
            "METRICS_LOGSTASH_HOST": "logstash.com"
        }
        get_mock.return_value = response_mock

        app = {"name": "appname"}

        backend = get_backend(app, 'token')
        self.assertIsInstance(backend, ElasticSearch)
コード例 #3
0
    def get(self, *args, **kwargs):
        metric = self.request.GET.get("metric")
        if not metric:
            return HttpResponseBadRequest()

        app_name = kwargs['app_name']
        app = self.get_app(app_name)
        app["envs"] = self.get_envs(self.request, app_name)

        from metrics.backend import get_backend
        token = self.request.session.get('tsuru_token')
        backend = get_backend(app, token)

        interval = self.request.GET.get("interval")
        date_range = self.request.GET.get("date_range")
        data = getattr(backend, metric)(date_range=date_range, interval=interval)
        return HttpResponse(json.dumps(data))
コード例 #4
0
ファイル: views.py プロジェクト: ntmedina/tsuru-dashboard
    def get(self, *args, **kwargs):
        metric = self.request.GET.get("metric")
        if not metric:
            return HttpResponseBadRequest()

        process_name = self.request.GET.get("process_name")

        app_name = kwargs['app_name']
        app = self.get_app(app_name)
        app["envs"] = self.get_envs(self.request, app_name)

        from metrics.backend import get_backend
        token = self.request.session.get('tsuru_token')
        backend = get_backend(app, token)

        interval = self.request.GET.get("interval")
        date_range = self.request.GET.get("date_range")
        data = getattr(backend, metric)(date_range=date_range, interval=interval, process_name=process_name)
        return HttpResponse(json.dumps(data))
コード例 #5
0
    def test_without_metrics(self, get_mock):
        get_mock.return_value = mock.Mock(status_code=404)
        app = {"name": "appname"}

        with self.assertRaises(MetricNotEnabled):
            get_backend(app, "token")
コード例 #6
0
    def test_envs_from_app(self):
        app = {"name": "appname", "envs": {"ELASTICSEARCH_HOST": "ble"}}

        backend = get_backend(app, "token")
        self.assertIsInstance(backend, ElasticSearch)
コード例 #7
0
    def test_without_metrics(self, get_mock):
        get_mock.return_value = Mock(status_code=404)
        app = {"name": "appname"}

        with self.assertRaises(MetricNotEnabled):
            get_backend(app, 'token')
コード例 #8
0
    def test_envs_from_app(self):
        app = {"name": "appname", "envs": {"ELASTICSEARCH_HOST": "ble"}}

        backend = get_backend(app, 'token')
        self.assertIsInstance(backend, ElasticSearch)