Beispiel #1
0
def calculate_incident_suspects(incident_id):
    from sentry.incidents.logic import get_incident_suspect_commits

    lock = locks.get(u'incident:suspects:{}'.format(incident_id), duration=60 * 10)
    with TimedRetryPolicy(60)(lock.acquire):
        incident = Incident.objects.get(id=incident_id)
        suspect_commits = get_incident_suspect_commits(incident)
        with transaction.atomic():
            IncidentSuspectCommit.objects.filter(incident=incident).delete()
            IncidentSuspectCommit.objects.bulk_create([
                IncidentSuspectCommit(incident=incident, commit_id=commit_id, order=i)
                for i, commit_id in enumerate(suspect_commits)
            ])
Beispiel #2
0
    def test_simple(self):
        release = self.create_release(project=self.project, version="v12")

        included_commits = set([letter * 40 for letter in ("a", "b", "c", "d")])
        commit_iter = iter(included_commits)

        one_min_ago = iso_format(before_now(minutes=1))
        event = self.store_event(
            data={
                "fingerprint": ["group-1"],
                "message": "Kaboom!",
                "platform": "python",
                "stacktrace": {
                    "frames": [
                        {"filename": "sentry/tasks.py"},
                        {"filename": "sentry/models/release.py"},
                    ]
                },
                "release": release.version,
                "timestamp": one_min_ago,
            },
            project_id=self.project.id,
        )
        group = event.group
        self.repo = Repository.objects.create(
            organization_id=self.organization.id, name=self.organization.id
        )
        release.set_commits(
            [
                {
                    "id": next(commit_iter),
                    "repository": self.repo.name,
                    "author_email": "*****@*****.**",
                    "author_name": "Bob",
                    "message": "i fixed a bug",
                    "patch_set": [{"path": "src/sentry/models/release.py", "type": "M"}],
                },
                {
                    "id": next(commit_iter),
                    "repository": self.repo.name,
                    "author_email": "*****@*****.**",
                    "author_name": "Bob",
                    "message": "i fixed a bug",
                    "patch_set": [{"path": "src/sentry/models/release.py", "type": "M"}],
                },
                {
                    "id": next(commit_iter),
                    "repository": self.repo.name,
                    "author_email": "*****@*****.**",
                    "author_name": "Ross",
                    "message": "i fixed a bug",
                    "patch_set": [{"path": "src/sentry/models/release.py", "type": "M"}],
                },
            ]
        )
        release_2 = self.create_release(project=self.project, version="v13")
        event_2 = self.store_event(
            data={
                "fingerprint": ["group-2"],
                "message": "Kaboom!",
                "platform": "python",
                "stacktrace": {
                    "frames": [
                        {"filename": "sentry/tasks.py"},
                        {"filename": "sentry/models/group.py"},
                    ]
                },
                "release": release_2.version,
                "timestamp": one_min_ago,
            },
            project_id=self.project.id,
        )
        group_2 = event_2.group
        excluded_id = "z" * 40
        release_2.set_commits(
            [
                {
                    "id": next(commit_iter),
                    "repository": self.repo.name,
                    "author_email": "*****@*****.**",
                    "author_name": "Hello",
                    "message": "i fixed a bug",
                    "patch_set": [{"path": "src/sentry/models/group.py", "type": "M"}],
                },
                {
                    "id": excluded_id,
                    "repository": self.repo.name,
                    "author_email": "*****@*****.**",
                    "author_name": "Hello",
                    "message": "i fixed a bug",
                    "patch_set": [{"path": "src/sentry/models/not_group.py", "type": "M"}],
                },
            ]
        )

        commit_ids = (
            Commit.objects.filter(releasecommit__release__in=[release, release_2])
            .exclude(key=excluded_id)
            .values_list("id", flat=True)
        )
        incident = self.create_incident(self.organization, groups=[group, group_2])
        assert set(get_incident_suspect_commits(incident)) == set(commit_ids)
Beispiel #3
0
    def test_simple(self):
        release = self.create_release(project=self.project, version='v12')

        included_commits = set(
            [letter * 40 for letter in ('a', 'b', 'c', 'd')])
        commit_iter = iter(included_commits)

        one_min_ago = (timezone.now() - timedelta(minutes=1)).isoformat()[:19]
        event = self.store_event(
            data={
                'fingerprint': ['group-1'],
                'message': 'Kaboom!',
                'platform': 'python',
                'stacktrace': {
                    'frames': [
                        {
                            'filename': 'sentry/tasks.py'
                        },
                        {
                            'filename': 'sentry/models/release.py'
                        },
                    ]
                },
                'release': release.version,
                'timestamp': one_min_ago,
            },
            project_id=self.project.id,
        )
        group = event.group
        self.repo = Repository.objects.create(
            organization_id=self.organization.id,
            name=self.organization.id,
        )
        release.set_commits([
            {
                'id':
                next(commit_iter),
                'repository':
                self.repo.name,
                'author_email':
                '*****@*****.**',
                'author_name':
                'Bob',
                'message':
                'i fixed a bug',
                'patch_set': [{
                    'path': 'src/sentry/models/release.py',
                    'type': 'M'
                }]
            },
            {
                'id':
                next(commit_iter),
                'repository':
                self.repo.name,
                'author_email':
                '*****@*****.**',
                'author_name':
                'Bob',
                'message':
                'i fixed a bug',
                'patch_set': [{
                    'path': 'src/sentry/models/release.py',
                    'type': 'M'
                }]
            },
            {
                'id':
                next(commit_iter),
                'repository':
                self.repo.name,
                'author_email':
                '*****@*****.**',
                'author_name':
                'Ross',
                'message':
                'i fixed a bug',
                'patch_set': [{
                    'path': 'src/sentry/models/release.py',
                    'type': 'M'
                }]
            },
        ])
        release_2 = self.create_release(project=self.project, version='v13')
        event_2 = self.store_event(
            data={
                'fingerprint': ['group-2'],
                'message': 'Kaboom!',
                'platform': 'python',
                'stacktrace': {
                    'frames': [
                        {
                            'filename': 'sentry/tasks.py'
                        },
                        {
                            'filename': 'sentry/models/group.py'
                        },
                    ],
                },
                'release': release_2.version,
                'timestamp': one_min_ago,
            },
            project_id=self.project.id,
        )
        group_2 = event_2.group
        excluded_id = 'z' * 40
        release_2.set_commits([
            {
                'id': next(commit_iter),
                'repository': self.repo.name,
                'author_email': '*****@*****.**',
                'author_name': 'Hello',
                'message': 'i fixed a bug',
                'patch_set': [{
                    'path': 'src/sentry/models/group.py',
                    'type': 'M'
                }]
            },
            {
                'id':
                excluded_id,
                'repository':
                self.repo.name,
                'author_email':
                '*****@*****.**',
                'author_name':
                'Hello',
                'message':
                'i fixed a bug',
                'patch_set': [{
                    'path': 'src/sentry/models/not_group.py',
                    'type': 'M'
                }]
            },
        ])

        commit_ids = Commit.objects.filter(releasecommit__release__in=[
            release, release_2
        ], ).exclude(key=excluded_id).values_list('id', flat=True)
        incident = self.create_incident(
            self.organization,
            groups=[group, group_2],
        )
        assert set(get_incident_suspect_commits(incident)) == set(commit_ids)