def _NewPinpointRequest(self, alert): start_git_hash = pinpoint_request.ResolveToGitHash( alert.start_revision, alert.benchmark_name, crrev=self._crrev) end_git_hash = pinpoint_request.ResolveToGitHash( alert.end_revision, alert.benchmark_name, crrev=self._crrev) # Pinpoint also requires you specify which isolate target to run the # test, so we derive that from the suite name. Eventually, this would # ideally be stored in a SparseDiagnostic but for now we can guess. Also, # Pinpoint only currently works well with Telemetry targets, so we only run # benchmarks that are not explicitly blacklisted. target = pinpoint_request.GetIsolateTarget( alert.bot_name, alert.benchmark_name, alert.start_revision, alert.end_revision, only_telemetry=True) if not target: return None job_name = 'Auto-Bisection on %s/%s' % ( alert.bot_name, alert.benchmark_name) alert_magnitude = alert.median_after_anomaly - alert.median_before_anomaly return pinpoint_service.MakeBisectionRequest( test=alert.test.get(), commit_range=pinpoint_service.CommitRange( start=start_git_hash, end=end_git_hash ), issue=anomaly.Issue( project_id=alert.project_id, issue_id=alert.bug_id, ), comparison_mode='performance', target=target, comparison_magnitude=alert_magnitude, name=job_name, priority=10, tags={ 'test_path': utils.TestPath(alert.test), 'alert': alert.key.urlsafe(), 'auto_bisection': 'true', }, )
def PinpointParamsFromBisectParams(params): """Takes parameters from Dashboard's pinpoint-job-dialog and returns a dict with parameters for a new Pinpoint job. Args: params: A dict in the following format: { 'test_path': Test path for the metric being bisected. 'start_git_hash': Git hash of earlier revision. 'end_git_hash': Git hash of later revision. 'bug_id': Associated bug. 'project_id': Associated Monorail project. } Returns: A dict of params for passing to Pinpoint to start a job, or a dict with an 'error' field. """ if not utils.IsValidSheriffUser(): user = utils.GetEmail() raise InvalidParamsError('User "%s" not authorized.' % user) test_path = params['test_path'] test_path_parts = test_path.split('/') bot_name = test_path_parts[1] suite = test_path_parts[2] # If functional bisects are speciied, Pinpoint expects these parameters to be # empty. bisect_mode = params['bisect_mode'] if bisect_mode != 'performance' and bisect_mode != 'functional': raise InvalidParamsError('Invalid bisect mode %s specified.' % bisect_mode) start_commit = params['start_commit'] end_commit = params['end_commit'] start_git_hash = ResolveToGitHash(start_commit, suite) end_git_hash = ResolveToGitHash(end_commit, suite) # Pinpoint also requires you specify which isolate target to run the # test, so we derive that from the suite name. Eventually, this would # ideally be stored in a SparesDiagnostic but for now we can guess. target = GetIsolateTarget(bot_name, suite) email = utils.GetEmail() job_name = '%s bisect on %s/%s' % (bisect_mode.capitalize(), bot_name, suite) alert_key = '' if params.get('alerts'): alert_keys = json.loads(params.get('alerts')) if alert_keys: alert_key = alert_keys[0] alert_magnitude = None if alert_key: alert = ndb.Key(urlsafe=alert_key).get() alert_magnitude = alert.median_after_anomaly - alert.median_before_anomaly if not alert_magnitude: alert_magnitude = FindMagnitudeBetweenCommits(utils.TestKey(test_path), start_commit, end_commit) if isinstance(params['bug_id'], int): issue_id = params['bug_id'] if params['bug_id'] > 0 else None else: issue_id = int( params['bug_id']) if params['bug_id'].isdigit() else None issue = anomaly.Issue(project_id=params.get('project_id', 'chromium'), issue_id=issue_id) return pinpoint_service.MakeBisectionRequest( test=utils.TestKey(test_path).get(), commit_range=pinpoint_service.CommitRange(start=start_git_hash, end=end_git_hash), issue=issue, comparison_mode=bisect_mode, target=target, comparison_magnitude=alert_magnitude, user=email, name=job_name, story_filter=params['story_filter'], pin=params.get('pin'), tags={ 'test_path': test_path, 'alert': alert_key, }, )