|
58 | 58 | from sentry.integrations.models.data_forwarder_project import DataForwarderProject |
59 | 59 | from sentry.integrations.models.integration import Integration |
60 | 60 | from sentry.integrations.models.organization_integration import OrganizationIntegration |
| 61 | +from sentry.investigations.models import ( |
| 62 | + Investigation, |
| 63 | + InvestigationCell, |
| 64 | + InvestigationCellComment, |
| 65 | + InvestigationCellDependency, |
| 66 | + InvestigationCellExecution, |
| 67 | + InvestigationCellExecutionProject, |
| 68 | + InvestigationCellParameter, |
| 69 | + InvestigationCellReaction, |
| 70 | + InvestigationCommentReaction, |
| 71 | + InvestigationCommentTeamMention, |
| 72 | + InvestigationCommentUserMention, |
| 73 | + InvestigationFavoriteUser, |
| 74 | + InvestigationParameter, |
| 75 | + InvestigationPermissions, |
| 76 | + InvestigationPermissionsTeam, |
| 77 | + InvestigationProject, |
| 78 | +) |
61 | 79 | from sentry.models.activity import Activity |
62 | 80 | from sentry.models.apiauthorization import ApiAuthorization |
63 | 81 | from sentry.models.apidevicecode import ApiDeviceCode |
@@ -841,6 +859,105 @@ def create_exhaustive_organization( |
841 | 859 | overrides={"write_key": "test_override_write_key"}, |
842 | 860 | ) |
843 | 861 |
|
| 862 | + investigation = Investigation.objects.create( |
| 863 | + organization=org, |
| 864 | + created_by_id=owner_id, |
| 865 | + title=f"Investigation in {slug}", |
| 866 | + status="archived", |
| 867 | + template_key="breached_metric", |
| 868 | + template_version=2, |
| 869 | + source_type="breached_metric", |
| 870 | + source_ref={"groupId": str(group.id)}, |
| 871 | + filters={"environment": ["production"]}, |
| 872 | + version=2, |
| 873 | + ) |
| 874 | + InvestigationProject.objects.create(investigation=investigation, project=project) |
| 875 | + InvestigationFavoriteUser.objects.create(investigation=investigation, user_id=owner_id) |
| 876 | + investigation_permissions = InvestigationPermissions.objects.create( |
| 877 | + investigation=investigation, |
| 878 | + is_editable_by_everyone=False, |
| 879 | + ) |
| 880 | + InvestigationPermissionsTeam.objects.create( |
| 881 | + permissions=investigation_permissions, team=team |
| 882 | + ) |
| 883 | + parameter = InvestigationParameter.objects.create( |
| 884 | + investigation=investigation, |
| 885 | + key="environment", |
| 886 | + label="Environment", |
| 887 | + description="Environment filter", |
| 888 | + type="string", |
| 889 | + required=True, |
| 890 | + constraints={"maxLength": 64}, |
| 891 | + default_value="development", |
| 892 | + saved_value="production", |
| 893 | + source="user", |
| 894 | + position=1, |
| 895 | + version=2, |
| 896 | + ) |
| 897 | + upstream_cell = InvestigationCell.objects.create( |
| 898 | + investigation=investigation, |
| 899 | + created_by_id=owner_id, |
| 900 | + last_edited_by_id=owner_id, |
| 901 | + position=1, |
| 902 | + kind="text", |
| 903 | + title="Upstream", |
| 904 | + content="Upstream evidence", |
| 905 | + prompt="Create evidence", |
| 906 | + generated_content="Generated evidence", |
| 907 | + config={"language": "markdown"}, |
| 908 | + display={"type": "markdown"}, |
| 909 | + version=2, |
| 910 | + stale_at=timezone.now(), |
| 911 | + deleted_at=timezone.now(), |
| 912 | + ) |
| 913 | + cell = InvestigationCell.objects.create( |
| 914 | + investigation=investigation, |
| 915 | + created_by_id=owner_id, |
| 916 | + last_edited_by_id=owner_id, |
| 917 | + position=2, |
| 918 | + kind="query", |
| 919 | + title="Query", |
| 920 | + content="count()", |
| 921 | + prompt="Build a query", |
| 922 | + generated_content="count()", |
| 923 | + config={"dataset": "spans"}, |
| 924 | + display={"type": "table"}, |
| 925 | + version=2, |
| 926 | + stale_at=timezone.now(), |
| 927 | + deleted_at=timezone.now(), |
| 928 | + ) |
| 929 | + InvestigationCellDependency.objects.create(cell=cell, depends_on=upstream_cell) |
| 930 | + InvestigationCellParameter.objects.create(cell=cell, parameter=parameter) |
| 931 | + execution = InvestigationCellExecution.objects.create( |
| 932 | + cell=cell, |
| 933 | + triggered_by_id=owner_id, |
| 934 | + executor="code_mode", |
| 935 | + status="completed", |
| 936 | + cell_version=2, |
| 937 | + input_snapshot={"environment": "production"}, |
| 938 | + input_fingerprint="f" * 64, |
| 939 | + result_schema_version=2, |
| 940 | + result={"rows": [[1]]}, |
| 941 | + error={"previous": "transient"}, |
| 942 | + started_at=timezone.now(), |
| 943 | + completed_at=timezone.now(), |
| 944 | + ) |
| 945 | + InvestigationCellExecutionProject.objects.create(execution=execution, project=project) |
| 946 | + cell.current_execution = execution |
| 947 | + cell.save(update_fields=["current_execution"]) |
| 948 | + comment = InvestigationCellComment.objects.create( |
| 949 | + cell=cell, |
| 950 | + author_id=owner_id, |
| 951 | + body="Please review this result", |
| 952 | + deleted_at=timezone.now(), |
| 953 | + ) |
| 954 | + InvestigationCellReaction.objects.create(cell=cell, user_id=owner_id, reaction="heart") |
| 955 | + InvestigationCommentReaction.objects.create( |
| 956 | + comment=comment, user_id=owner_id, reaction="eyes" |
| 957 | + ) |
| 958 | + InvestigationCommentUserMention.objects.create(comment=comment, user_id=owner_id) |
| 959 | + InvestigationCommentTeamMention.objects.create(comment=comment, team=team) |
| 960 | + |
844 | 961 | return org |
845 | 962 |
|
846 | 963 | @assume_test_silo_mode(SiloMode.CONTROL) |
|
0 commit comments