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 |
| 23 def _PassAdditionalCriteria(additional_criteria): | |
| 24 passed = True | |
| 25 for criterion in additional_criteria.values(): | |
|
Sharu Jiang
2016/09/02 20:42:51
Sorry, just realize =_=
You just can do
for ...:
chanli
2016/09/03 01:27:02
Thought of a one liner to do this : )
| |
| 26 passed = passed and criterion | |
|
lijeffrey1
2016/09/03 00:31:53
so this is assuming every criterion must have a va
chanli
2016/09/03 01:27:02
Done.
| |
| 27 return passed | |
| 28 | |
| 29 | |
| 22 @ndb.transactional | 30 @ndb.transactional |
| 23 def _ShouldSendNotification( | 31 def _ShouldSendNotification( |
| 24 master_name, builder_name, build_number, repo_name, revision, | 32 master_name, builder_name, build_number, repo_name, revision, |
| 25 commit_position, build_num_threshold, time_limit_passed): | 33 commit_position, additional_criteria): |
| 26 """Returns True if a notification for the culprit should be sent.""" | 34 """Returns True if a notification for the culprit should be sent.""" |
| 27 culprit = (WfCulprit.Get(repo_name, revision) or | 35 culprit = (WfCulprit.Get(repo_name, revision) or |
| 28 WfCulprit.Create(repo_name, revision, commit_position)) | 36 WfCulprit.Create(repo_name, revision, commit_position)) |
| 29 if [master_name, builder_name, build_number] in culprit.builds: | 37 if [master_name, builder_name, build_number] in culprit.builds: |
| 30 return False | 38 return False |
| 31 | 39 |
| 32 culprit.builds.append([master_name, builder_name, build_number]) | 40 culprit.builds.append([master_name, builder_name, build_number]) |
| 33 # Send notification only when: | 41 # Send notification only when: |
| 34 # 1. It was not processed yet. | 42 # 1. It was not processed yet. |
| 35 # 2. The culprit is for multiple failures in different builds to avoid false | 43 # 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. | 44 # * 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. | 45 # * The whole analysis was rerun a long time after the failure occurred. |
| 40 should_send = not (culprit.cr_notification_processed or | 46 should_send = not (culprit.cr_notification_processed or |
| 41 len(culprit.builds) < build_num_threshold or | 47 not _PassAdditionalCriteria(additional_criteria)) |
| 42 time_limit_passed) | |
| 43 if should_send: | 48 if should_send: |
| 44 culprit.cr_notification_status = status.RUNNING | 49 culprit.cr_notification_status = status.RUNNING |
| 45 culprit.put() | 50 culprit.put() |
| 46 return should_send | 51 return should_send |
| 47 | 52 |
| 48 | 53 |
| 49 @ndb.transactional | 54 @ndb.transactional |
| 50 def _UpdateNotificationStatus(repo_name, revision, new_status): | 55 def _UpdateNotificationStatus(repo_name, revision, new_status): |
| 51 culprit = WfCulprit.Get(repo_name, revision) | 56 culprit = WfCulprit.Get(repo_name, revision) |
| 52 culprit.cr_notification_status = new_status | 57 culprit.cr_notification_status = new_status |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 79 def _GetCulpritInfo(repo_name, revision): | 84 def _GetCulpritInfo(repo_name, revision): |
| 80 """Returns commit position/time and code-review url of the given revision.""" | 85 """Returns commit position/time and code-review url of the given revision.""" |
| 81 # TODO(stgao): get repo url at runtime based on the given repo name. | 86 # TODO(stgao): get repo url at runtime based on the given repo name. |
| 82 # unused arg - pylint: disable=W0612,W0613 | 87 # unused arg - pylint: disable=W0612,W0613 |
| 83 repo = GitRepository( | 88 repo = GitRepository( |
| 84 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) | 89 'https://chromium.googlesource.com/chromium/src.git', HttpClient()) |
| 85 change_log = repo.GetChangeLog(revision) | 90 change_log = repo.GetChangeLog(revision) |
| 86 return change_log.commit_position, change_log.code_review_url | 91 return change_log.commit_position, change_log.code_review_url |
| 87 | 92 |
| 88 | 93 |
| 89 def _NotificationTimeLimitPassed(build_end_time, latency_limit_minutes): | 94 def _NotificationTimeLimitNotPassed(build_end_time, latency_limit_minutes): |
| 90 """Returns True if it is too late to send notification.""" | 95 """Returns True if it is too late to send notification.""" |
|
lijeffrey1
2016/09/03 00:31:53
is this docstring now out of date? I think i prefe
chanli
2016/09/03 01:27:02
Done.
| |
| 91 latency_seconds = (time_util.GetUTCNow() - build_end_time).total_seconds() | 96 latency_seconds = (time_util.GetUTCNow() - build_end_time).total_seconds() |
| 92 return latency_seconds > latency_limit_minutes * 60 | 97 return latency_seconds <= latency_limit_minutes * 60 |
| 93 | 98 |
| 94 | 99 |
| 95 class SendNotificationForCulpritPipeline(BasePipeline): | 100 class SendNotificationForCulpritPipeline(BasePipeline): |
| 96 | 101 |
| 97 # Arguments number differs from overridden method - pylint: disable=W0221 | 102 # Arguments number differs from overridden method - pylint: disable=W0221 |
| 98 def run(self, master_name, builder_name, build_number, repo_name, revision): | 103 def run(self, master_name, builder_name, build_number, repo_name, revision): |
| 99 action_settings = waterfall_config.GetActionSettings() | 104 action_settings = waterfall_config.GetActionSettings() |
| 100 # Set some impossible default values to prevent notification by default. | 105 # 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( | 106 latency_limit_minutes = action_settings.get( |
| 104 'cr_notification_latency_limit_minutes', 1) | 107 'cr_notification_latency_limit_minutes', 1) |
| 105 | 108 |
| 106 commit_position, code_review_url = _GetCulpritInfo( | 109 commit_position, code_review_url = _GetCulpritInfo( |
| 107 repo_name, revision) | 110 repo_name, revision) |
| 108 build_end_time = build_util.GetBuildEndTime( | 111 build_end_time = build_util.GetBuildEndTime( |
| 109 master_name, builder_name, build_number) | 112 master_name, builder_name, build_number) |
| 110 time_limit_passed = _NotificationTimeLimitPassed( | 113 within_time_limit = _NotificationTimeLimitNotPassed( |
| 111 build_end_time, latency_limit_minutes) | 114 build_end_time, latency_limit_minutes) |
| 112 | 115 |
| 116 # Additional criteria that will help decide if a notification | |
|
lijeffrey1
2016/09/03 00:31:53
nit: Too many spaces
chanli
2016/09/03 01:27:02
Done.
| |
| 117 # should be sent. | |
| 118 # TODO (chanli): Add check for if confidence for the culprit is | |
| 119 # over threshold. | |
| 120 additional_criteria = { | |
| 121 'within_time_limit': within_time_limit | |
| 122 } | |
| 123 | |
| 113 if not _ShouldSendNotification( | 124 if not _ShouldSendNotification( |
| 114 master_name, builder_name, build_number, repo_name, | 125 master_name, builder_name, build_number, repo_name, |
| 115 revision, commit_position, build_threshold, time_limit_passed): | 126 revision, commit_position, additional_criteria): |
| 116 return False | 127 return False |
| 117 return _SendNotificationForCulprit( | 128 return _SendNotificationForCulprit( |
| 118 repo_name, revision, commit_position, code_review_url) | 129 repo_name, revision, commit_position, code_review_url) |
| OLD | NEW |