Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from datetime import datetime | 5 from datetime import datetime |
| 6 import logging | 6 import logging |
| 7 import textwrap | 7 import textwrap |
| 8 | 8 |
| 9 from google.appengine.ext import ndb | 9 from google.appengine.ext import ndb |
| 10 | 10 |
| 11 from common import time_util | 11 from common import time_util |
| 12 from common.git_repository import GitRepository | 12 from common.git_repository import GitRepository |
| 13 from common.http_client_appengine import HttpClientAppengine as HttpClient | 13 from common.http_client_appengine import HttpClientAppengine as HttpClient |
| 14 from common.pipeline_wrapper import BasePipeline | 14 from common.pipeline_wrapper import BasePipeline |
| 15 from common.rietveld import Rietveld | 15 from common.rietveld import Rietveld |
| 16 from model import analysis_status as status | 16 from model import analysis_status as status |
| 17 from model.wf_analysis import WfAnalysis | |
| 17 from model.wf_culprit import WfCulprit | 18 from model.wf_culprit import WfCulprit |
| 18 from waterfall import build_util | 19 from waterfall import build_util |
| 19 from waterfall import waterfall_config | 20 from waterfall import waterfall_config |
| 20 | 21 |
| 21 | 22 |
| 22 @ndb.transactional | 23 @ndb.transactional |
| 23 def _ShouldSendNotification( | 24 def _ShouldSendNotification( |
| 24 master_name, builder_name, build_number, repo_name, revision, | 25 master_name, builder_name, build_number, repo_name, revision, |
| 25 commit_position, build_num_threshold, time_limit_passed): | 26 commit_position, criteria): |
| 26 """Returns True if a notification for the culprit should be sent.""" | 27 """Returns True if a notification for the culprit should be sent.""" |
| 27 culprit = (WfCulprit.Get(repo_name, revision) or | 28 culprit = (WfCulprit.Get(repo_name, revision) or |
| 28 WfCulprit.Create(repo_name, revision, commit_position)) | 29 WfCulprit.Create(repo_name, revision, commit_position)) |
| 29 if [master_name, builder_name, build_number] in culprit.builds: | 30 if [master_name, builder_name, build_number] in culprit.builds: |
| 30 return False | 31 return False |
| 31 | 32 |
| 32 culprit.builds.append([master_name, builder_name, build_number]) | 33 culprit.builds.append([master_name, builder_name, build_number]) |
| 33 # Send notification only when: | 34 # Send notification only when: |
| 34 # 1. It was not processed yet. | 35 # 1. It was not processed yet. |
| 35 # 2. The culprit is for multiple failures in different builds to avoid false | 36 # 2. It is not too late after the culprit was committed. |
| 36 # positive due to flakiness. | |
| 37 # 3. It is not too late after the culprit was committed. | |
| 38 # * Try-job takes too long to complete and the failure got fixed. | 37 # * Try-job takes too long to complete and the failure got fixed. |
| 39 # * The whole analysis was rerun a long time after the failure occurred. | 38 # * The whole analysis was rerun a long time after the failure occurred. |
| 40 should_send = not (culprit.cr_notification_processed or | 39 should_send = not (culprit.cr_notification_processed or |
| 41 len(culprit.builds) < build_num_threshold or | 40 criteria['time_limit_passed']) |
|
lijeffrey
2016/09/02 06:37:34
nit: since criteria will eventually contain multip
chanli
2016/09/02 16:57:19
Done.
| |
| 42 time_limit_passed) | |
| 43 if should_send: | 41 if should_send: |
| 44 culprit.cr_notification_status = status.RUNNING | 42 culprit.cr_notification_status = status.RUNNING |
| 45 culprit.put() | 43 culprit.put() |
| 46 return should_send | 44 return should_send |
| 47 | 45 |
| 48 | 46 |
| 49 @ndb.transactional | 47 @ndb.transactional |
| 50 def _UpdateNotificationStatus(repo_name, revision, new_status): | 48 def _UpdateNotificationStatus(repo_name, revision, new_status): |
| 51 culprit = WfCulprit.Get(repo_name, revision) | 49 culprit = WfCulprit.Get(repo_name, revision) |
| 52 culprit.cr_notification_status = new_status | 50 culprit.cr_notification_status = new_status |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 latency_seconds = (time_util.GetUTCNow() - build_end_time).total_seconds() | 89 latency_seconds = (time_util.GetUTCNow() - build_end_time).total_seconds() |
| 92 return latency_seconds > latency_limit_minutes * 60 | 90 return latency_seconds > latency_limit_minutes * 60 |
| 93 | 91 |
| 94 | 92 |
| 95 class SendNotificationForCulpritPipeline(BasePipeline): | 93 class SendNotificationForCulpritPipeline(BasePipeline): |
| 96 | 94 |
| 97 # Arguments number differs from overridden method - pylint: disable=W0221 | 95 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 98 def run(self, master_name, builder_name, build_number, repo_name, revision): | 96 def run(self, master_name, builder_name, build_number, repo_name, revision): |
| 99 action_settings = waterfall_config.GetActionSettings() | 97 action_settings = waterfall_config.GetActionSettings() |
| 100 # Set some impossible default values to prevent notification by default. | 98 # Set some impossible default values to prevent notification by default. |
| 101 build_threshold = action_settings.get( | |
| 102 'cr_notification_build_threshold', 100000) | |
| 103 latency_limit_minutes = action_settings.get( | 99 latency_limit_minutes = action_settings.get( |
| 104 'cr_notification_latency_limit_minutes', 1) | 100 'cr_notification_latency_limit_minutes', 1) |
| 105 | 101 |
| 106 commit_position, code_review_url = _GetCulpritInfo( | 102 commit_position, code_review_url = _GetCulpritInfo( |
| 107 repo_name, revision) | 103 repo_name, revision) |
| 108 build_end_time = build_util.GetBuildEndTime( | 104 build_end_time = build_util.GetBuildEndTime( |
| 109 master_name, builder_name, build_number) | 105 master_name, builder_name, build_number) |
| 110 time_limit_passed = _NotificationTimeLimitPassed( | 106 time_limit_passed = _NotificationTimeLimitPassed( |
| 111 build_end_time, latency_limit_minutes) | 107 build_end_time, latency_limit_minutes) |
| 112 | 108 |
| 109 # criteria are additional parameters that will help decide if a notification | |
| 110 # should be sent. | |
| 111 # TODO (chanli): Add check for if confidence for the culprit is | |
| 112 # over threshold. | |
| 113 criteria = { | |
|
lijeffrey
2016/09/02 06:37:34
nit: since criteria is a dict of additional parame
chanli
2016/09/02 16:57:19
Changed to additional_criteria
| |
| 114 'time_limit_passed': time_limit_passed | |
| 115 } | |
| 116 | |
| 113 if not _ShouldSendNotification( | 117 if not _ShouldSendNotification( |
| 114 master_name, builder_name, build_number, repo_name, | 118 master_name, builder_name, build_number, repo_name, |
| 115 revision, commit_position, build_threshold, time_limit_passed): | 119 revision, commit_position, criteria): |
| 116 return False | 120 return False |
| 117 return _SendNotificationForCulprit( | 121 return _SendNotificationForCulprit( |
| 118 repo_name, revision, commit_position, code_review_url) | 122 repo_name, revision, commit_position, code_review_url) |
| OLD | NEW |