Ejemplo n.º 1
0
    def test_single_summary_format(self):
        data = {
            "name": "logged_users_total",
            "doc": "Logged users in the application",
            "const_labels": {},
        }

        labels = {}  # This one hasn't got labels
        values = [3, 5.2, 13, 4]

        valid_result = (
            "# HELP logged_users_total Logged users in the application",
            "# TYPE logged_users_total summary",
            'logged_users_total{quantile="0.5"} 4.0',
            'logged_users_total{quantile="0.9"} 5.2',
            'logged_users_total{quantile="0.99"} 5.2',
            "logged_users_total_count 4",
            "logged_users_total_sum 25.2",
        )

        s = Summary(**data)

        for i in values:
            s.add(labels, i)

        f = TextFormatter()
        result = f.marshall_lines(s)

        result = sorted(result)
        valid_result = sorted(valid_result)

        self.assertEqual(valid_result, result)
Ejemplo n.º 2
0
    def test_one_summary_format(self):
        data = {
            "name": "logged_users_total",
            "doc": "Logged users in the application",
            "const_labels": {},
        }

        labels = {"handler": "/static"}
        values = [3, 5.2, 13, 4]

        valid_result = (
            "# HELP logged_users_total Logged users in the application",
            "# TYPE logged_users_total summary",
            'logged_users_total{handler="/static",quantile="0.5"} 4.0',
            'logged_users_total{handler="/static",quantile="0.9"} 5.2',
            'logged_users_total{handler="/static",quantile="0.99"} 5.2',
            'logged_users_total_count{handler="/static"} 4',
            'logged_users_total_sum{handler="/static"} 25.2',
        )

        s = Summary(**data)

        for i in values:
            s.add(labels, i)

        f = TextFormatter()
        result = f.marshall_lines(s)

        result = sorted(result)
        valid_result = sorted(valid_result)

        self.assertEqual(valid_result, result)
Ejemplo n.º 3
0
    def test_single_summary_format(self):
        data = {
            "name": "logged_users_total",
            "doc": "Logged users in the application",
            "const_labels": {},
        }

        labels = {}  # This one hasn't got labels
        values = [3, 5.2, 13, 4]

        valid_result = (
            "# HELP logged_users_total Logged users in the application",
            "# TYPE logged_users_total summary",
            'logged_users_total{quantile="0.5"} 4.0',
            'logged_users_total{quantile="0.9"} 5.2',
            'logged_users_total{quantile="0.99"} 5.2',
            "logged_users_total_count 4",
            "logged_users_total_sum 25.2",
        )

        s = Summary(**data)

        for i in values:
            s.add(labels, i)

        f = TextFormatter()
        result = f.marshall_lines(s)

        result = sorted(result)
        valid_result = sorted(valid_result)

        self.assertEqual(valid_result, result)
Ejemplo n.º 4
0
    def test_one_summary_format(self):
        data = {
            "name": "logged_users_total",
            "doc": "Logged users in the application",
            "const_labels": {},
        }

        labels = {"handler": "/static"}
        values = [3, 5.2, 13, 4]

        valid_result = (
            "# HELP logged_users_total Logged users in the application",
            "# TYPE logged_users_total summary",
            'logged_users_total{handler="/static",quantile="0.5"} 4.0',
            'logged_users_total{handler="/static",quantile="0.9"} 5.2',
            'logged_users_total{handler="/static",quantile="0.99"} 5.2',
            'logged_users_total_count{handler="/static"} 4',
            'logged_users_total_sum{handler="/static"} 25.2',
        )

        s = Summary(**data)

        for i in values:
            s.add(labels, i)

        f = TextFormatter()
        result = f.marshall_lines(s)

        result = sorted(result)
        valid_result = sorted(valid_result)

        self.assertEqual(valid_result, result)
Ejemplo n.º 5
0
    def test_counter_format_with_const_labels(self):

        self.data = {
            "name": "logged_users_total",
            "doc": "Logged users in the application",
            "const_labels": {"app": "my_app"},
        }
        c = Counter(**self.data)

        counter_data = (
            ({"country": "sp", "device": "desktop"}, 520),
            ({"country": "us", "device": "mobile"}, 654),
            ({"country": "uk", "device": "desktop"}, 1001),
            ({"country": "de", "device": "desktop"}, 995),
            ({"country": "zh", "device": "desktop"}, 520),
            ({"country": "ch", "device": "mobile"}, 654),
            ({"country": "ca", "device": "desktop"}, 1001),
            ({"country": "jp", "device": "desktop"}, 995),
            ({"country": "au", "device": "desktop"}, 520),
            ({"country": "py", "device": "mobile"}, 654),
            ({"country": "ar", "device": "desktop"}, 1001),
            ({"country": "pt", "device": "desktop"}, 995),
        )

        valid_result = (
            "# HELP logged_users_total Logged users in the application",
            "# TYPE logged_users_total counter",
            'logged_users_total{app="my_app",country="ch",device="mobile"} 654',
            'logged_users_total{app="my_app",country="zh",device="desktop"} 520',
            'logged_users_total{app="my_app",country="jp",device="desktop"} 995',
            'logged_users_total{app="my_app",country="de",device="desktop"} 995',
            'logged_users_total{app="my_app",country="pt",device="desktop"} 995',
            'logged_users_total{app="my_app",country="ca",device="desktop"} 1001',
            'logged_users_total{app="my_app",country="sp",device="desktop"} 520',
            'logged_users_total{app="my_app",country="au",device="desktop"} 520',
            'logged_users_total{app="my_app",country="uk",device="desktop"} 1001',
            'logged_users_total{app="my_app",country="py",device="mobile"} 654',
            'logged_users_total{app="my_app",country="us",device="mobile"} 654',
            'logged_users_total{app="my_app",country="ar",device="desktop"} 1001',
        )

        # Add data to the collector
        for i in counter_data:
            c.set_value(i[0], i[1])

        # Select format
        f = TextFormatter()
        result = f.marshall_lines(c)

        result = sorted(result)
        valid_result = sorted(valid_result)

        self.assertEqual(valid_result, result)
Ejemplo n.º 6
0
    def test_multiple_summary_format(self):
        data = {
            "name": "prometheus_target_interval_length_seconds",
            "doc": "Actual intervals between scrapes.",
            "const_labels": {},
        }

        summary_data = (
            ({
                "interval": "5s"
            }, [3, 5.2, 13, 4]),
            ({
                "interval": "10s"
            }, [1.3, 1.2, 32.1, 59.2, 109.46, 70.9]),
            ({
                "interval": "10s",
                "method": "fast"
            }, [5, 9.8, 31, 9.7, 101.4]),
        )

        valid_result = (
            "# HELP prometheus_target_interval_length_seconds Actual intervals between scrapes.",
            "# TYPE prometheus_target_interval_length_seconds summary",
            'prometheus_target_interval_length_seconds{interval="5s",quantile="0.5"} 4.0',
            'prometheus_target_interval_length_seconds{interval="5s",quantile="0.9"} 5.2',
            'prometheus_target_interval_length_seconds{interval="5s",quantile="0.99"} 5.2',
            'prometheus_target_interval_length_seconds_count{interval="5s"} 4',
            'prometheus_target_interval_length_seconds_sum{interval="5s"} 25.2',
            'prometheus_target_interval_length_seconds{interval="10s",quantile="0.5"} 32.1',
            'prometheus_target_interval_length_seconds{interval="10s",quantile="0.9"} 59.2',
            'prometheus_target_interval_length_seconds{interval="10s",quantile="0.99"} 59.2',
            'prometheus_target_interval_length_seconds_count{interval="10s"} 6',
            'prometheus_target_interval_length_seconds_sum{interval="10s"} 274.15999999999997',
            'prometheus_target_interval_length_seconds{interval="10s",method="fast",quantile="0.5"} 9.7',
            'prometheus_target_interval_length_seconds{interval="10s",method="fast",quantile="0.9"} 9.8',
            'prometheus_target_interval_length_seconds{interval="10s",method="fast",quantile="0.99"} 9.8',
            'prometheus_target_interval_length_seconds_count{interval="10s",method="fast"} 5',
            'prometheus_target_interval_length_seconds_sum{interval="10s",method="fast"} 156.9',
        )

        s = Summary(**data)

        for i in summary_data:
            for j in i[1]:
                s.add(i[0], j)

        f = TextFormatter()
        result = f.marshall_lines(s)

        self.assertEqual(sorted(valid_result), sorted(result))
Ejemplo n.º 7
0
    def test_multiple_summary_format(self):
        data = {
            "name": "prometheus_target_interval_length_seconds",
            "doc": "Actual intervals between scrapes.",
            "const_labels": {},
        }

        summary_data = (
            ({"interval": "5s"}, [3, 5.2, 13, 4]),
            ({"interval": "10s"}, [1.3, 1.2, 32.1, 59.2, 109.46, 70.9]),
            ({"interval": "10s", "method": "fast"}, [5, 9.8, 31, 9.7, 101.4]),
        )

        valid_result = (
            "# HELP prometheus_target_interval_length_seconds Actual intervals between scrapes.",
            "# TYPE prometheus_target_interval_length_seconds summary",
            'prometheus_target_interval_length_seconds{interval="5s",quantile="0.5"} 4.0',
            'prometheus_target_interval_length_seconds{interval="5s",quantile="0.9"} 5.2',
            'prometheus_target_interval_length_seconds{interval="5s",quantile="0.99"} 5.2',
            'prometheus_target_interval_length_seconds_count{interval="5s"} 4',
            'prometheus_target_interval_length_seconds_sum{interval="5s"} 25.2',
            'prometheus_target_interval_length_seconds{interval="10s",quantile="0.5"} 32.1',
            'prometheus_target_interval_length_seconds{interval="10s",quantile="0.9"} 59.2',
            'prometheus_target_interval_length_seconds{interval="10s",quantile="0.99"} 59.2',
            'prometheus_target_interval_length_seconds_count{interval="10s"} 6',
            'prometheus_target_interval_length_seconds_sum{interval="10s"} 274.15999999999997',
            'prometheus_target_interval_length_seconds{interval="10s",method="fast",quantile="0.5"} 9.7',
            'prometheus_target_interval_length_seconds{interval="10s",method="fast",quantile="0.9"} 9.8',
            'prometheus_target_interval_length_seconds{interval="10s",method="fast",quantile="0.99"} 9.8',
            'prometheus_target_interval_length_seconds_count{interval="10s",method="fast"} 5',
            'prometheus_target_interval_length_seconds_sum{interval="10s",method="fast"} 156.9',
        )

        s = Summary(**data)

        for i in summary_data:
            for j in i[1]:
                s.add(i[0], j)

        f = TextFormatter()
        result = f.marshall_lines(s)

        self.assertEqual(sorted(valid_result), sorted(result))
Ejemplo n.º 8
0
    def test_gauge_format_with_const_labels(self):

        self.data = {
            "name": "logged_users_total",
            "doc": "Logged users in the application",
            "const_labels": {
                "app": "my_app"
            },
        }
        g = Gauge(**self.data)

        counter_data = (
            ({
                "country": "sp",
                "device": "desktop"
            }, 520),
            ({
                "country": "us",
                "device": "mobile"
            }, 654),
            ({
                "country": "uk",
                "device": "desktop"
            }, 1001),
            ({
                "country": "de",
                "device": "desktop"
            }, 995),
            ({
                "country": "zh",
                "device": "desktop"
            }, 520),
            ({
                "country": "ch",
                "device": "mobile"
            }, 654),
            ({
                "country": "ca",
                "device": "desktop"
            }, 1001),
            ({
                "country": "jp",
                "device": "desktop"
            }, 995),
            ({
                "country": "au",
                "device": "desktop"
            }, 520),
            ({
                "country": "py",
                "device": "mobile"
            }, 654),
            ({
                "country": "ar",
                "device": "desktop"
            }, 1001),
            ({
                "country": "pt",
                "device": "desktop"
            }, 995),
        )

        valid_result = (
            "# HELP logged_users_total Logged users in the application",
            "# TYPE logged_users_total gauge",
            'logged_users_total{app="my_app",country="ch",device="mobile"} 654',
            'logged_users_total{app="my_app",country="zh",device="desktop"} 520',
            'logged_users_total{app="my_app",country="jp",device="desktop"} 995',
            'logged_users_total{app="my_app",country="de",device="desktop"} 995',
            'logged_users_total{app="my_app",country="pt",device="desktop"} 995',
            'logged_users_total{app="my_app",country="ca",device="desktop"} 1001',
            'logged_users_total{app="my_app",country="sp",device="desktop"} 520',
            'logged_users_total{app="my_app",country="au",device="desktop"} 520',
            'logged_users_total{app="my_app",country="uk",device="desktop"} 1001',
            'logged_users_total{app="my_app",country="py",device="mobile"} 654',
            'logged_users_total{app="my_app",country="us",device="mobile"} 654',
            'logged_users_total{app="my_app",country="ar",device="desktop"} 1001',
        )

        # Add data to the collector
        for i in counter_data:
            g.set_value(i[0], i[1])

        # Select format
        f = TextFormatter()
        result = f.marshall_lines(g)

        result = sorted(result)
        valid_result = sorted(valid_result)

        self.assertEqual(valid_result, result)