Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(204)

Side by Side Diff: appengine/findit/waterfall/send_notification_for_culprit_pipeline.py

Issue 2075423002: [Findit] Group failures by culprit and send notification to codereview. (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 import logging
6 import textwrap
7
8 from google.appengine.ext import ndb
9
10 from common.git_repository import GitRepository
11 from common.http_client_appengine import HttpClientAppengine as HttpClient
12 from common.pipeline_wrapper import BasePipeline
13 from common.rietveld import Rietveld
14 from model import analysis_status as status
15 from model.wf_culprit import WfCulprit
16
17
18 @ndb.transactional
19 def _ShouldSendNotification(
20 master_name, builder_name, build_number, repo_name, revision):
21 """Returns True if a notification for the culprit should be sent."""
22 culprit = WfCulprit.Get(repo_name, revision)
lijeffrey 2016/06/21 00:07:35 nit: how about culprit = WfCulprit.Get(repo_name,
stgao 2016/06/21 15:14:29 Good idea! Done.
23 if not culprit:
24 culprit = WfCulprit.Create(repo_name, revision)
25 if [master_name, builder_name, build_number] in culprit.failed_builds:
26 return False
27
28 culprit.failed_builds.append([master_name, builder_name, build_number])
29 # Send notification when the culprit is for 2+ failures in two different
30 # builds to avoid false positive due to flakiness.
chanli 2016/06/21 17:50:31 Do you have data to back up this idea? What percen
stgao 2016/06/24 16:10:28 This is from data in the InCorrect-Found. Only one
chanli 2016/06/24 23:42:38 I'm not sure about it: I can see quite several cas
31 should_send = len(culprit.failed_builds) >= 2 # TODO(stgao): move to config.
lijeffrey 2016/06/21 00:07:34 is it possible to merge these 2? i.e. should_sen
stgao 2016/06/21 15:14:29 Done.
32 if culprit.notification_status in (status.COMPLETED, status.RUNNING):
33 should_send = False # Already being processed by another pipeline.
34 if should_send:
35 culprit.notification_status = status.RUNNING
36 culprit.put()
37 return should_send
38
39
40 @ndb.transactional
41 def _UpdateNotificationStatus(repo_name, revision, new_status):
42 culprit = WfCulprit.Get(repo_name, revision)
43 culprit.notification_status = new_status
44 culprit.put()
45
46
47 def _SendNotificationForCulprit(repo_name, revision):
48 # TODO(stgao): get repo url at runtime based on the given repo name.
49 repo = GitRepository(
50 'https://chromium.googlesource.com/chromium/src.git', HttpClient())
51 change_log = repo.GetChangeLog(revision)
52 sent = False
53 if change_log.code_review_url:
54 # Occasionally, a commit was not uploaded for code-review.
55 culprit = WfCulprit.Get(repo_name, revision)
56 rietveld = Rietveld()
57 message = textwrap.dedent("""
58 Findit Try-job identified this CL (revision %s) as the culprit for failures
59 in the build cycle(s) as shown on:
60 https://findit-for-me.appspot.com/waterfall/culprit?key=%s
61 """) % (revision, culprit.key().urlsafe())
62 sent = rietveld.PostMessage(change_log.code_review_url, message)
63 else:
64 logging.error('Can not get code-review url for %s/%s', repo_name, revision)
65
66 _UpdateNotificationStatus(repo_name, revision,
67 status.COMPLETED if sent else status.ERROR)
68 return sent
69
70
71 class SendNotificationForCulpritPipeline(BasePipeline):
72
73 # Arguments number differs from overridden method - pylint: disable=W0221
74 def run(self, master_name, builder_name, build_number, repo_name, revision):
75 if not _ShouldSendNotification(
76 master_name, builder_name, build_number, repo_name, revision):
77 return False
78 return _SendNotificationForCulprit(
79 master_name, builder_name, build_number, repo_name, revision)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698