Exemple #1
0
    def test_sessions_metrics_equal_num_keys(self):
        """
        Tests whether the number of keys in the metrics implementation of
        sessions data is the same as in the sessions implementation.

        Runs twice. Firstly, against sessions implementation to populate the
        cache. Then, against the metrics implementation, and compares with
        cached results.
        """
        interval_days = "1d"
        groupbyes = _session_groupby_powerset()

        for groupby in groupbyes:
            with patch(
                "sentry.api.endpoints.organization_sessions.release_health",
                SessionsReleaseHealthBackend(),
            ):
                sessions_data = result_sorted(self.get_sessions_data(groupby, interval_days))

            with patch(
                "sentry.release_health.metrics_sessions_v2.indexer.resolve", MockIndexer().resolve
            ), patch(
                "sentry.api.endpoints.organization_sessions.release_health",
                MetricsReleaseHealthBackend(),
            ):
                metrics_data = result_sorted(self.get_sessions_data(groupby, interval_days))

            errors = compare_results(
                sessions=sessions_data,
                metrics=metrics_data,
                rollup=interval_days * 24 * 60 * 60,  # days to seconds
            )
            assert len(errors) == 0
Exemple #2
0
 def __init__(
     self,
     metrics_start: datetime,
 ):
     self.sessions = SessionsReleaseHealthBackend()
     self.metrics = MetricsReleaseHealthBackend()
     self.metrics_start = metrics_start
Exemple #3
0
 def __init__(
     self,
     metrics_start: datetime,
 ):
     self.sessions = SessionsReleaseHealthBackend()
     self.metrics = MetricsReleaseHealthBackend()
     self.metrics_start = max(
         metrics_start,
         # The sessions backend never returns data beyond 90 days, so any
         # query beyond 90 days will return truncated results.
         # We assume that the release health duplex backend is sufficiently
         # often reinstantiated, at least once per day, not only due to
         # deploys but also because uwsgi/celery are routinely restarting
         # processes
         datetime.now(timezone.utc) - timedelta(days=89),
     )
Exemple #4
0
 class MetricsTest(SessionMetricsTestCase, cls):
     __doc__ = f"Repeat tests from {cls} with metrics"
     backend = MetricsReleaseHealthBackend()
Exemple #5
0
class ReleaseHealthMetricsTestCase(SessionMetricsTestCase):
    backend = MetricsReleaseHealthBackend()
Exemple #6
0
            },
            {
                "by": {"release": "[email protected]"},
                "series": {"count_unique(user)": [0], "sum(session)": [1]},
                "totals": {"count_unique(user)": 0, "sum(session)": 1},
            },
        ]

    @freeze_time(MOCK_DATETIME + datetime.timedelta(days=2))
    def test_groupby_no_data(self):
        # Empty results for everything
        response = self.do_request(
            {
                "project": self.project.id,  # project without users
                "statsPeriod": "1d",
                "interval": "1d",
                "field": ["count_unique(user)", "sum(session)"],
                "groupBy": "release",
            }
        )

        assert response.status_code == 200, response.content
        assert result_sorted(response.data)["groups"] == []


@patch("sentry.api.endpoints.organization_sessions.release_health", MetricsReleaseHealthBackend())
class OrganizationSessionsEndpointMetricsTest(
    SessionMetricsTestCase, OrganizationSessionsEndpointTest
):
    """Repeat with metrics backend"""
    @freeze_time(MOCK_DATETIME)
    def test_environment_filter_not_present_in_query(self):
        self.create_environment(name="abc")
        response = self.do_request({
            "project": [-1],
            "statsPeriod": "1d",
            "interval": "1d",
            "field": ["sum(session)"],
            "environment": ["development", "abc"],
        })

        assert response.status_code == 200, response.content
        assert result_sorted(response.data)["groups"] == [{
            "by": {},
            "series": {
                "sum(session)": [1]
            },
            "totals": {
                "sum(session)": 1
            }
        }]


@patch("sentry.api.endpoints.organization_sessions.release_health",
       MetricsReleaseHealthBackend())
class OrganizationSessionsEndpointMetricsTest(SessionMetricsTestCase,
                                              OrganizationSessionsEndpointTest
                                              ):
    """Repeat with metrics backend"""