|
7 | 7 |
|
8 | 8 | from sentry.replays.testutils import mock_replay |
9 | 9 | from sentry.search.events.constants import RELEASE_ALIAS, SEMVER_ALIAS |
| 10 | +from sentry.snuba.dataset import Dataset |
10 | 11 | from sentry.testutils.cases import APITestCase, ReplaysSnubaTestCase, SnubaTestCase |
11 | 12 | from sentry.testutils.helpers.datetime import before_now, iso_format |
12 | 13 | from sentry.utils.samples import load_data |
| 14 | +from tests.sentry.issues.test_utils import OccurrenceTestMixin |
13 | 15 |
|
14 | 16 |
|
15 | 17 | class OrganizationTagKeyTestCase(APITestCase, SnubaTestCase): |
@@ -808,3 +810,134 @@ def test_schema(self): |
808 | 810 | "name", |
809 | 811 | "value", |
810 | 812 | ] |
| 813 | + |
| 814 | + |
| 815 | +class DatasetParamOrganizationTagKeyValuesTest(OrganizationTagKeyTestCase, OccurrenceTestMixin): |
| 816 | + def setUp(self): |
| 817 | + super().setUp() |
| 818 | + |
| 819 | + def run_dataset_test(self, key, expected, dataset: Dataset, **kwargs): |
| 820 | + # all tests here require that we search in transactions so make that the default here |
| 821 | + qs_params = kwargs.get("qs_params", {}) |
| 822 | + qs_params["dataset"] = dataset.value |
| 823 | + kwargs["qs_params"] = qs_params |
| 824 | + super().run_test(key, expected, **kwargs) |
| 825 | + |
| 826 | + def test_dataset_events(self): |
| 827 | + self.store_event( |
| 828 | + data={ |
| 829 | + "event_id": "a" * 32, |
| 830 | + "tags": {"berry": "raspberry"}, |
| 831 | + "timestamp": iso_format(self.min_ago), |
| 832 | + }, |
| 833 | + project_id=self.project.id, |
| 834 | + ) |
| 835 | + self.store_event( |
| 836 | + data={ |
| 837 | + "event_id": "b" * 32, |
| 838 | + "tags": {"berry": "blueberry"}, |
| 839 | + "timestamp": iso_format(self.min_ago), |
| 840 | + }, |
| 841 | + project_id=self.project.id, |
| 842 | + ) |
| 843 | + self.store_event( |
| 844 | + data={ |
| 845 | + "event_id": "c" * 32, |
| 846 | + "tags": {"berry": "banana"}, |
| 847 | + "timestamp": iso_format(self.min_ago), |
| 848 | + }, |
| 849 | + project_id=self.project.id, |
| 850 | + ) |
| 851 | + self.store_event( |
| 852 | + data={ |
| 853 | + "event_id": "d" * 32, |
| 854 | + "tags": {"berry": "banana"}, |
| 855 | + "timestamp": iso_format(self.min_ago), |
| 856 | + }, |
| 857 | + project_id=self.project.id, |
| 858 | + ) |
| 859 | + # Should appear in Events and Discover datasets, but not IssuePlatform |
| 860 | + self.run_dataset_test( |
| 861 | + "berry", |
| 862 | + expected=[("raspberry", 1), ("blueberry", 1), ("banana", 2)], |
| 863 | + dataset=Dataset.Events, |
| 864 | + ) |
| 865 | + self.run_dataset_test( |
| 866 | + "berry", |
| 867 | + expected=[("raspberry", 1), ("blueberry", 1), ("banana", 2)], |
| 868 | + dataset=Dataset.Discover, |
| 869 | + ) |
| 870 | + self.run_dataset_test( |
| 871 | + "berry", |
| 872 | + expected=[], |
| 873 | + dataset=Dataset.IssuePlatform, |
| 874 | + ) |
| 875 | + |
| 876 | + def test_dataset_issue_platform(self): |
| 877 | + self.store_event( |
| 878 | + data={ |
| 879 | + "event_id": "a" * 32, |
| 880 | + "tags": {"stone_fruit": "peach"}, |
| 881 | + "timestamp": iso_format(self.min_ago), |
| 882 | + }, |
| 883 | + project_id=self.project.id, |
| 884 | + ) |
| 885 | + self.process_occurrence( |
| 886 | + event_id=uuid.uuid4().hex, |
| 887 | + project_id=self.project.id, |
| 888 | + event_data={ |
| 889 | + "title": "some problem", |
| 890 | + "platform": "python", |
| 891 | + "tags": {"stone_fruit": "cherry"}, |
| 892 | + "timestamp": iso_format(self.min_ago), |
| 893 | + "received": iso_format(self.min_ago), |
| 894 | + }, |
| 895 | + ) |
| 896 | + |
| 897 | + # (stone_fruit: cherry) should appear in IssuePlatform dataset, |
| 898 | + # but (sonte_fruit: peach) should not |
| 899 | + self.run_dataset_test( |
| 900 | + "stone_fruit", |
| 901 | + expected=[("cherry", 1)], |
| 902 | + dataset=Dataset.IssuePlatform, |
| 903 | + ) |
| 904 | + self.run_dataset_test( |
| 905 | + "stone_fruit", |
| 906 | + expected=[("peach", 1)], |
| 907 | + dataset=Dataset.Events, |
| 908 | + ) |
| 909 | + self.run_dataset_test( |
| 910 | + "stone_fruit", |
| 911 | + expected=[("peach", 1)], |
| 912 | + dataset=Dataset.Discover, |
| 913 | + ) |
| 914 | + |
| 915 | + def test_dataset_discover(self): |
| 916 | + event = load_data("transaction") |
| 917 | + event["tags"].extend([["fake_fruit", "tomato"]]) |
| 918 | + event.update( |
| 919 | + { |
| 920 | + "transaction": "example_transaction", |
| 921 | + "event_id": uuid.uuid4().hex, |
| 922 | + "start_timestamp": iso_format(self.min_ago), |
| 923 | + "timestamp": iso_format(self.min_ago), |
| 924 | + } |
| 925 | + ) |
| 926 | + event["measurements"]["lcp"]["value"] = 5000 |
| 927 | + self.store_event(data=event, project_id=self.project.id) |
| 928 | + |
| 929 | + self.run_dataset_test( |
| 930 | + "fake_fruit", |
| 931 | + expected=[], |
| 932 | + dataset=Dataset.IssuePlatform, |
| 933 | + ) |
| 934 | + self.run_dataset_test( |
| 935 | + "fake_fruit", |
| 936 | + expected=[], |
| 937 | + dataset=Dataset.Events, |
| 938 | + ) |
| 939 | + self.run_dataset_test( |
| 940 | + "fake_fruit", |
| 941 | + expected=[("tomato", 1)], |
| 942 | + dataset=Dataset.Discover, |
| 943 | + ) |
0 commit comments