Beispiel #1
0
def test_translate_results_missing_slots(_1, _2):
    query_params = MultiValueDict(
        {
            "field": [
                "sum(session)",
            ],
            "interval": ["1d"],
            "statsPeriod": ["3d"],
        }
    )
    query_definition = QueryDefinition(query_params)

    results = {
        "metrics_counters": {
            "totals": {
                "data": [
                    {
                        "metric_id": 9,  # session
                        "value": 400,
                    },
                ],
            },
            "series": {
                "data": [
                    {
                        "metric_id": 9,  # session
                        "bucketed_time": datetime(2021, 8, 23, tzinfo=pytz.utc),
                        "value": 100,
                    },
                    # no data for 2021-08-24
                    {
                        "metric_id": 9,  # session
                        "bucketed_time": datetime(2021, 8, 25, tzinfo=pytz.utc),
                        "value": 300,
                    },
                ],
            },
        },
    }

    intervals = list(query_definition.get_intervals())
    assert SnubaResultConverter(1, query_definition, intervals, results).translate_results() == [
        {
            "by": {},
            "totals": {
                "sum(session)": 400,
            },
            "series": {
                # No data for 2021-08-24
                "sum(session)": [100, 0, 300],
            },
        },
    ]
Beispiel #2
0
def test_translate_results(_1, _2):
    query_params = MultiValueDict(
        {
            "groupBy": ["session.status"],
            "field": [
                "sum(session)",
                "max(session.duration)",
                "p50(session.duration)",
                "p95(session.duration)",
            ],
            "interval": ["1d"],
            "statsPeriod": ["2d"],
        }
    )
    query_definition = QueryDefinition(query_params)

    intervals = list(query_definition.get_intervals())
    results = {
        "metrics_counters": {
            "totals": {
                "data": [
                    {
                        "metric_id": 9,  # session
                        "tags[8]": 4,  # session.status:healthy
                        "value": 300,
                    },
                    {
                        "metric_id": 9,  # session
                        "tags[8]": 0,  # session.status:abnormal
                        "value": 330,
                    },
                ],
            },
            "series": {
                "data": [
                    {
                        "metric_id": 9,  # session
                        "tags[8]": 4,
                        "bucketed_time": datetime(2021, 8, 24, tzinfo=pytz.utc),
                        "value": 100,
                    },
                    {
                        "metric_id": 9,  # session
                        "tags[8]": 0,
                        "bucketed_time": datetime(2021, 8, 24, tzinfo=pytz.utc),
                        "value": 110,
                    },
                    {
                        "metric_id": 9,  # session
                        "tags[8]": 4,
                        "bucketed_time": datetime(2021, 8, 25, tzinfo=pytz.utc),
                        "value": 200,
                    },
                    {
                        "metric_id": 9,  # session
                        "tags[8]": 0,
                        "bucketed_time": datetime(2021, 8, 25, tzinfo=pytz.utc),
                        "value": 220,
                    },
                ],
            },
        },
        "metrics_distributions": {
            "totals": {
                "data": [
                    {
                        "metric_id": 7,  # session.duration
                        "tags[8]": 4,
                        "max": 123.4,
                        "percentiles": [1, 2, 3, 4, 5],
                    },
                    {
                        "metric_id": 7,  # session.duration
                        "tags[8]": 0,
                        "max": 456.7,
                        "percentiles": [1.5, 2.5, 3.5, 4.5, 5.5],
                    },
                ],
            },
            "series": {
                "data": [
                    {
                        "metric_id": 7,  # session.duration
                        "tags[8]": 4,
                        "bucketed_time": datetime(2021, 8, 24, tzinfo=pytz.utc),
                        "max": 10.1,
                        "percentiles": [1.1, 2.1, 3.1, 4.1, 5.1],
                    },
                    {
                        "metric_id": 7,  # session.duration
                        "tags[8]": 0,
                        "bucketed_time": datetime(2021, 8, 24, tzinfo=pytz.utc),
                        "max": 20.2,
                        "percentiles": [1.2, 2.2, 3.2, 4.2, 5.2],
                    },
                    {
                        "metric_id": 7,  # session.duration
                        "tags[8]": 4,
                        "bucketed_time": datetime(2021, 8, 25, tzinfo=pytz.utc),
                        "max": 30.3,
                        "percentiles": [1.3, 2.3, 3.3, 4.3, 5.3],
                    },
                    {
                        "metric_id": 7,  # session.duration
                        "tags[8]": 0,
                        "bucketed_time": datetime(2021, 8, 25, tzinfo=pytz.utc),
                        "max": 40.4,
                        "percentiles": [1.4, 2.4, 3.4, 4.4, 5.4],
                    },
                ],
            },
        },
    }

    assert SnubaResultConverter(1, query_definition, intervals, results).translate_results() == [
        {
            "by": {"session.status": "healthy"},
            "totals": {
                "sum(session)": 300,
                "max(session.duration)": 123.4,
                "p50(session.duration)": 1,
                "p95(session.duration)": 4,
            },
            "series": {
                "sum(session)": [100, 200],
                "max(session.duration)": [10.1, 30.3],
                "p50(session.duration)": [1.1, 1.3],
                "p95(session.duration)": [4.1, 4.3],
            },
        },
        {
            "by": {"session.status": "abnormal"},
            "totals": {
                "sum(session)": 330,
                "max(session.duration)": 456.7,
                "p50(session.duration)": 1.5,
                "p95(session.duration)": 4.5,
            },
            "series": {
                "sum(session)": [110, 220],
                "max(session.duration)": [20.2, 40.4],
                "p50(session.duration)": [1.2, 1.4],
                "p95(session.duration)": [4.2, 4.4],
            },
        },
    ]