1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687 |
- import time
- from datetime import datetime, timedelta
- from datetime import timezone as dt_timezone
- import pytest
- import pytz
- from django.utils import timezone
- from sentry.release_health.base import OverviewStat
- from sentry.release_health.metrics import MetricsReleaseHealthBackend
- from sentry.release_health.sessions import SessionsReleaseHealthBackend
- from sentry.sentry_metrics.configuration import UseCaseKey
- from sentry.snuba.sessions import _make_stats
- from sentry.testutils.cases import BaseMetricsTestCase, SnubaTestCase, TestCase
- from sentry.testutils.silo import region_silo_test
- pytestmark = pytest.mark.sentry_metrics
- def parametrize_backend(cls):
- """
- hack to parametrize test-classes by backend. Ideally we'd move
- over to pytest-style tests so we can use `pytest.mark.parametrize`, but
- hopefully we won't have more than one backend in the future.
- """
- assert not hasattr(cls, "backend")
- cls.backend = SessionsReleaseHealthBackend()
- class MetricsLayerTest(BaseMetricsTestCase, cls):
- __doc__ = f"Repeat tests from {cls} with metrics layer"
- backend = MetricsReleaseHealthBackend()
- adjust_interval = True # HACK interval adjustment for new MetricsLayer implementation
- MetricsLayerTest.__name__ = f"{cls.__name__}MetricsLayer"
- globals()[MetricsLayerTest.__name__] = MetricsLayerTest
- return cls
- def format_timestamp(dt):
- if not isinstance(dt, datetime):
- dt = datetime.utcfromtimestamp(dt)
- return dt.strftime("%Y-%m-%dT%H:%M:%S+00:00")
- def make_24h_stats(ts, adjust_start=False):
- ret_val = _make_stats(datetime.utcfromtimestamp(ts).replace(tzinfo=pytz.utc), 3600, 24)
- if adjust_start:
- # HACK this adds another interval at the beginning in accordance with the new way of calculating intervals
- # https://www.notion.so/sentry/Metrics-Layer-get_intervals-bug-dce140607d054201a5e6629b070cb969
- ret_val.insert(0, [ret_val[0][0] - 3600, 0])
- return ret_val
- @parametrize_backend
- class SnubaSessionsTest(TestCase, SnubaTestCase):
- adjust_interval = False # HACK interval adjustment for new MetricsLayer implementation
- def setUp(self):
- super().setUp()
- self.received = time.time()
- self.session_started = time.time() // 60 * 60
- self.session_release = "foo@1.0.0"
- self.session_crashed_release = "foo@2.0.0"
- session_1 = "5d52fd05-fcc9-4bf3-9dc9-267783670341"
- session_2 = "5e910c1a-6941-460e-9843-24103fb6a63c"
- session_3 = "a148c0c5-06a2-423b-8901-6b43b812cf82"
- user_1 = "39887d89-13b2-4c84-8c23-5d13d2102666"
- self.store_session(
- self.build_session(
- distinct_id=user_1,
- session_id=session_1,
- status="exited",
- release=self.session_release,
- environment="prod",
- started=self.session_started,
- received=self.received,
- )
- )
- self.store_session(
- self.build_session(
- distinct_id=user_1,
- session_id=session_2,
- release=self.session_release,
- environment="prod",
- duration=None,
- started=self.session_started,
- received=self.received,
- )
- )
- self.store_session(
- self.build_session(
- distinct_id=user_1,
- session_id=session_2,
- seq=1,
- duration=30,
- status="exited",
- release=self.session_release,
- environment="prod",
- started=self.session_started,
- received=self.received,
- )
- )
- self.store_session(
- self.build_session(
- distinct_id=user_1,
- session_id=session_3,
- status="crashed",
- release=self.session_crashed_release,
- environment="prod",
- started=self.session_started,
- received=self.received,
- )
- )
- def test_get_oldest_health_data_for_releases(self):
- data = self.backend.get_oldest_health_data_for_releases(
- [(self.project.id, self.session_release)]
- )
- assert data == {
- (self.project.id, self.session_release): format_timestamp(
- self.session_started // 3600 * 3600
- )
- }
- def test_check_has_health_data(self):
- data = self.backend.check_has_health_data(
- [(self.project.id, self.session_release), (self.project.id, "dummy-release")]
- )
- assert data == {(self.project.id, self.session_release)}
- def test_check_has_health_data_without_releases_should_include_sessions_lte_90_days(self):
- """
- Test that ensures that `check_has_health_data` returns a set of projects that has health
- data within the last 90d if only a list of project ids is provided and any project with
- session data earlier than 90 days should be included
- """
- project2 = self.create_project(
- name="Bar2",
- slug="bar2",
- teams=[self.team],
- fire_project_created=True,
- organization=self.organization,
- )
- self.store_session(
- self.build_session(
- **{
- "project_id": project2.id,
- "org_id": project2.organization_id,
- "status": "exited",
- }
- )
- )
- data = self.backend.check_has_health_data([self.project.id, project2.id])
- assert data == {self.project.id, project2.id}
- def test_check_has_health_data_does_not_crash_when_sending_projects_list_as_set(self):
- data = self.backend.check_has_health_data({self.project.id})
- assert data == {self.project.id}
- def test_get_project_releases_by_stability(self):
- # Add an extra session with a different `distinct_id` so that sorting by users
- # is stable
- self.store_session(
- self.build_session(
- release=self.session_release,
- environment="prod",
- started=self.session_started,
- received=self.received,
- )
- )
- for scope in "sessions", "users":
- data = self.backend.get_project_releases_by_stability(
- [self.project.id], offset=0, limit=100, scope=scope, stats_period="24h"
- )
- assert data == [
- (self.project.id, self.session_release),
- (self.project.id, self.session_crashed_release),
- ]
- def test_get_project_releases_by_stability_for_crash_free_sort(self):
- """
- Test that ensures that using crash free rate sort options, returns a list of ASC releases
- according to the chosen crash_free sort option
- """
- # add another user to session_release to make sure that they are sorted correctly
- self.store_session(
- self.build_session(
- status="exited",
- release=self.session_release,
- environment="prod",
- started=self.session_started,
- received=self.received,
- )
- )
- for scope in "crash_free_sessions", "crash_free_users":
- data = self.backend.get_project_releases_by_stability(
- [self.project.id], offset=0, limit=100, scope=scope, stats_period="24h"
- )
- assert data == [
- (self.project.id, self.session_crashed_release),
- (self.project.id, self.session_release),
- ]
- def test_get_project_releases_by_stability_for_releases_with_users_data(self):
- """
- Test that ensures if releases contain no users data, then those releases should not be
- returned on `users` and `crash_free_users` sorts
- """
- self.store_session(
- self.build_session(
- distinct_id=None,
- release="release-with-no-users",
- environment="prod",
- started=self.session_started,
- received=self.received,
- )
- )
- data = self.backend.get_project_releases_by_stability(
- [self.project.id], offset=0, limit=100, scope="users", stats_period="24h"
- )
- assert set(data) == {
- (self.project.id, self.session_release),
- (self.project.id, self.session_crashed_release),
- }
- data = self.backend.get_project_releases_by_stability(
- [self.project.id], offset=0, limit=100, scope="crash_free_users", stats_period="24h"
- )
- assert set(data) == {
- (self.project.id, self.session_crashed_release),
- (self.project.id, self.session_release),
- }
- def test_get_release_adoption(self):
- data = self.backend.get_release_adoption(
- [
- (self.project.id, self.session_release),
- (self.project.id, self.session_crashed_release),
- (self.project.id, "dummy-release"),
- ]
- )
- assert data == {
- (self.project.id, self.session_release): {
- "sessions_24h": 2,
- "users_24h": 1,
- "adoption": 100.0,
- "sessions_adoption": 66.66666666666666,
- "project_sessions_24h": 3,
- "project_users_24h": 1,
- },
- (self.project.id, self.session_crashed_release): {
- "sessions_24h": 1,
- "users_24h": 1,
- "adoption": 100.0,
- "sessions_adoption": 33.33333333333333,
- "project_sessions_24h": 3,
- "project_users_24h": 1,
- },
- }
- def test_get_release_adoption_lowered(self):
- self.store_session(
- self.build_session(
- release=self.session_crashed_release,
- environment="prod",
- status="crashed",
- started=self.session_started,
- received=self.received,
- )
- )
- data = self.backend.get_release_adoption(
- [
- (self.project.id, self.session_release),
- (self.project.id, self.session_crashed_release),
- (self.project.id, "dummy-release"),
- ]
- )
- assert data == {
- (self.project.id, self.session_release): {
- "sessions_24h": 2,
- "users_24h": 1,
- "adoption": 50.0,
- "sessions_adoption": 50.0,
- "project_sessions_24h": 4,
- "project_users_24h": 2,
- },
- (self.project.id, self.session_crashed_release): {
- "sessions_24h": 2,
- "users_24h": 2,
- "adoption": 100.0,
- "sessions_adoption": 50.0,
- "project_sessions_24h": 4,
- "project_users_24h": 2,
- },
- }
- def test_get_release_health_data_overview_users(self):
- data = self.backend.get_release_health_data_overview(
- [
- (self.project.id, self.session_release),
- (self.project.id, self.session_crashed_release),
- ],
- summary_stats_period="24h",
- health_stats_period="24h",
- stat="users",
- )
- stats = make_24h_stats(self.received - (24 * 3600), adjust_start=self.adjust_interval)
- stats[-1] = [stats[-1][0], 1]
- stats_ok = stats_crash = stats
- assert data == {
- (self.project.id, self.session_crashed_release): {
- "total_sessions": 1,
- "sessions_errored": 0,
- "total_sessions_24h": 1,
- "total_users": 1,
- "duration_p90": None,
- "sessions_crashed": 1,
- "total_users_24h": 1,
- "stats": {"24h": stats_crash},
- "crash_free_users": 0.0,
- "adoption": 100.0,
- "sessions_adoption": 33.33333333333333,
- "has_health_data": True,
- "crash_free_sessions": 0.0,
- "duration_p50": None,
- "total_project_sessions_24h": 3,
- "total_project_users_24h": 1,
- },
- (self.project.id, self.session_release): {
- "total_sessions": 2,
- "sessions_errored": 0,
- "total_sessions_24h": 2,
- "total_users": 1,
- "duration_p90": 57.0,
- "sessions_crashed": 0,
- "total_users_24h": 1,
- "stats": {"24h": stats_ok},
- "crash_free_users": 100.0,
- "adoption": 100.0,
- "sessions_adoption": 66.66666666666666,
- "has_health_data": True,
- "crash_free_sessions": 100.0,
- "duration_p50": 45.0,
- "total_project_sessions_24h": 3,
- "total_project_users_24h": 1,
- },
- }
- def test_get_release_health_data_overview_sessions(self):
- data = self.backend.get_release_health_data_overview(
- [
- (self.project.id, self.session_release),
- (self.project.id, self.session_crashed_release),
- ],
- summary_stats_period="24h",
- health_stats_period="24h",
- stat="sessions",
- )
- stats = make_24h_stats(self.received - (24 * 3600), adjust_start=self.adjust_interval)
- stats_ok = stats[:-1] + [[stats[-1][0], 2]]
- stats_crash = stats[:-1] + [[stats[-1][0], 1]]
- assert data == {
- (self.project.id, self.session_crashed_release): {
- "total_sessions": 1,
- "sessions_errored": 0,
- "total_sessions_24h": 1,
- "total_users": 1,
- "duration_p90": None,
- "sessions_crashed": 1,
- "total_users_24h": 1,
- "stats": {"24h": stats_crash},
- "crash_free_users": 0.0,
- "adoption": 100.0,
- "sessions_adoption": 33.33333333333333,
- "has_health_data": True,
- "crash_free_sessions": 0.0,
- "duration_p50": None,
- "total_project_sessions_24h": 3,
- "total_project_users_24h": 1,
- },
- (self.project.id, self.session_release): {
- "total_sessions": 2,
- "sessions_errored": 0,
- "total_sessions_24h": 2,
- "total_users": 1,
- "duration_p90": 57.0,
- "sessions_crashed": 0,
- "total_users_24h": 1,
- "stats": {"24h": stats_ok},
- "crash_free_users": 100.0,
- "sessions_adoption": 66.66666666666666,
- "adoption": 100.0,
- "has_health_data": True,
- "crash_free_sessions": 100.0,
- "duration_p50": 45.0,
- "total_project_sessions_24h": 3,
- "total_project_users_24h": 1,
- },
- }
- def test_fetching_release_sessions_time_bounds_for_different_release(self):
- """
- Test that ensures only session bounds for releases are calculated according
- to their respective release
- """
- # Same release session
- self.store_session(
- self.build_session(
- release=self.session_release,
- environment="prod",
- status="exited",
- started=self.session_started - 3600 * 2,
- received=self.received - 3600 * 2,
- )
- )
- # Different release session
- self.store_session(
- self.build_session(
- release=self.session_crashed_release,
- environment="prod",
- status="crashed",
- started=self.session_started - 3600 * 2,
- received=self.received - 3600 * 2,
- )
- )
- expected_formatted_lower_bound = (
- datetime.utcfromtimestamp(self.session_started - 3600 * 2)
- .replace(minute=0)
- .isoformat()[:19]
- + "Z"
- )
- expected_formatted_upper_bound = (
- datetime.utcfromtimestamp(self.session_started).replace(minute=0).isoformat()[:19] + "Z"
- )
- # Test for self.session_release
- data = self.backend.get_release_sessions_time_bounds(
- project_id=self.project.id,
- release=self.session_release,
- org_id=self.organization.id,
- environments=["prod"],
- )
- assert data == {
- "sessions_lower_bound": expected_formatted_lower_bound,
- "sessions_upper_bound": expected_formatted_upper_bound,
- }
- # Test for self.session_crashed_release
- data = self.backend.get_release_sessions_time_bounds(
- project_id=self.project.id,
- release=self.session_crashed_release,
- org_id=self.organization.id,
- environments=["prod"],
- )
- assert data == {
- "sessions_lower_bound": expected_formatted_lower_bound,
- "sessions_upper_bound": expected_formatted_upper_bound,
- }
- def test_fetching_release_sessions_time_bounds_for_different_release_with_no_sessions(self):
- """
- Test that ensures if no sessions are available for a specific release then the bounds
- should be returned as None
- """
- data = self.backend.get_release_sessions_time_bounds(
- project_id=self.project.id,
- release="different_release",
- org_id=self.organization.id,
- environments=["prod"],
- )
- assert data == {
- "sessions_lower_bound": None,
- "sessions_upper_bound": None,
- }
- def test_get_crash_free_breakdown(self):
- start = timezone.now() - timedelta(days=4)
- # it should work with and without environments
- for environments in [None, ["prod"]]:
- data = self.backend.get_crash_free_breakdown(
- project_id=self.project.id,
- release=self.session_release,
- start=start,
- environments=environments,
- )
- # Last returned date is generated within function, should be close to now:
- last_date = data[-1].pop("date")
- assert timezone.now() - last_date < timedelta(seconds=1)
- assert data == [
- {
- "crash_free_sessions": None,
- "crash_free_users": None,
- "date": start + timedelta(days=1),
- "total_sessions": 0,
- "total_users": 0,
- },
- {
- "crash_free_sessions": None,
- "crash_free_users": None,
- "date": start + timedelta(days=2),
- "total_sessions": 0,
- "total_users": 0,
- },
- {
- "crash_free_sessions": 100.0,
- "crash_free_users": 100.0,
- "total_sessions": 2,
- "total_users": 1,
- },
- ]
- data = self.backend.get_crash_free_breakdown(
- project_id=self.project.id,
- release=self.session_crashed_release,
- start=start,
- environments=["prod"],
- )
- data[-1].pop("date")
- assert data == [
- {
- "crash_free_sessions": None,
- "crash_free_users": None,
- "date": start + timedelta(days=1),
- "total_sessions": 0,
- "total_users": 0,
- },
- {
- "crash_free_sessions": None,
- "crash_free_users": None,
- "date": start + timedelta(days=2),
- "total_sessions": 0,
- "total_users": 0,
- },
- {
- "crash_free_sessions": 0.0,
- "crash_free_users": 0.0,
- "total_sessions": 1,
- "total_users": 1,
- },
- ]
- data = self.backend.get_crash_free_breakdown(
- project_id=self.project.id,
- release="non-existing",
- start=start,
- environments=["prod"],
- )
- data[-1].pop("date")
- assert data == [
- {
- "crash_free_sessions": None,
- "crash_free_users": None,
- "date": start + timedelta(days=1),
- "total_sessions": 0,
- "total_users": 0,
- },
- {
- "crash_free_sessions": None,
- "crash_free_users": None,
- "date": start + timedelta(days=2),
- "total_sessions": 0,
- "total_users": 0,
- },
- {
- "crash_free_sessions": None,
- "crash_free_users": None,
- "total_sessions": 0,
- "total_users": 0,
- },
- ]
- def test_basic_release_model_adoptions(self):
- """
- Test that the basic (project,release) data is returned
- """
- proj_id = self.project.id
- data = self.backend.get_changed_project_release_model_adoptions([proj_id])
- assert set(data) == {(proj_id, "foo@1.0.0"), (proj_id, "foo@2.0.0")}
- def test_old_release_model_adoptions(self):
- """
- Test that old entries (older that 72 h) are not returned
- """
- _100h = 100 * 60 * 60 # 100 hours in seconds
- proj_id = self.project.id
- self.store_session(
- self.build_session(
- release="foo@3.0.0",
- environment="prod",
- status="crashed",
- started=self.session_started - _100h,
- received=self.received - 3600 * 2,
- )
- )
- data = self.backend.get_changed_project_release_model_adoptions([proj_id])
- assert set(data) == {(proj_id, "foo@1.0.0"), (proj_id, "foo@2.0.0")}
- def test_multi_proj_release_model_adoptions(self):
- """Test that the api works with multiple projects"""
- proj_id = self.project.id
- new_proj_id = proj_id + 1
- self.store_session(
- self.build_session(
- project_id=new_proj_id,
- release="foo@3.0.0",
- environment="prod",
- status="crashed",
- started=self.session_started,
- received=self.received - 3600 * 2,
- )
- )
- data = self.backend.get_changed_project_release_model_adoptions([proj_id, new_proj_id])
- assert set(data) == {
- (proj_id, "foo@1.0.0"),
- (proj_id, "foo@2.0.0"),
- (new_proj_id, "foo@3.0.0"),
- }
- @staticmethod
- def _add_timestamps_to_series(series, start: datetime):
- one_day = 24 * 60 * 60
- day0 = one_day * int(start.timestamp() / one_day)
- def ts(days: int) -> int:
- return day0 + days * one_day
- return [[ts(i + 1), data] for i, data in enumerate(series)]
- def _test_get_project_release_stats(
- self, stat: OverviewStat, release: str, expected_series, expected_totals
- ):
- end = timezone.now()
- start = end - timedelta(days=4)
- stats, totals = self.backend.get_project_release_stats(
- self.project.id,
- release=release,
- stat=stat,
- rollup=86400,
- start=start,
- end=end,
- )
- # Let's not care about lists vs. tuples:
- stats = [[ts, data] for ts, data in stats]
- assert stats == self._add_timestamps_to_series(expected_series, start)
- assert totals == expected_totals
- def test_get_project_release_stats_users(self):
- self._test_get_project_release_stats(
- "users",
- self.session_release,
- [
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- {
- "duration_p50": 45.0,
- "duration_p90": 57.0,
- "users": 1,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 1,
- },
- ],
- {
- "users": 1,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 1,
- },
- )
- def test_get_project_release_stats_users_crashed(self):
- self._test_get_project_release_stats(
- "users",
- self.session_crashed_release,
- [
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 1,
- "users_abnormal": 0,
- "users_crashed": 1,
- "users_errored": 0,
- "users_healthy": 0,
- },
- ],
- {
- "users": 1,
- "users_abnormal": 0,
- "users_crashed": 1,
- "users_errored": 0,
- "users_healthy": 0,
- },
- )
- def test_get_project_release_stats_sessions(self):
- self._test_get_project_release_stats(
- "sessions",
- self.session_release,
- [
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- {
- "duration_p50": 45.0,
- "duration_p90": 57.0,
- "sessions": 2,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 2,
- },
- ],
- {
- "sessions": 2,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 2,
- },
- )
- def test_get_project_release_stats_sessions_crashed(self):
- self._test_get_project_release_stats(
- "sessions",
- self.session_crashed_release,
- [
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 1,
- "sessions_abnormal": 0,
- "sessions_crashed": 1,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- ],
- {
- "sessions": 1,
- "sessions_abnormal": 0,
- "sessions_crashed": 1,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- )
- def test_get_project_release_stats_no_sessions(self):
- """
- Test still returning correct data when no sessions are available
- :return:
- """
- self._test_get_project_release_stats(
- "sessions",
- "INEXISTENT-RELEASE",
- [
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- ],
- {
- "sessions": 0,
- "sessions_abnormal": 0,
- "sessions_crashed": 0,
- "sessions_errored": 0,
- "sessions_healthy": 0,
- },
- )
- def test_get_project_release_stats_no_users(self):
- self._test_get_project_release_stats(
- "users",
- "INEXISTENT-RELEASE",
- [
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- {
- "duration_p50": None,
- "duration_p90": None,
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- ],
- {
- "users": 0,
- "users_abnormal": 0,
- "users_crashed": 0,
- "users_errored": 0,
- "users_healthy": 0,
- },
- )
- @parametrize_backend
- class GetCrashFreeRateTestCase(TestCase, SnubaTestCase):
- """
- TestClass that tests that `get_current_and_previous_crash_free_rates` returns the correct
- `currentCrashFreeRate` and `previousCrashFreeRate` for each project
- TestData:
- Project 1:
- In the last 24h -> 2 Exited Sessions / 2 Total Sessions -> 100% Crash free rate
- In the previous 24h (>24h & <48h) -> 2 Exited + 1 Crashed Sessions / 3 Sessions -> 66.7%
- Project 2:
- In the last 24h -> 1 Exited + 1 Crashed / 2 Total Sessions -> 50% Crash free rate
- In the previous 24h (>24h & <48h) -> 0 Sessions -> None
- Project 3:
- In the last 24h -> 0 Sessions -> None
- In the previous 24h (>24h & <48h) -> 4 Exited + 1 Crashed / 5 Total Sessions -> 80%
- """
- def setUp(self):
- super().setUp()
- self.session_started = time.time() // 60 * 60
- self.session_started_gt_24_lt_48 = self.session_started - 30 * 60 * 60
- self.project2 = self.create_project(
- name="Bar2",
- slug="bar2",
- teams=[self.team],
- fire_project_created=True,
- organization=self.organization,
- )
- self.project3 = self.create_project(
- name="Bar3",
- slug="bar3",
- teams=[self.team],
- fire_project_created=True,
- organization=self.organization,
- )
- # Project 1
- for _ in range(0, 2):
- self.store_session(
- self.build_session(
- **{
- "project_id": self.project.id,
- "org_id": self.project.organization_id,
- "status": "exited",
- }
- )
- )
- for idx in range(0, 3):
- status = "exited"
- if idx == 2:
- status = "crashed"
- self.store_session(
- self.build_session(
- **{
- "project_id": self.project.id,
- "org_id": self.project.organization_id,
- "status": status,
- "started": self.session_started_gt_24_lt_48,
- }
- )
- )
- # Project 2
- for i in range(0, 2):
- status = "exited"
- if i == 1:
- status = "crashed"
- self.store_session(
- self.build_session(
- **{
- "project_id": self.project2.id,
- "org_id": self.project2.organization_id,
- "status": status,
- }
- )
- )
- # Project 3
- for i in range(0, 5):
- status = "exited"
- if i == 4:
- status = "crashed"
- self.store_session(
- self.build_session(
- **{
- "project_id": self.project3.id,
- "org_id": self.project3.organization_id,
- "status": status,
- "started": self.session_started_gt_24_lt_48,
- }
- )
- )
- def test_get_current_and_previous_crash_free_rates(self):
- now = timezone.now().replace(minute=15, second=23)
- last_24h_start = now - 24 * timedelta(hours=1)
- last_48h_start = now - 2 * 24 * timedelta(hours=1)
- data = self.backend.get_current_and_previous_crash_free_rates(
- org_id=self.organization.id,
- project_ids=[self.project.id, self.project2.id, self.project3.id],
- current_start=last_24h_start,
- current_end=now,
- previous_start=last_48h_start,
- previous_end=last_24h_start,
- rollup=3600,
- )
- assert data == {
- self.project.id: {
- "currentCrashFreeRate": 100,
- "previousCrashFreeRate": 66.66666666666667,
- },
- self.project2.id: {"currentCrashFreeRate": 50.0, "previousCrashFreeRate": None},
- self.project3.id: {"currentCrashFreeRate": None, "previousCrashFreeRate": 80.0},
- }
- def test_get_current_and_previous_crash_free_rates_with_zero_sessions(self):
- now = timezone.now().replace(minute=15, second=23)
- last_48h_start = now - 2 * 24 * timedelta(hours=1)
- last_72h_start = now - 3 * 24 * timedelta(hours=1)
- last_96h_start = now - 4 * 24 * timedelta(hours=1)
- data = self.backend.get_current_and_previous_crash_free_rates(
- org_id=self.organization.id,
- project_ids=[self.project.id],
- current_start=last_72h_start,
- current_end=last_48h_start,
- previous_start=last_96h_start,
- previous_end=last_72h_start,
- rollup=3600,
- )
- assert data == {
- self.project.id: {
- "currentCrashFreeRate": None,
- "previousCrashFreeRate": None,
- },
- }
- @region_silo_test
- @parametrize_backend
- class GetProjectReleasesCountTest(TestCase, SnubaTestCase):
- def test_empty(self):
- # Test no errors when no session data
- org = self.create_organization()
- proj = self.create_project(organization=org)
- assert (
- self.backend.get_project_releases_count(
- org.id, [proj.id], "crash_free_users", stats_period="14d"
- )
- == 0
- )
- def test_with_other_metrics(self):
- if not self.backend.is_metrics_based():
- return
- # Test no errors when no session data
- org = self.create_organization()
- proj = self.create_project(organization=org)
- # Insert a different set metric:
- for value in 1, 2, 3:
- self.store_metric(
- org_id=org.id,
- project_id=proj.id,
- name="foobarbaz", # any other metric ID
- timestamp=int(time.time()),
- tags={},
- type="set",
- value=value,
- use_case_id=UseCaseKey.RELEASE_HEALTH,
- )
- assert (
- self.backend.get_project_releases_count(
- org.id, [proj.id], "crash_free_users", stats_period="14d"
- )
- == 0
- )
- def test(self):
- project_release_1 = self.create_release(self.project)
- other_project = self.create_project()
- other_project_release_1 = self.create_release(other_project)
- self.bulk_store_sessions(
- [
- self.build_session(
- environment=self.environment.name, release=project_release_1.version
- ),
- self.build_session(
- environment="staging",
- project_id=other_project.id,
- release=other_project_release_1.version,
- ),
- ]
- )
- assert (
- self.backend.get_project_releases_count(
- self.organization.id, [self.project.id], "sessions"
- )
- == 1
- )
- assert (
- self.backend.get_project_releases_count(
- self.organization.id, [self.project.id], "users"
- )
- == 1
- )
- assert (
- self.backend.get_project_releases_count(
- self.organization.id, [self.project.id, other_project.id], "sessions"
- )
- == 2
- )
- assert (
- self.backend.get_project_releases_count(
- self.organization.id,
- [self.project.id, other_project.id],
- "users",
- )
- == 2
- )
- assert (
- self.backend.get_project_releases_count(
- self.organization.id,
- [self.project.id, other_project.id],
- "sessions",
- environments=[self.environment.name],
- )
- == 1
- )
- @parametrize_backend
- class CheckReleasesHaveHealthDataTest(TestCase, SnubaTestCase):
- def run_test(self, expected, projects, releases, start=None, end=None):
- if not start:
- start = datetime.now() - timedelta(days=1)
- if not end:
- end = datetime.now()
- assert self.backend.check_releases_have_health_data(
- self.organization.id,
- [p.id for p in projects],
- [r.version for r in releases],
- start,
- end,
- ) == {v.version for v in expected}
- def test_empty(self):
- # Test no errors when no session data
- project_release_1 = self.create_release(self.project)
- self.run_test([], [self.project], [project_release_1])
- def test(self):
- other_project = self.create_project()
- release_1 = self.create_release(
- self.project, version="1", additional_projects=[other_project]
- )
- release_2 = self.create_release(other_project, version="2")
- self.bulk_store_sessions(
- [
- self.build_session(release=release_1),
- self.build_session(project_id=other_project, release=release_1),
- self.build_session(project_id=other_project, release=release_2),
- ]
- )
- self.run_test([release_1], [self.project], [release_1])
- self.run_test([release_1], [self.project], [release_1, release_2])
- self.run_test([release_1], [other_project], [release_1])
- self.run_test([release_1, release_2], [other_project], [release_1, release_2])
- self.run_test([release_1, release_2], [self.project, other_project], [release_1, release_2])
- @parametrize_backend
- class CheckNumberOfSessions(TestCase, SnubaTestCase):
- def setUp(self):
- super().setUp()
- self.dev_env = self.create_environment(name="development", project=self.project)
- self.prod_env = self.create_environment(name="production", project=self.project)
- self.test_env = self.create_environment(name="test", project=self.project)
- self.another_project = self.create_project()
- self.third_project = self.create_project()
- # now_dt should be set to 17:40 of some day not in the future and (system time - now_dt)
- # must be less than 90 days for the metrics DB TTL
- ONE_DAY_AGO = datetime.now(tz=dt_timezone.utc) - timedelta(days=1)
- self.now_dt = ONE_DAY_AGO.replace(hour=17, minute=40, second=0)
- self._5_min_ago_dt = self.now_dt - timedelta(minutes=5)
- self._30_min_ago_dt = self.now_dt - timedelta(minutes=30)
- self._1_h_ago_dt = self.now_dt - timedelta(hours=1)
- self._2_h_ago_dt = self.now_dt - timedelta(hours=2)
- self._3_h_ago_dt = self.now_dt - timedelta(hours=3)
- self.now = self.now_dt.timestamp()
- self._5_min_ago = self._5_min_ago_dt.timestamp()
- self._30_min_ago = self._30_min_ago_dt.timestamp()
- self._1_h_ago = self._1_h_ago_dt.timestamp()
- self._2_h_ago = self._2_h_ago_dt.timestamp()
- self._3_h_ago = self._3_h_ago_dt.timestamp()
- def test_no_sessions(self):
- """
- Tests that when there are no sessions the function behaves and returns 0
- """
- actual = self.backend.get_project_sessions_count(
- project_id=self.project.id,
- environment_id=None,
- rollup=60,
- start=self._30_min_ago_dt,
- end=self.now_dt,
- )
- assert 0 == actual
- def test_sessions_in_environment(self):
- """
- Tests that it correctly picks up the sessions for the selected environment
- in the selected time, not counting other environments and other times
- """
- dev = self.dev_env.name
- prod = self.prod_env.name
- self.bulk_store_sessions(
- [
- self.build_session(
- environment=dev, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(
- environment=prod, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(
- environment=prod, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(environment=prod, received=self._2_h_ago, started=self._2_h_ago),
- ]
- )
- actual = self.backend.get_project_sessions_count(
- project_id=self.project.id,
- environment_id=self.prod_env.id,
- rollup=60,
- start=self._1_h_ago_dt,
- end=self.now_dt,
- )
- assert actual == 2
- def test_environment_without_sessions(self):
- """
- We should get zero sessions, even if the environment name has not been indexed
- by the metrics indexer.
- """
- env_without_sessions = self.create_environment(
- name="this_has_no_sessions", project=self.project
- )
- self.bulk_store_sessions(
- [
- self.build_session(
- environment=self.prod_env.name,
- received=self._5_min_ago,
- started=self._5_min_ago,
- ),
- self.build_session(
- environment=None, received=self._5_min_ago, started=self._5_min_ago
- ),
- ]
- )
- count_env_all = self.backend.get_project_sessions_count(
- project_id=self.project.id,
- environment_id=None,
- rollup=60,
- start=self._1_h_ago_dt,
- end=self.now_dt,
- )
- assert count_env_all == 2
- count_env_new = self.backend.get_project_sessions_count(
- project_id=self.project.id,
- environment_id=env_without_sessions.id,
- rollup=60,
- start=self._1_h_ago_dt,
- end=self.now_dt,
- )
- assert count_env_new == 0
- def test_sessions_in_all_environments(self):
- """
- When the environment is not specified sessions from all environments are counted
- """
- dev = self.dev_env.name
- prod = self.prod_env.name
- self.bulk_store_sessions(
- [
- self.build_session(
- environment=dev, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(
- environment=prod, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(
- environment=prod, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(environment=prod, received=self._2_h_ago, started=self._2_h_ago),
- self.build_session(environment=dev, received=self._2_h_ago, started=self._2_h_ago),
- ]
- )
- actual = self.backend.get_project_sessions_count(
- project_id=self.project.id,
- environment_id=None,
- rollup=60,
- start=self._1_h_ago_dt,
- end=self.now_dt,
- )
- assert actual == 3
- def test_sessions_from_multiple_projects(self):
- """
- Only sessions from the specified project are considered
- """
- dev = self.dev_env.name
- prod = self.prod_env.name
- self.bulk_store_sessions(
- [
- self.build_session(
- environment=dev, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(
- environment=prod, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(
- environment=prod,
- received=self._5_min_ago,
- project_id=self.another_project.id,
- started=self._5_min_ago,
- ),
- ]
- )
- actual = self.backend.get_project_sessions_count(
- project_id=self.project.id,
- environment_id=None,
- rollup=60,
- start=self._1_h_ago_dt,
- end=self.now_dt,
- )
- assert actual == 2
- def test_sessions_per_project_no_sessions(self):
- """
- Tests that no sessions are returned
- """
- actual = self.backend.get_num_sessions_per_project(
- project_ids=[self.project.id, self.another_project.id],
- environment_ids=None,
- rollup=60,
- start=self._30_min_ago_dt,
- end=self.now_dt,
- )
- assert [] == actual
- def test_sesions_per_project_multiple_projects(self):
- dev = self.dev_env.name
- prod = self.prod_env.name
- test = self.test_env.name
- p1 = self.project
- p2 = self.another_project
- p3 = self.third_project
- self.bulk_store_sessions(
- [
- # counted in p1
- self.build_session(
- environment=dev, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(
- environment=prod, received=self._5_min_ago, started=self._5_min_ago
- ),
- self.build_session(
- environment=dev, received=self._30_min_ago, started=self._30_min_ago
- ),
- # ignored in p1
- # ignored env
- self.build_session(
- environment=test, received=self._30_min_ago, started=self._30_min_ago
- ),
- # too old
- self.build_session(environment=prod, received=self._3_h_ago, started=self._3_h_ago),
- # counted in p2
- self.build_session(
- environment=dev,
- received=self._5_min_ago,
- project_id=p2.id,
- started=self._5_min_ago,
- ),
- # ignored in p2
- # ignored env
- self.build_session(
- environment=test,
- received=self._5_min_ago,
- project_id=p2.id,
- started=self._5_min_ago,
- ),
- # too old
- self.build_session(
- environment=prod,
- received=self._3_h_ago,
- project_id=p2.id,
- started=self._3_h_ago,
- ),
- # ignored p3
- self.build_session(
- environment=dev,
- received=self._5_min_ago,
- project_id=p3.id,
- started=self._5_min_ago,
- ),
- ]
- )
- actual = self.backend.get_num_sessions_per_project(
- project_ids=[self.project.id, self.another_project.id],
- environment_ids=[self.dev_env.id, self.prod_env.id],
- rollup=60,
- start=self._2_h_ago_dt,
- end=self.now_dt,
- )
- assert set(actual) == {(p1.id, 3), (p2.id, 1)}
- for eids in ([], None):
- actual = self.backend.get_num_sessions_per_project(
- project_ids=[self.project.id, self.another_project.id],
- environment_ids=eids,
- rollup=60,
- start=self._2_h_ago_dt,
- end=self.now_dt,
- )
- assert set(actual) == {(p1.id, 4), (p2.id, 2)}
- @region_silo_test(stable=True)
- @parametrize_backend
- class InitWithoutUserTestCase(TestCase, SnubaTestCase):
- def setUp(self):
- super().setUp()
- self.received = time.time()
- self.session_started = time.time() // 60 * 60
- self.session_release = "foo@1.0.0"
- session_1 = "5d52fd05-fcc9-4bf3-9dc9-267783670341"
- session_2 = "5e910c1a-6941-460e-9843-24103fb6a63c"
- session_3 = "a148c0c5-06a2-423b-8901-6b43b812cf82"
- user_1 = "39887d89-13b2-4c84-8c23-5d13d2102666"
- user_2 = "39887d89-13b2-4c84-8c23-5d13d2102667"
- user_3 = "39887d89-13b2-4c84-8c23-5d13d2102668"
- self.bulk_store_sessions(
- [
- self.build_session(
- distinct_id=user_1,
- session_id=session_1,
- status="exited",
- release=self.session_release,
- environment="prod",
- started=self.session_started,
- received=self.received,
- ),
- self.build_session(
- distinct_id=user_2,
- session_id=session_2,
- status="crashed",
- release=self.session_release,
- environment="prod",
- started=self.session_started,
- received=self.received,
- ),
- # session_3 initial update: no user ID
- self.build_session(
- distinct_id=None,
- session_id=session_3,
- status="ok",
- seq=0,
- release=self.session_release,
- environment="prod",
- started=self.session_started,
- received=self.received,
- ),
- # session_3 subsequent update: user ID is here!
- self.build_session(
- distinct_id=user_3,
- session_id=session_3,
- status="ok",
- seq=123,
- release=self.session_release,
- environment="prod",
- started=self.session_started,
- received=self.received,
- ),
- ]
- )
- def test_get_release_adoption(self):
- data = self.backend.get_release_adoption(
- [
- (self.project.id, self.session_release),
- ]
- )
- inner = data[(self.project.id, self.session_release)]
- assert inner["users_24h"] == 3
- def test_get_release_health_data_overview_users(self):
- data = self.backend.get_release_health_data_overview(
- [
- (self.project.id, self.session_release),
- ],
- summary_stats_period="24h",
- health_stats_period="24h",
- stat="users",
- )
- inner = data[(self.project.id, self.session_release)]
- assert inner["total_users"] == 3
- assert inner["total_users_24h"] == 3
- assert inner["crash_free_users"] == 66.66666666666667
- assert inner["total_project_users_24h"] == 3
- def test_get_crash_free_breakdown(self):
- start = timezone.now() - timedelta(days=4)
- data = self.backend.get_crash_free_breakdown(
- project_id=self.project.id,
- release=self.session_release,
- start=start,
- environments=["prod"],
- )
- # Last returned date is generated within function, should be close to now:
- last_date = data[-1].pop("date")
- assert timezone.now() - last_date < timedelta(seconds=1)
- assert data == [
- {
- "crash_free_sessions": None,
- "crash_free_users": None,
- "date": start + timedelta(days=1),
- "total_sessions": 0,
- "total_users": 0,
- },
- {
- "crash_free_sessions": None,
- "crash_free_users": None,
- "date": start + timedelta(days=2),
- "total_sessions": 0,
- "total_users": 0,
- },
- {
- "crash_free_sessions": 66.66666666666667,
- "crash_free_users": 66.66666666666667,
- "total_sessions": 3,
- "total_users": 3,
- },
- ]
- def test_get_project_release_stats_users(self):
- end = timezone.now()
- start = end - timedelta(days=4)
- stats, totals = self.backend.get_project_release_stats(
- self.project.id,
- release=self.session_release,
- stat="users",
- rollup=86400,
- start=start,
- end=end,
- )
- assert stats[3][1] == {
- "duration_p50": 60.0,
- "duration_p90": 60.0,
- "users": 3,
- "users_abnormal": 0,
- "users_crashed": 1,
- "users_errored": 0,
- "users_healthy": 2,
- }
|