Beispiel #1
0
 def on_post(self, req, res):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req,
                                    self._post_metrics_authorized_roles)
     metrics = helpers.read_http_resource(req)
     self._validate_metrics(metrics)
     tenant_id = (helpers.get_x_tenant_or_tenant_id(
         req, self._delegate_authorized_roles))
     transformed_metrics = metrics_message.transform(
         metrics, tenant_id, self._region)
     self._send_metrics(transformed_metrics)
     res.status = falcon.HTTP_204
Beispiel #2
0
 def on_post(self, req, res):
     helpers.validate_json_content_type(req)
     helpers.validate_authorization(req,
                                    self._post_metrics_authorized_roles)
     metrics = helpers.read_http_resource(req)
     self._validate_metrics(metrics)
     tenant_id = (
         helpers.get_x_tenant_or_tenant_id(req,
                                           self._delegate_authorized_roles))
     transformed_metrics = metrics_message.transform(
         metrics, tenant_id, self._region)
     self._send_metrics(transformed_metrics)
     res.status = falcon.HTTP_204
 def test_single_metrics(self, time):
     time.return_value = 514862580
     tenant_id = 222
     region = 'default'
     metrics = 'example.test'
     expected_metrics = {'metric': 'example.test',
                         'creation_time': 514862580,
                         'meta':
                             {'region': 'default',
                              'tenantId': 222}}
     transformed_metric = transform(metrics, tenant_id, region)
     self.assertIsInstance(transformed_metric, list)
     self.assertEqual(len(transformed_metric), 1)
     self.assertEqual(expected_metrics, json.loads(transformed_metric[0]))
Beispiel #4
0
    def on_post(self, req, res):
        helpers.validate_json_content_type(req)
        helpers.validate_authorization(req, ['api:metrics:post'])
        metrics = helpers.from_json(req)
        try:
            metric_validation.validate(metrics)
        except Exception as ex:
            LOG.exception(ex)
            raise HTTPUnprocessableEntityError("Unprocessable Entity", str(ex))

        tenant_id = helpers.get_x_tenant_or_tenant_id(req, ['api:delegate'])
        transformed_metrics = metrics_message.transform(
            metrics, tenant_id, self._region)
        self._send_metrics(transformed_metrics)
        res.status = falcon.HTTP_204
Beispiel #5
0
 def test_single_metrics(self, time):
     time.return_value = 514862580
     tenant_id = 222
     region = 'default'
     metrics = 'example.test'
     expected_metrics = {
         'metric': 'example.test',
         'creation_time': 514862580,
         'meta': {
             'region': 'default',
             'tenantId': 222
         }
     }
     transformed_metric = transform(metrics, tenant_id, region)
     self.assertIsInstance(transformed_metric, list)
     self.assertEqual(len(transformed_metric), 1)
     self.assertEqual(expected_metrics, json.loads(transformed_metric[0]))
 def test_multiple_metrics(self, time):
     time.return_value = 514862580
     tenant_id = 222
     region = 'default'
     metrics = ['example.test1', 'example.test2']
     expected_metrics = []
     for metric in metrics:
         expected_metrics.append({'metric': metric,
                                  'creation_time': 514862580,
                                  'meta':
                                      {'region': 'default',
                                       'tenantId': 222}})
     transformed_metrics = transform(metrics, tenant_id, region)
     self.assertIsInstance(transformed_metrics, list)
     self.assertEqual(len(transformed_metrics), len(metrics))
     for transformed_metric in transformed_metrics:
         self.assertIn(json.loads(transformed_metric), expected_metrics)
Beispiel #7
0
    def on_post(self, req, res):
        helpers.validate_json_content_type(req)
        helpers.validate_authorization(req,
                                       self._post_metrics_authorized_roles)
        metrics = helpers.read_http_resource(req)
        try:
            metric_validation.validate(metrics)
        except Exception as ex:
            LOG.exception(ex)
            raise HTTPUnprocessableEntityError("Unprocessable Entity",
                                               ex.message)

        tenant_id = (helpers.get_x_tenant_or_tenant_id(
            req, self._delegate_authorized_roles))
        transformed_metrics = metrics_message.transform(
            metrics, tenant_id, self._region)
        self._send_metrics(transformed_metrics)
        res.status = falcon.HTTP_204
Beispiel #8
0
    def on_post(self, req, res):
        helpers.validate_json_content_type(req)
        helpers.validate_authorization(req,
                                       self._post_metrics_authorized_roles)
        metrics = helpers.from_json(req)
        try:
            metric_validation.validate(metrics)
        except Exception as ex:
            LOG.exception(ex)
            raise HTTPUnprocessableEntityError("Unprocessable Entity", str(ex))

        tenant_id = (
            helpers.get_x_tenant_or_tenant_id(req,
                                              self._delegate_authorized_roles))
        transformed_metrics = metrics_message.transform(
            metrics, tenant_id, self._region)
        self._send_metrics(transformed_metrics)
        res.status = falcon.HTTP_204
Beispiel #9
0
 def test_multiple_metrics(self, time):
     time.return_value = 514862580
     tenant_id = 222
     region = 'default'
     metrics = ['example.test1', 'example.test2']
     expected_metrics = []
     for metric in metrics:
         expected_metrics.append({
             'metric': metric,
             'creation_time': 514862580,
             'meta': {
                 'region': 'default',
                 'tenantId': 222
             }
         })
     transformed_metrics = transform(metrics, tenant_id, region)
     self.assertIsInstance(transformed_metrics, list)
     self.assertEqual(len(transformed_metrics), len(metrics))
     for transformed_metric in transformed_metrics:
         self.assertIn(json.loads(transformed_metric), expected_metrics)