Ejemplo n.º 1
0
    def test_document_from_metric_should_build_a_document_from_a_metric(self):
        p0 = "foo"
        p1 = "bar"
        p2 = "baz"
        metric_name = "%s.%s.%s" % (p0, p1, p2)
        metric_id = uuid.uuid5(
            uuid.UUID("{00000000-1111-2222-3333-444444444444}"), metric_name)

        aggregator = Aggregator.maximum
        retention_str = "42*1s:43*60s"
        retention = Retention.from_string(retention_str)
        carbon_xfilesfactor = 0.5
        metadata = MetricMetadata.create(aggregator, retention,
                                         carbon_xfilesfactor)
        metric = bg_metric.Metric(
            metric_name,
            metric_id,
            metadata,
            created_on=datetime.datetime(2017, 1, 1),
            updated_on=datetime.datetime(2018, 2, 2),
        )

        document = bg_elasticsearch.document_from_metric(metric)

        self.__check_document_value(document, "depth", 2)
        self.__check_document_value(document, "uuid", metric_id)
        self.__check_document_value(document, "p0", p0)
        self.__check_document_value(document, "p1", p1)
        self.__check_document_value(document, "p2", p2)

        self.assertTrue("config" in document)
        document_config = document["config"]
        self.__check_document_value(document_config, "aggregator",
                                    aggregator.name)
        self.__check_document_value(document_config, "retention",
                                    retention_str)
        self.__check_document_value(document_config, "carbon_xfilesfactor",
                                    "%f" % carbon_xfilesfactor)

        self.assertTrue("created_on" in document)
        self.assertTrue(isinstance(document["created_on"], datetime.datetime))
        self.assertEqual(metric.created_on, document["created_on"])
        self.assertTrue("updated_on" in document)
        self.assertTrue(isinstance(document["updated_on"], datetime.datetime))
        self.assertEqual(metric.updated_on, document["updated_on"])
        self.assertTrue("read_on" in document)
        self.assertEqual(document["read_on"], None)
Ejemplo n.º 2
0
    def test_document_from_metric_should_build_a_document_from_a_metric(self):
        p0 = "foo"
        p1 = "bar"
        p2 = "baz"
        metric_name = "%s.%s.%s" % (p0, p1, p2)
        metric_id = uuid.uuid5(
            uuid.UUID("{00000000-1111-2222-3333-444444444444}"), metric_name
        )

        aggregator = Aggregator.maximum
        retention_str = "42*1s:43*60s"
        retention = Retention.from_string(retention_str)
        carbon_xfilesfactor = 0.5
        metadata = MetricMetadata(aggregator, retention, carbon_xfilesfactor)
        metric = bg_metric.Metric(
            metric_name,
            metric_id,
            metadata,
            created_on=datetime.datetime(2017, 1, 1),
            updated_on=datetime.datetime(2018, 2, 2),
        )

        document = bg_elasticsearch.document_from_metric(metric)

        self.__check_document_value(document, "depth", 2)
        self.__check_document_value(document, "uuid", metric_id)
        self.__check_document_value(document, "p0", p0)
        self.__check_document_value(document, "p1", p1)
        self.__check_document_value(document, "p2", p2)

        self.assertTrue("config" in document)
        document_config = document["config"]
        self.__check_document_value(document_config, "aggregator", aggregator.name)
        self.__check_document_value(document_config, "retention", retention_str)
        self.__check_document_value(
            document_config, "carbon_xfilesfactor", "%f" % carbon_xfilesfactor
        )

        self.assertTrue("created_on" in document)
        self.assertTrue(isinstance(document["created_on"], datetime.datetime))
        self.assertEqual(metric.created_on, document["created_on"])
        self.assertTrue("updated_on" in document)
        self.assertTrue(isinstance(document["updated_on"], datetime.datetime))
        self.assertEqual(metric.updated_on, document["updated_on"])
        self.assertTrue("read_on" in document)
        self.assertEqual(document["read_on"], None)
Ejemplo n.º 3
0
 def test_document_from_metric_should_throw_AttributeError_on_None_metric(self):
     with self.assertRaises(AttributeError):
         bg_elasticsearch.document_from_metric(None)
Ejemplo n.º 4
0
 def test_document_from_metric_should_throw_AttributeError_on_None_metric(
         self):
     with self.assertRaises(AttributeError):
         bg_elasticsearch.document_from_metric(None)