| 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 import base64 | 5 import base64 |
| 6 | 6 |
| 7 from google.appengine.ext import ndb | 7 from google.appengine.ext import ndb |
| 8 | 8 |
| 9 from model.base_build_model import BaseBuildModel | 9 from model.base_build_model import BaseBuildModel |
| 10 from model.base_analysis import BaseAnalysis | 10 from model.base_analysis import BaseAnalysis |
| 11 from model.flake.flake_swarming_task import FlakeSwarmingTask | 11 from model.flake.flake_swarming_task import FlakeSwarmingTask |
| 12 | 12 |
| 13 | 13 |
| 14 class MasterFlakeAnalysis(BaseAnalysis, BaseBuildModel): | 14 class MasterFlakeAnalysis(BaseAnalysis, BaseBuildModel): |
| 15 """Represents an analysis of a flaky test in a Chromium Waterfall.""" | 15 """Represents an analysis of a flaky test in a Chromium Waterfall.""" |
| 16 | 16 |
| 17 @staticmethod | |
| 18 def _CreateAnalysisId(master_name, builder_name, | |
| 19 build_number, step_name, test_name): | |
| 20 encoded_test_name = base64.urlsafe_b64encode(test_name) | |
| 21 return '%s/%s/%s/%s/%s' % (master_name, builder_name, | |
| 22 build_number, step_name, encoded_test_name) | |
| 23 | |
| 24 @ndb.ComputedProperty | 17 @ndb.ComputedProperty |
| 25 def step_name(self): | 18 def step_name(self): |
| 26 return self.key.pairs()[0][1].split('/')[3] | 19 return self.key.pairs()[0][1].split('/')[3] |
| 27 | 20 |
| 28 @ndb.ComputedProperty | 21 @ndb.ComputedProperty |
| 29 def test_name(self): | 22 def test_name(self): |
| 30 return base64.urlsafe_b64decode(self.key.pairs()[0][1].split('/')[4]) | 23 return base64.urlsafe_b64decode(self.key.pairs()[0][1].split('/')[4]) |
| 31 | 24 |
| 32 @staticmethod | 25 @staticmethod |
| 33 def _CreateKey(master_name, builder_name, build_number, | 26 def _CreateAnalysisId( |
| 34 step_name, test_name): # pragma: no cover | 27 master_name, builder_name, build_number, step_name, test_name): |
| 35 return ndb.Key('MasterFlakeAnalysis', | 28 encoded_test_name = base64.urlsafe_b64encode(test_name) |
| 36 MasterFlakeAnalysis._CreateAnalysisId( | 29 return '%s/%s/%s/%s/%s' % ( |
| 37 master_name, builder_name, build_number, | 30 master_name, builder_name, build_number, step_name, encoded_test_name) |
| 38 step_name, test_name)) | |
| 39 | 31 |
| 40 @staticmethod | 32 @staticmethod |
| 41 def Create(master_name, builder_name, build_number, | 33 def _CreateKey(master_name, builder_name, build_number, step_name, test_name): |
| 42 step_name, test_name): # pragma: no cover | 34 return ndb.Key( |
| 43 return MasterFlakeAnalysis( | 35 'MasterFlakeAnalysis', MasterFlakeAnalysis._CreateAnalysisId( |
| 44 key=MasterFlakeAnalysis._CreateKey( | 36 master_name, builder_name, build_number, step_name, test_name)) |
| 45 master_name, builder_name, build_number, | |
| 46 step_name, test_name)) | |
| 47 | 37 |
| 38 # TODO(lijeffrey): Override this method to use base64-encoded test name and |
| 39 # call the parent's Create from versioned_model.py. |
| 48 @staticmethod | 40 @staticmethod |
| 49 def Get(master_name, builder_name, build_number, | 41 def Create(master_name, builder_name, build_number, step_name, test_name): |
| 50 step_name, test_name): # pragma: no cover | 42 return MasterFlakeAnalysis(key=MasterFlakeAnalysis._CreateKey( |
| 43 master_name, builder_name, build_number, step_name, test_name)) |
| 44 |
| 45 # TODO(lijeffrey): Once masterflakeanalysis is versionized there should be no |
| 46 # need for this get method. Instead use GetVersion(). |
| 47 @staticmethod |
| 48 def Get(master_name, builder_name, build_number, step_name, |
| 49 test_name): # pragma: no cover |
| 51 return MasterFlakeAnalysis._CreateKey( | 50 return MasterFlakeAnalysis._CreateKey( |
| 52 master_name, builder_name, build_number, step_name, test_name).get() | 51 master_name, builder_name, build_number, step_name, test_name).get() |
| 53 | 52 |
| 54 # List of tested build_numbers and their corresponding success rates. | 53 # The UTC timestamp the check flake task was requested. |
| 55 # We need to keep these sorted manually. | 54 created_time = ndb.DateTimeProperty(indexed=True) |
| 55 |
| 56 # The UTC timestamp the check flake task came completed. |
| 57 completed_time = ndb.DateTimeProperty(indexed=True) |
| 58 |
| 59 # A dict containing information about each swarming rerun's results that can |
| 60 # be used for metrics, such as number of cache hits, average run time, etc. |
| 61 # Example dict: |
| 62 # { |
| 63 # task_id_1: { |
| 64 # 'request_time': 2016-09-06 (10:21:26.288) UTC |
| 65 # 'start_time': 2016-09-06 (10:21:26.288) UTC, |
| 66 # 'end_time': 2016-09-06 (10:21:26.288) UTC, |
| 67 # 'build_number': 12345, |
| 68 # 'cache_hit': True/False, |
| 69 # 'number_of_iterations': 100, |
| 70 # 'number_of_passes': 90, |
| 71 # }, |
| 72 # task_id_2: { |
| 73 # ... |
| 74 # }, |
| 75 # ... |
| 76 # } |
| 77 swarming_rerun_results = ndb.JsonProperty(default={}, indexed=False) |
| 78 |
| 79 # Error code and message, if any. |
| 80 error = ndb.JsonProperty(indexed=False) |
| 81 |
| 82 # Boolean whether or not the suspected regression range/build is correct. |
| 83 correct = ndb.BooleanProperty(indexed=False) |
| 84 |
| 85 # The look back algorithm parameters that were used, as specified in Findit's |
| 86 # configuration. For example, |
| 87 # { |
| 88 # 'iterations_to_rerun': 100, |
| 89 # 'lower_flake_threshold': 0.02, |
| 90 # 'max_build_numbers_to_look_back': 500, |
| 91 # 'max_flake_in_a_row': 4, |
| 92 # 'max_stable_in_a_row': 4, |
| 93 # 'upper_flake_threshold': 0.98 |
| 94 # } |
| 95 algorithm_parameters = ndb.JsonProperty(indexed=False) |
| 96 |
| 97 # The suspected build number to have introduced the flakiness. |
| 98 suspected_flake_build_number = ndb.IntegerProperty() |
| 99 |
| 100 # The build numbers that were examined to generate this run's flakiness graph. |
| 101 # This list needs to be kept sorted manually. |
| 56 build_numbers = ndb.IntegerProperty(indexed=False, repeated=True) | 102 build_numbers = ndb.IntegerProperty(indexed=False, repeated=True) |
| 57 success_rates = ndb.FloatProperty(indexed=False, repeated=True) | 103 |
| 58 flake_swarming_tasks = ndb.KeyProperty( | 104 # The corresponding pass rates of build number's swarming rerun results. |
| 59 kind='FlakeSwarmingTask', repeated=True) | 105 # This list needs to be kept sorted manually. |
| 60 suspected_flake_build_number = ndb.IntegerProperty() | 106 pass_rates = ndb.FloatProperty(indexed=False, repeated=True) |
| OLD | NEW |