Ejemplo n.º 1
0
    def test_status_report_duplicate_distinct_ids(self) -> None:
        create_person_distinct_id(self.team.id, "duplicate_id1", str(UUIDT()))
        create_person_distinct_id(self.team.id, "duplicate_id1", str(UUIDT()))
        create_person_distinct_id(self.team.id, "duplicate_id2", str(UUIDT()))
        create_person_distinct_id(self.team.id, "duplicate_id2", str(UUIDT()))
        create_person_distinct_id(self.team.id, "duplicate_id2", str(UUIDT()))

        for index in range(0, 2):
            sync_execute(
                "INSERT INTO person_distinct_id SELECT %(distinct_id)s, %(person_id)s, %(team_id)s, 1, %(timestamp)s, 0 VALUES",
                {
                    "distinct_id": "duplicate_id_old",
                    "person_id": str(UUIDT()),
                    "team_id": self.team.id,
                    "timestamp": "2020-01-01 12:01:0%s" % index,
                },
            )

        report = status_report(dry_run=True).get("teams")[self.team.id]  # type: ignore

        duplicate_ids_report = report["duplicate_distinct_ids"]

        expected_result = {
            "prev_total_ids_with_duplicates": 1,
            "prev_total_extra_distinct_id_rows": 1,
            "new_total_ids_with_duplicates": 2,
            "new_total_extra_distinct_id_rows": 4,
        }

        self.assertEqual(duplicate_ids_report, expected_result)
Ejemplo n.º 2
0
    def test_status_report(self) -> None:
        report = status_report(dry_run=True)

        self.assertEqual(report["posthog_version"], VERSION)
        self.assertEqual(report["deployment"], "tests")
        self.assertLess(report["table_sizes"]["posthog_event"], 10 ** 7)  # <10MB
        self.assertLess(report["table_sizes"]["posthog_sessionrecordingevent"], 10 ** 7)  # <10MB
Ejemplo n.º 3
0
    def test_status_report_multiple_ids_per_person(self) -> None:
        person_id1 = str(UUIDT())
        person_id2 = str(UUIDT())

        create_person_distinct_id(self.team.id, "id1", person_id1)
        create_person_distinct_id(self.team.id, "id2", person_id1)
        create_person_distinct_id(self.team.id, "id3", person_id1)
        create_person_distinct_id(self.team.id, "id4", person_id1)
        create_person_distinct_id(self.team.id, "id5", person_id1)

        create_person_distinct_id(self.team.id, "id6", person_id2)
        create_person_distinct_id(self.team.id, "id7", person_id2)
        create_person_distinct_id(self.team.id, "id8", person_id2)

        report = status_report(
            dry_run=True).get("teams")[self.team.id]  # type: ignore

        multiple_ids_report = report["multiple_ids_per_person"]

        expected_result = {
            "total_persons_with_more_than_2_ids": 2,
            "max_distinct_ids_for_one_person": 5,
        }

        self.assertEqual(multiple_ids_report, expected_result)
Ejemplo n.º 4
0
    def test_team_status_report_event_counts(self) -> None:
        with freeze_time("2020-11-02"):
            self.create_person("old_user1")
            self.create_person("old_user2")

        with freeze_time("2020-11-10"):
            self.create_person("new_user1")
            self.create_person("new_user2")
            self.create_event("new_user1", "$event1", "$web",
                              now() - relativedelta(weeks=1, hours=2))
            self.create_event("new_user1", "$event2", "$web",
                              now() - relativedelta(weeks=1, hours=1))
            self.create_event("new_user1", "$event2", "$mobile",
                              now() - relativedelta(weeks=1, hours=1))
            self.create_event("new_user1", "$event3", "$mobile",
                              now() - relativedelta(weeks=5))

            team_report = status_report(
                dry_run=True).get("teams")[self.team.id]  # type: ignore

            self.assertEqual(team_report["events_count_total"], 4)
            self.assertEqual(team_report["events_count_new_in_period"], 3)
            self.assertEqual(team_report["events_count_by_lib"], {
                "$mobile": 1,
                "$web": 2
            })
            self.assertEqual(team_report["events_count_by_name"], {
                "$event1": 1,
                "$event2": 2
            })

            self.assertEqual(team_report["persons_count_total"], 4)
            self.assertEqual(team_report["persons_count_new_in_period"], 2)
            self.assertEqual(team_report["persons_count_active_in_period"], 1)
Ejemplo n.º 5
0
        def test_status_report_plugins(self) -> None:
            self._create_plugin("Installed but not enabled", False)
            self._create_plugin("Installed and enabled", True)
            report = status_report(dry_run=True)

            self.assertEqual(report["plugins_installed"], {
                "Installed but not enabled": 1,
                "Installed and enabled": 1
            })
            self.assertEqual(report["plugins_enabled"],
                             {"Installed and enabled": 1})
Ejemplo n.º 6
0
def status_report():
    from posthog.tasks.status_report import status_report

    status_report()
Ejemplo n.º 7
0
        def test_instance_status_report_event_counts(self) -> None:
            with freeze_time("2020-11-02"):
                _create_person("old_user1", team=self.team)
                _create_person("old_user2", team=self.team)

            with freeze_time("2020-11-10"):
                _create_person("new_user1", team=self.team)
                _create_person("new_user2", team=self.team)
                _create_event("new_user1",
                              "$event1",
                              "$web",
                              now() - relativedelta(weeks=1, hours=2),
                              team=self.team)
                _create_event("new_user1",
                              "$event2",
                              "$web",
                              now() - relativedelta(weeks=1, hours=1),
                              team=self.team)
                _create_event("new_user1",
                              "$event2",
                              "$mobile",
                              now() - relativedelta(weeks=1, hours=1),
                              team=self.team)
                _create_event("new_user1",
                              "$event3",
                              "$mobile",
                              now() - relativedelta(weeks=5),
                              team=self.team)

                team_report = status_report(
                    dry_run=True).get("teams")[self.team.id]  # type: ignore

                def _test_team_report() -> None:
                    self.assertEqual(team_report["events_count_total"], 4)
                    self.assertEqual(team_report["events_count_new_in_period"],
                                     3)
                    self.assertEqual(team_report["events_count_by_lib"], {
                        "$mobile": 1,
                        "$web": 2
                    })
                    self.assertEqual(team_report["events_count_by_name"], {
                        "$event1": 1,
                        "$event2": 2
                    })
                    self.assertEqual(team_report["persons_count_total"], 4)
                    self.assertEqual(
                        team_report["persons_count_new_in_period"], 2)

                _test_team_report()

                # Create usage in a different org.
                team_in_other_org = self.create_new_org_and_team()
                _create_person("new_user1", team=team_in_other_org)
                _create_person("new_user2", team=team_in_other_org)
                _create_event("new_user1",
                              "$event1",
                              "$web",
                              now() - relativedelta(weeks=1, hours=2),
                              team=team_in_other_org)

                # Make sure the original team report is unchanged
                _test_team_report()

                instance_usage_summary = status_report(
                    dry_run=True).get("instance_usage_summary")
                self.assertEqual(
                    instance_usage_summary[
                        "events_count_new_in_period"],  # type: ignore
                    team_report["events_count_new_in_period"] + 1,
                )
                self.assertEqual(
                    instance_usage_summary[
                        "events_count_total"],  # type: ignore
                    team_report["events_count_total"] + 1,
                )
                self.assertEqual(
                    instance_usage_summary[
                        "persons_count_total"],  # type: ignore
                    team_report["persons_count_total"] + 2,
                )
                self.assertEqual(
                    instance_usage_summary[
                        "persons_count_new_in_period"],  # type: ignore
                    team_report["persons_count_new_in_period"],
                )
                # Create an event before and after this current period
                _create_event("new_user1",
                              "$eventBefore",
                              "$web",
                              now() + relativedelta(weeks=2, hours=2),
                              team=self.team)
                _create_event("new_user1",
                              "$eventAfter",
                              "$web",
                              now() - relativedelta(weeks=2, hours=2),
                              team=self.team)

                updated_team_report = status_report(
                    dry_run=True).get("teams")[self.team.id]  # type: ignore
                updated_instance_usage_summary = status_report(
                    dry_run=True).get("instance_usage_summary")

                # Check event totals are updated
                self.assertEqual(
                    updated_team_report["events_count_total"],
                    team_report["events_count_total"] + 2,
                )
                self.assertEqual(
                    updated_instance_usage_summary[
                        "events_count_total"],  # type: ignore
                    instance_usage_summary["events_count_total"] +
                    2,  # type: ignore
                )

                # Check event usage in current period is unchanged
                self.assertEqual(
                    updated_team_report["events_count_new_in_period"],
                    team_report["events_count_new_in_period"])
                self.assertEqual(
                    updated_instance_usage_summary[
                        "events_count_new_in_period"],  # type: ignore
                    instance_usage_summary[
                        "events_count_new_in_period"],  # type: ignore
                )

                # Create an internal metrics org
                internal_metrics_team = self.create_new_org_and_team(
                    for_internal_metrics=True)
                _create_person("new_user1", team=internal_metrics_team)
                _create_event("new_user1",
                              "$event1",
                              "$web",
                              now() - relativedelta(weeks=1, hours=2),
                              team=internal_metrics_team)
                _create_event("new_user1",
                              "$event2",
                              "$web",
                              now() - relativedelta(weeks=1, hours=2),
                              team=internal_metrics_team)
                _create_event("new_user1",
                              "$event3",
                              "$web",
                              now() - relativedelta(weeks=1, hours=2),
                              team=internal_metrics_team)
                # Verify that internal metrics events are not counted
                self.assertEqual(
                    status_report(dry_run=True).get("teams")[self.team.id]
                    ["events_count_total"],  # type: ignore
                    updated_team_report["events_count_total"],
                )
                self.assertEqual(
                    status_report(dry_run=True).get("instance_usage_summary")
                    ["events_count_total"],  # type: ignore
                    updated_instance_usage_summary[
                        "events_count_total"],  # type: ignore
                )
Ejemplo n.º 8
0
 def test_sttus_report(self) -> None:
     with freeze_time("2020-01-04T13:01:01Z"):
         status_report(dry_run=True)