def testGetMostRecentDiagnosticData_ReturnsAllData(self):
        data_samples = [{
            'type': 'Ownership',
            'guid': 'eb212e80-db58-4cbd-b331-c2245ecbb826',
            'emails': ['*****@*****.**', '*****@*****.**'],
            'component': 'fooBar'
        }, {
            'guid': 'abc',
            'osName': 'linux',
            'type': 'DeviceInfo'
        }]

        test_key = utils.TestKey('Chromium/win7/foo')
        for data in data_samples:
            entity = histogram.SparseDiagnostic(data=json.dumps(data),
                                                test=test_key,
                                                start_revision=1,
                                                end_revision=sys.maxint,
                                                id='sample' + data.get('type'))
            entity.put()

        owner_lookup_result = find_anomalies.GetMostRecentDiagnosticData(
            test_key, 'Ownership')
        device_lookup_result = find_anomalies.GetMostRecentDiagnosticData(
            test_key, 'DeviceInfo')

        self.assertEqual(owner_lookup_result.get('component'), 'fooBar')
        self.assertListEqual(owner_lookup_result.get('emails'),
                             ['*****@*****.**', '*****@*****.**'])

        self.assertIsNone(device_lookup_result.get('component'))
        self.assertEqual(device_lookup_result.get('osName'), 'linux')
def ProcessDiagnostics(diagnostic_data, revision, test_key, internal_only):
    if not diagnostic_data:
        raise ndb.Return({})

    diagnostic_entities = []
    for name, diagnostic_datum in diagnostic_data.items():
        guid = diagnostic_datum['guid']
        diagnostic_entities.append(
            histogram.SparseDiagnostic(id=guid,
                                       name=name,
                                       data=diagnostic_datum,
                                       test=test_key,
                                       start_revision=revision,
                                       end_revision=sys.maxsize,
                                       internal_only=internal_only))

    suite_key = utils.TestKey('/'.join(test_key.id().split('/')[:3]))
    last_added = yield histogram.HistogramRevisionRecord.GetLatest(suite_key)
    assert last_added

    new_guids_to_existing_diagnostics = yield (
        histogram.SparseDiagnostic.FindOrInsertDiagnostics(
            diagnostic_entities, test_key, revision, last_added.revision))

    raise ndb.Return(new_guids_to_existing_diagnostics)
Esempio n. 3
0
    def testGetMostRecentValuesByNames_ReturnsNoneIfNoneFound(self):
        data_sample = {
            'type': 'GenericSet',
            'guid': 'eb212e80-db58-4cbd-b331-c2245ecbb826',
            'values': ['*****@*****.**']
        }

        test_key = utils.TestKey('Chromium/win7/foo')
        entity = histogram.SparseDiagnostic(data=json.dumps(data_sample),
                                            test=test_key,
                                            start_revision=1,
                                            end_revision=sys.maxint,
                                            id=data_sample['guid'],
                                            name=reserved_infos.OWNERS.name)
        entity.put()

        lookup_result = histogram.SparseDiagnostic.GetMostRecentValuesByNames(
            test_key,
            set([
                reserved_infos.OWNERS.name, reserved_infos.BUG_COMPONENTS.name
            ]))

        self.assertEqual(lookup_result.get(reserved_infos.OWNERS.name),
                         ['*****@*****.**'])
        self.assertIsNone(lookup_result.get(
            reserved_infos.BUG_COMPONENTS.name))
Esempio n. 4
0
    def post(self):
        """Adds a single histogram or sparse shared diagnostic to the datastore.

    The |data| request parameter can be either a histogram or a sparse shared
    diagnostic; the set of diagnostics that are considered sparse (meaning that
    they don't normally change on every upload for a given benchmark from a
    given bot) is shown in add_histograms.SPARSE_DIAGNOSTIC_TYPES.

    See https://goo.gl/lHzea6 for detailed information on the JSON format for
    histograms and diagnostics.

    Request parameters:
      data: JSON encoding of a histogram or shared diagnostic.
      revision: a revision, given as an int.
      test_path: the test path to which this diagnostic or histogram should be
          attached.
    """
        datastore_hooks.SetPrivilegedRequest()

        data = self.request.get('data')
        data_dict = json.loads(data)
        revision = int(self.request.get('revision'))
        test_key = utils.TestKey(self.request.get('test_path'))

        if data_dict.get('type') in add_histograms.SPARSE_DIAGNOSTIC_TYPES:
            entity = histogram.SparseDiagnostic(data=data,
                                                test=test_key,
                                                start_revision=revision,
                                                end_revision=revision)
        else:
            entity = histogram.Histogram(data=data,
                                         test=test_key,
                                         revision=revision)

        entity.put()
Esempio n. 5
0
 def testPostHistogram_WithDifferentDiagnostic(self):
     diag_dict = {
         'guid': 'c397a1a0-e289-45b2-abe7-29e638e09168',
         'values': ['*****@*****.**'],
         'type': 'GenericSet'
     }
     diag = histogram.SparseDiagnostic(
         data=diag_dict,
         name='owners',
         start_revision=1,
         end_revision=sys.maxsize,
         test=utils.TestKey('Chromium/win7/suite/metric'))
     diag.put()
     histogram.HistogramRevisionRecord.GetOrCreate(
         utils.TestKey('Chromium/win7/suite'), 1).put()
     test_path = 'Chromium/win7/suite/metric'
     params = [{
         'data': TEST_HISTOGRAM,
         'test_path': test_path,
         'benchmark_description': None,
         'revision': 123,
         'diagnostics': {
             'benchmarks': TEST_BENCHMARKS,
             'owners': TEST_OWNERS
         }
     }]
     self.testapp.post('/add_histograms_queue', json.dumps(params))
     histogram_entity = histogram.Histogram.query().fetch()[0]
     hist = histogram_module.Histogram.FromDict(histogram_entity.data)
     self.assertEqual('68e5b3bd-829c-4f4f-be3a-98a94279ccf0',
                      hist.diagnostics['owners'].guid)
     diagnostics = histogram.SparseDiagnostic.query().fetch()
     self.assertEqual(len(diagnostics), 3)
    def _AddMockData(self):
        """Adds sample TestMetadata, Row, and Anomaly entities."""
        testing_common.AddTests(*_MOCK_DATA)

        # Add 50 Row entities to one of the tests.
        # Also add 2 Anomaly entities.
        test_path = 'ChromiumPerf/mac/SunSpider/Total/t'
        test_key = utils.TestKey(test_path)
        test_container_key = utils.GetTestContainerKey(test_key)
        for rev in range(15000, 15100, 2):
            graph_data.Row(id=rev, parent=test_container_key,
                           value=(rev * 2)).put()
            if rev % 50 == 0:
                data = generic_set.GenericSet(['foo_%s' % rev])
                data = data.AsDict()
                anomaly.Anomaly(start_revision=(rev - 2),
                                end_revision=rev,
                                median_before_anomaly=100,
                                median_after_anomaly=50,
                                test=test_key).put()
                histogram.SparseDiagnostic(test=test_key,
                                           start_revision=rev - 50,
                                           end_revision=rev - 1,
                                           data=data).put()
                histogram.Histogram(test=test_key).put()
Esempio n. 7
0
  def testCompletedWithCommitAndDocs(
      self, differences, result_values, commit_as_dict):
    c = change.Change((change.Commit('chromium', 'git_hash'),))
    differences.return_value = [(None, c)]
    result_values.side_effect = [0], [1.23456]
    commit_as_dict.return_value = {
        'repository': 'chromium',
        'git_hash': 'git_hash',
        'url': 'https://example.com/repository/+/git_hash',
        'author': '*****@*****.**',
        'subject': 'Subject.',
        'message': 'Subject.\n\nCommit message.',
    }

    self.get_issue.return_value = {'status': 'Untriaged'}

    j = job.Job.New(
        (), (), bug_id=123456, comparison_mode='performance',
        tags={'test_path': 'master/bot/benchmark'})

    diag_dict = generic_set.GenericSet([[u'Benchmark doc link', u'http://docs']])
    diag = histogram.SparseDiagnostic(
        data=diag_dict.AsDict(), start_revision=1, end_revision=sys.maxint,
        name=reserved_infos.DOCUMENTATION_URLS.name,
        test=utils.TestKey('master/bot/benchmark'))
    diag.put()

    j.Run()

    self.add_bug_comment.assert_called_once_with(
        123456, _COMMENT_COMPLETED_WITH_COMMIT_AND_DOCS,
        status='Assigned', owner='*****@*****.**',
        cc_list=['*****@*****.**'])
Esempio n. 8
0
def ProcessHistogramSet(histogram_dicts):
    if not isinstance(histogram_dicts, list):
        raise api_request_handler.BadRequestError(
            'HistogramSet JSON much be a list of dicts')
    histograms = histogram_set.HistogramSet()
    histograms.ImportDicts(histogram_dicts)
    histograms.ResolveRelatedHistograms()
    InlineDenseSharedDiagnostics(histograms)

    revision = ComputeRevision(histograms)

    task_list = []

    suite_key = GetSuiteKey(histograms)

    suite_level_sparse_diagnostic_entities = []
    diagnostic_names_added = {}

    # We'll skip the histogram-level sparse diagnostics because we need to
    # handle those with the histograms, below, so that we can properly assign
    # test paths.
    for hist in histograms:
        for name, diag in hist.diagnostics.iteritems():
            if name in SUITE_LEVEL_SPARSE_DIAGNOSTIC_NAMES:
                if diagnostic_names_added.get(name) is None:
                    diagnostic_names_added[name] = diag.guid

                if diagnostic_names_added.get(name) != diag.guid:
                    raise ValueError(
                        name +
                        ' diagnostics must be the same for all histograms')

            if name in SUITE_LEVEL_SPARSE_DIAGNOSTIC_NAMES:
                suite_level_sparse_diagnostic_entities.append(
                    histogram.SparseDiagnostic(id=diag.guid,
                                               data=diag.AsDict(),
                                               test=suite_key,
                                               start_revision=revision,
                                               end_revision=sys.maxint,
                                               name=name))

    # TODO(eakuefner): Refactor master/bot computation to happen above this line
    # so that we can replace with a DiagnosticRef rather than a full diagnostic.
    new_guids_to_old_diagnostics = DeduplicateAndPut(
        suite_level_sparse_diagnostic_entities, suite_key, revision)
    for new_guid, old_diagnostic in new_guids_to_old_diagnostics.iteritems():
        histograms.ReplaceSharedDiagnostic(
            new_guid, diagnostic.Diagnostic.FromDict(old_diagnostic))

    for hist in histograms:
        guid = hist.guid
        diagnostics = FindHistogramLevelSparseDiagnostics(guid, histograms)
        # TODO(eakuefner): Don't compute full diagnostics, because we need anyway to
        # call GetOrCreate here and in the queue.
        test_path = ComputeTestPath(guid, histograms)
        # TODO(eakuefner): Batch these better than one per task.
        task_list.append(_MakeTask(hist, test_path, revision, diagnostics))

    queue = taskqueue.Queue(TASK_QUEUE_NAME)
    queue.add(task_list)
    def testMakeAnomalyEntity_AddsOwnership(self):
        data = json.dumps({
            'type': 'Ownership',
            'guid': 'eb212e80-db58-4cbd-b331-c2245ecbb826',
            'emails': ['*****@*****.**', '*****@*****.**'],
            'component': 'fooBar'
        })

        testing_common.AddTests(
            ['ChromiumPerf'], ['linux'], {
                'page_cycler_v2': {
                    'cnn': {},
                    'cnn_ref': {},
                    'yahoo': {},
                    'nytimes': {},
                },
            })
        test_key = utils.TestKey('ChromiumPerf/linux/page_cycler_v2/cnn')
        test = test_key.get()
        testing_common.AddRows(test.test_path, [100, 200, 300, 400])
        entity = histogram.SparseDiagnostic(data=data,
                                            test=test_key,
                                            id='abc',
                                            start_revision=1,
                                            end_revision=sys.maxint)
        entity.put()

        alert = find_anomalies._MakeAnomalyEntity(
            _MakeSampleChangePoint(10011, 50, 100), test,
            list(graph_data.Row.query()))

        self.assertEqual(alert.ownership['component'], 'fooBar')
        self.assertListEqual(alert.ownership['emails'],
                             ['*****@*****.**', '*****@*****.**'])
Esempio n. 10
0
    def testGetMostRecentDiagnosticData_LooksUpRightType(self):
        data_samples = [{
            'buildNumber': 0,
            'buildbotMasterName': '',
            'buildbotName': '',
            'displayBotName': 'bot',
            'displayMasterName': 'master',
            'guid': 'e9c2891d-2b04-413f-8cf4-099827e67626',
            'logUri': '',
            'type': 'BuildbotInfo'
        }, {
            'type': 'Ownership',
            'guid': 'eb212e80-db58-4cbd-b331-c2245ecbb826',
            'emails': ['*****@*****.**']
        }]

        test_key = utils.TestKey('Chromium/win7/foo')

        for data in data_samples:
            entity = histogram.SparseDiagnostic(data=json.dumps(data),
                                                test=test_key,
                                                start_revision=1,
                                                end_revision=sys.maxint,
                                                id='sample' + data.get('type'))
            entity.put()

        ownership_lookup_result = find_anomalies.GetMostRecentDiagnosticData(
            test_key, 'Ownership')
        buildbot_lookup_result = find_anomalies.GetMostRecentDiagnosticData(
            test_key, 'BuildbotInfo')

        self.assertIsNotNone(ownership_lookup_result)
        self.assertEqual(ownership_lookup_result['type'], 'Ownership')
        self.assertIsNotNone(buildbot_lookup_result)
        self.assertEqual(buildbot_lookup_result['type'], 'BuildbotInfo')
Esempio n. 11
0
  def testFixupDiagnostics_Middle_FixesRange(self):
    test_key = utils.TestKey('Chromium/win7/foo')

    self._AddMockData(test_key)

    data = {
        'type': 'GenericSet',
        'guid': '1',
        'values': ['10']
    }

    e = histogram.SparseDiagnostic(
        data=data, test=test_key,
        start_revision=5, end_revision=sys.maxint,
        name='owners', internal_only=False)
    e.put()

    histogram.SparseDiagnostic.FixDiagnostics(test_key).get_result()

    expected = {
        'owners': [(0, 4), (5, 9), (10, 19), (20, sys.maxint)],
        'bugs': [(0, 9), (10, 19), (20, sys.maxint)],
    }
    diags = histogram.SparseDiagnostic.query().fetch()
    for d in diags:
      self.assertIn((d.start_revision, d.end_revision), expected[d.name])
      expected[d.name].remove((d.start_revision, d.end_revision))
    self.assertEqual(0, len(expected['owners']))
    self.assertEqual(0, len(expected['bugs']))
Esempio n. 12
0
 def testPostHistogram_WithSameDiagnostic(self):
     diag_dict = {
         'guid': '05341937-1272-4214-80ce-43b2d03807f9',
         'values': ['myBenchmark'],
         'type': 'GenericSet',
     }
     diag = histogram.SparseDiagnostic(
         data=diag_dict,
         start_revision=1,
         end_revision=sys.maxsize,
         test=utils.TestKey('Chromium/win7/suite/metric'))
     diag.put()
     histogram.HistogramRevisionRecord.GetOrCreate(
         utils.TestKey('Chromium/win7/suite'), 1).put()
     test_path = 'Chromium/win7/suite/metric'
     params = [{
         'data': TEST_HISTOGRAM,
         'test_path': test_path,
         'benchmark_description': None,
         'revision': 123,
         'diagnostics': {
             'benchmarks': TEST_BENCHMARKS,
             'owners': TEST_OWNERS
         }
     }]
     self.testapp.post('/add_histograms_queue', json.dumps(params))
     histogram_entity = histogram.Histogram.query().fetch()[0]
     hist = histogram_module.Histogram.FromDict(histogram_entity.data)
     self.assertEqual(TEST_BENCHMARKS['guid'],
                      hist.diagnostics[reserved_infos.BENCHMARKS.name].guid)
     diagnostics = histogram.SparseDiagnostic.query().fetch()
     self.assertEqual(len(diagnostics), 3)
Esempio n. 13
0
    def testCaseTags(self):
        external_key = namespaced_stored_object.NamespaceKey(
            update_test_suites.TEST_SUITES_2_CACHE_KEY,
            datastore_hooks.EXTERNAL)
        stored_object.Set(external_key, ['suite'])
        testing_common.AddTests(['master'], ['a', 'b'], {
            'suite': {
                'measurement': {
                    'x': {},
                    'y': {},
                    'z': {},
                },
            },
        })
        for bot in 'ab':
            for case in 'xyz':
                test = utils.TestKey('master/%s/suite/measurement/%s' %
                                     (bot, case)).get()
                test.has_rows = True
                test.put()
        histogram.SparseDiagnostic(
            test=utils.TestKey('master/a/suite/measurement/x'),
            name=reserved_infos.STORY_TAGS.name,
            end_revision=sys.maxsize,
            data=generic_set.GenericSet(['j']).AsDict()).put()
        histogram.SparseDiagnostic(
            test=utils.TestKey('master/a/suite/measurement/y'),
            name=reserved_infos.STORY_TAGS.name,
            end_revision=sys.maxsize,
            data=generic_set.GenericSet(['j', 'k']).AsDict()).put()

        self.Post('/update_test_suite_descriptors')

        self.ExecuteDeferredTasks('default')

        expected = {
            'measurements': ['measurement'],
            'bots': ['master:a', 'master:b'],
            'cases': ['x', 'y', 'z'],
            'caseTags': {
                'j': ['x', 'y'],
                'k': ['y']
            },
        }
        actual = update_test_suite_descriptors.FetchCachedTestSuiteDescriptor(
            'suite')
        self.assertEqual(expected, actual)
 def _AddMockData(self, diagnostic_data):
   for diagnostic in diagnostic_data:
     histogram.SparseDiagnostic(
         id=diagnostic['data']['guid'],
         test=ndb.Key('TestMetadata', diagnostic['test_path']),
         start_revision=diagnostic['start_revision'],
         end_revision=diagnostic['end_revision'],
         data=diagnostic['data'],
         name=diagnostic['name']).put()
Esempio n. 15
0
  def testPostHistogram_DeduplicatesSameSparseDiagnostic(self):
    diag_dict = {
        'values': ['master'],
        'guid': 'e9c2891d-2b04-413f-8cf4-099827e67626',
        'type': 'GenericSet'
    }
    diag = histogram.SparseDiagnostic(
        id='e9c2891d-2b04-413f-8cf4-099827e67626', data=diag_dict,
        start_revision=1, end_revision=sys.maxint,
        test=utils.TestKey('master/bot/benchmark'))
    diag.put()
    data = json.dumps([
        {
            'values': ['benchmark'],
            'guid': '0bc1021b-8107-4db7-bc8c-49d7cf53c5ae',
            'type': 'GenericSet',
        }, {
            'values': [424242],
            'guid': '25f0a111-9bb4-4cea-b0c1-af2609623160',
            'type': 'GenericSet',
        }, {
            'values': ['master'],
            'guid': 'e9c2891d-2b04-413f-8cf4-099827e67626',
            'type': 'GenericSet'
        }, {
            'values': ['bot'],
            'guid': '53fb5448-9f8d-407a-8891-e7233fe1740f',
            'type': 'GenericSet'
        }, {
            'binBoundaries': [1, [1, 1000, 20]],
            'diagnostics': {
                reserved_infos.MASTERS.name:
                    'e9c2891d-2b04-413f-8cf4-099827e67626',
                reserved_infos.BOTS.name:
                    '53fb5448-9f8d-407a-8891-e7233fe1740f',
                reserved_infos.CHROMIUM_COMMIT_POSITIONS.name:
                    '25f0a111-9bb4-4cea-b0c1-af2609623160',
                reserved_infos.BENCHMARKS.name:
                    '0bc1021b-8107-4db7-bc8c-49d7cf53c5ae',
            },
            'guid': '4989617a-14d6-4f80-8f75-dafda2ff13b0',
            'name': 'foo',
            'unit': 'count'
        }
    ])
    self.testapp.post('/add_histograms', {'data': data})

    diagnostics = histogram.SparseDiagnostic.query().fetch()
    params_by_guid = self.TaskParamsByGuid()
    params = params_by_guid['4989617a-14d6-4f80-8f75-dafda2ff13b0']
    hist = params['data']

    self.assertEqual(3, len(diagnostics))
    self.assertEqual(
        'e9c2891d-2b04-413f-8cf4-099827e67626',
        hist['diagnostics'][reserved_infos.MASTERS.name])
Esempio n. 16
0
    def _AddMockData(self):
        """Adds sample TestMetadata and Row entities."""
        testing_common.AddTests(*_MOCK_DATA)

        # Add 50 Row entities to some of the tests.
        for test_path in _TESTS_WITH_ROWS:
            testing_common.AddRows(test_path, range(15000, 15100, 2))

            histogram.SparseDiagnostic(test=utils.TestKey(test_path)).put()
            histogram.Histogram(test=utils.TestKey(test_path)).put()
Esempio n. 17
0
 def testDeduplicateAndPut_Same(self):
   d = {
       'values': ['master'],
       'guid': 'e9c2891d-2b04-413f-8cf4-099827e67626',
       'type': 'GenericSet'
   }
   test_key = utils.TestKey('Chromium/win7/foo')
   entity = histogram.SparseDiagnostic(
       data=d, name='masters', test=test_key, start_revision=1,
       end_revision=sys.maxint, id='abc')
   entity.put()
   d2 = d.copy()
   d2['guid'] = 'def'
   entity2 = histogram.SparseDiagnostic(
       data=d2, test=test_key,
       start_revision=2, end_revision=sys.maxint, id='def')
   add_histograms.DeduplicateAndPut([entity2], test_key, 2)
   sparse = histogram.SparseDiagnostic.query().fetch()
   self.assertEqual(2, len(sparse))
Esempio n. 18
0
 def testDeduplicateAndPut_Same(self):
   d = {
       'guid': 'abc',
       'osName': 'linux',
       'type': 'DeviceInfo'
   }
   test_key = utils.TestKey('Chromium/win7/foo')
   entity = histogram.SparseDiagnostic(
       data=json.dumps(d), test=test_key, start_revision=1,
       end_revision=sys.maxint, id='abc')
   entity.put()
   d2 = d.copy()
   d2['guid'] = 'def'
   entity2 = histogram.SparseDiagnostic(
       data=json.dumps(d2), test=test_key,
       start_revision=2, end_revision=sys.maxint, id='def')
   add_histograms.DeduplicateAndPut([entity2], test_key, 2)
   sparse = histogram.SparseDiagnostic.query().fetch()
   self.assertEqual(1, len(sparse))
Esempio n. 19
0
    def post(self):
        """Adds a single histogram or sparse shared diagnostic to the datastore.

    The |data| request parameter can be either a histogram or a sparse shared
    diagnostic; the set of diagnostics that are considered sparse (meaning that
    they don't normally change on every upload for a given benchmark from a
    given bot) is shown in add_histograms.SPARSE_DIAGNOSTIC_TYPES.

    See https://goo.gl/lHzea6 for detailed information on the JSON format for
    histograms and diagnostics.

    Request parameters:
      data: JSON encoding of a histogram or shared diagnostic.
      revision: a revision, given as an int.
      test_path: the test path to which this diagnostic or histogram should be
          attached.
    """
        datastore_hooks.SetPrivilegedRequest()

        data = self.request.get('data')
        revision = int(self.request.get('revision'))
        test_path = self.request.get('test_path')

        data_dict = json.loads(data)
        guid = data_dict['guid']
        is_diagnostic = 'type' in data_dict

        test_path_parts = test_path.split('/')
        master = test_path_parts[0]
        bot = test_path_parts[1]
        test_name = '/'.join(test_path_parts[2:])
        bot_whitelist = stored_object.Get(add_point_queue.BOT_WHITELIST_KEY)
        internal_only = add_point_queue.BotInternalOnly(bot, bot_whitelist)
        extra_args = {} if is_diagnostic else GetUnitArgs(data_dict['unit'])
        # TDOO(eakuefner): Populate benchmark_description once it appears in
        # diagnostics.
        test_key = add_point_queue.GetOrCreateAncestors(
            master, bot, test_name, internal_only, **extra_args).key

        if is_diagnostic:
            entity = histogram.SparseDiagnostic(id=guid,
                                                data=data,
                                                test=test_key,
                                                start_revision=revision,
                                                end_revision=revision,
                                                internal_only=internal_only)
        else:
            entity = histogram.Histogram(id=guid,
                                         data=data,
                                         test=test_key,
                                         revision=revision,
                                         internal_only=internal_only)
            AddRow(data_dict, test_key, revision, test_path, internal_only)

        entity.put()
Esempio n. 20
0
    def testGetMostRecentDataByNames_ReturnAllData(self):
        data_samples = [{
            'type': 'GenericSet',
            'guid': 'eb212e80-db58-4cbd-b331-c2245ecbb826',
            'values': ['*****@*****.**']
        }, {
            'type': 'GenericSet',
            'guid': 'eb212e80-db58-4cbd-b331-c2245ecbb827',
            'values': ['abc']
        }]

        test_key = utils.TestKey('Chromium/win7/foo')
        entity = histogram.SparseDiagnostic(data=data_samples[0],
                                            test=test_key,
                                            start_revision=1,
                                            end_revision=sys.maxsize,
                                            id=data_samples[0]['guid'],
                                            name=reserved_infos.OWNERS.name)
        entity.put()

        entity = histogram.SparseDiagnostic(
            data=data_samples[1],
            test=test_key,
            start_revision=1,
            end_revision=sys.maxsize,
            id=data_samples[1]['guid'],
            name=reserved_infos.BUG_COMPONENTS.name)
        entity.put()

        lookup_result = histogram.SparseDiagnostic.GetMostRecentDataByNamesSync(
            test_key,
            set([
                reserved_infos.OWNERS.name, reserved_infos.BUG_COMPONENTS.name
            ]))

        self.assertEqual(
            lookup_result.get(reserved_infos.OWNERS.name).get('values'),
            ['*****@*****.**'])
        self.assertEqual(
            lookup_result.get(
                reserved_infos.BUG_COMPONENTS.name).get('values'), ['abc'])
Esempio n. 21
0
    def _AddMockData(self, test_key):
        data_samples = {
            'owners': [
                {
                    'type': 'GenericSet',
                    'guid': '1',
                    'values': ['1']
                },
                {
                    'type': 'GenericSet',
                    'guid': '1',
                    'values': ['2']
                },
                {
                    'type': 'GenericSet',
                    'guid': '1',
                    'values': ['3']
                },
            ],
            'bugs': [
                {
                    'type': 'GenericSet',
                    'guid': '1',
                    'values': ['a']
                },
                {
                    'type': 'GenericSet',
                    'guid': '1',
                    'values': ['b']
                },
                {
                    'type': 'GenericSet',
                    'guid': '1',
                    'values': ['c']
                },
            ]
        }
        for k, diagnostic_samples in data_samples.items():
            for i, sample in enumerate(diagnostic_samples):
                start_revision = i * 10
                end_revision = (i + 1) * 10 - 1
                if i == len(diagnostic_samples) - 1:
                    end_revision = sys.maxsize

                e = histogram.SparseDiagnostic(data=sample,
                                               test=test_key,
                                               start_revision=start_revision,
                                               end_revision=end_revision,
                                               name=k,
                                               internal_only=False)
                e.put()
Esempio n. 22
0
 def testDeduplicateAndPut_New(self):
   d = {
       'guid': 'abc',
       'osName': 'linux',
       'type': 'DeviceInfo'
   }
   test_key = utils.TestKey('Chromium/win7/foo')
   entity = histogram.SparseDiagnostic(
       data=d, test=test_key, start_revision=1,
       end_revision=sys.maxint, id='abc')
   entity.put()
   add_histograms.DeduplicateAndPut([entity], test_key, 1)
   sparse = histogram.SparseDiagnostic.query().fetch()
   self.assertEqual(1, len(sparse))
Esempio n. 23
0
 def _CreateGenericDiagnostic(self,
                              name,
                              values,
                              test_key,
                              start_revision,
                              end_revision=sys.maxsize):
     d = generic_set.GenericSet([values])
     e = histogram.SparseDiagnostic(id=d.guid,
                                    data=d.AsDict(),
                                    name=name,
                                    test=test_key,
                                    start_revision=start_revision,
                                    end_revision=end_revision)
     return e
Esempio n. 24
0
 def testCompletedWithCommitAndDocs(self, differences, result_values,
                                    commit_as_dict):
     c = change.Change((change.Commit('chromium', 'git_hash'), ))
     differences.return_value = [(None, c)]
     result_values.side_effect = [1.23456], [0]
     commit_as_dict.return_value = {
         'repository': 'chromium',
         'git_hash': 'git_hash',
         'url': 'https://example.com/repository/+/git_hash',
         'author': '*****@*****.**',
         'subject': 'Subject.',
         'message': 'Subject.\n\nCommit message.',
     }
     self.get_issue.return_value = {'status': 'Untriaged'}
     j = job.Job.New((), (),
                     bug_id=123456,
                     comparison_mode='performance',
                     tags={'test_path': 'master/bot/benchmark'})
     diag_dict = generic_set.GenericSet(
         [[u'Benchmark doc link', u'http://docs']])
     diag = histogram.SparseDiagnostic(
         data=diag_dict.AsDict(),
         start_revision=1,
         end_revision=sys.maxsize,
         name=reserved_infos.DOCUMENTATION_URLS.name,
         test=utils.TestKey('master/bot/benchmark'))
     diag.put()
     j.Run()
     self.ExecuteDeferredTasks('default')
     self.assertFalse(j.failed)
     self.add_bug_comment.assert_called_once_with(
         123456,
         mock.ANY,
         status='Assigned',
         owner='*****@*****.**',
         labels=mock.ANY,
         cc_list=['*****@*****.**'],
         merge_issue=None,
         project='chromium')
     message = self.add_bug_comment.call_args[0][1]
     self.assertIn('Found a significant difference at 1 commit.', message)
     self.assertIn('http://docs', message)
     self.assertIn('Benchmark doc link', message)
     labels = self.add_bug_comment.call_args[1]['labels']
     self.assertIn('Pinpoint-Job-Completed', labels)
     self.assertNotIn('-Pinpoint-Job-Completed', labels)
     self.assertIn('Pinpoint-Culprit-Found', labels)
     self.assertNotIn('-Pinpoint-Culprit-Found', labels)
Esempio n. 25
0
def FindSuiteLevelSparseDiagnostics(
    histograms, suite_key, revision, internal_only):
  diagnostics = {}
  for hist in histograms:
    for name, diag in hist.diagnostics.iteritems():
      if name in SUITE_LEVEL_SPARSE_DIAGNOSTIC_NAMES:
        existing_entity = diagnostics.get(name)
        if existing_entity is None:
          diagnostics[name] = histogram.SparseDiagnostic(
              id=diag.guid, data=diag.AsDict(), test=suite_key,
              start_revision=revision, end_revision=sys.maxint, name=name,
              internal_only=internal_only)
        elif existing_entity.key.id() != diag.guid:
          raise ValueError(
              name + ' diagnostics must be the same for all histograms')
  return diagnostics.values()
Esempio n. 26
0
    def testGetMostRecentDiagnosticData_ReturnsNoneIfNoneFound(self):
        data = json.dumps({
            'guid': 'abc',
            'osName': 'linux',
            'type': 'DeviceInfo'
        })
        test_key = utils.TestKey('Chromium/win7/foo')
        entity = histogram.SparseDiagnostic(data=data,
                                            test=test_key,
                                            start_revision=1,
                                            end_revision=sys.maxint,
                                            id='abc')
        entity.put()

        lookup_result = find_anomalies.GetMostRecentDiagnosticData(
            test_key, 'Ownership')
        self.assertIsNone(lookup_result)
def ProcessDiagnostics(diagnostic_data, revision, test_key, internal_only):
  if not diagnostic_data:
    raise ndb.Return({})

  diagnostic_entities = []
  for name, diagnostic_datum in diagnostic_data.iteritems():
    # TODO(eakuefner): Pass map of guid to dict to avoid overhead
    guid = diagnostic_datum['guid']
    diagnostic_entities.append(histogram.SparseDiagnostic(
        id=guid, name=name, data=diagnostic_datum, test=test_key,
        start_revision=revision, end_revision=sys.maxint,
        internal_only=internal_only))
  new_guids_to_existing_diagnostics = yield (
      add_histograms.DeduplicateAndPutAsync(
          diagnostic_entities, test_key, revision))

  raise ndb.Return(new_guids_to_existing_diagnostics)
Esempio n. 28
0
    def testGet_SuccessWithMeasurementsAndAssociatedHistogram(self):
        owners_diagnostic = generic_set.GenericSet(['owner_name'])
        owners_diagnostic.guid = str(uuid.uuid4())

        histogram.SparseDiagnostic(id=owners_diagnostic.guid,
                                   data=owners_diagnostic.AsDict(),
                                   name=reserved_infos.OWNERS.name,
                                   test=None,
                                   start_revision=1,
                                   end_revision=999).put().get()

        hs = self.GetTestHistogram(owners_diagnostic).put().get()

        token_id = str(uuid.uuid4())
        test_path = 'Chromium/win7/suite/metric1'
        token = upload_completion_token.Token(id=token_id).put().get()
        measurement = token.AddMeasurement(test_path, True).get_result()
        measurement.histogram = hs.key
        measurement.put()

        expected = {
            'token':
            token_id,
            'file':
            None,
            'created':
            str(token.creation_time),
            'lastUpdated':
            str(token.update_time),
            'state':
            'PROCESSING',
            'measurements': [
                {
                    'name': test_path,
                    'state': 'PROCESSING',
                    'monitored': True,
                    'lastUpdated': str(measurement.update_time),
                },
            ]
        }
        response = json.loads(
            self.testapp.get('/uploads/%s?additional_info=measurements' %
                             token_id,
                             status=200).body)
        self.assertEqual(response, expected)
Esempio n. 29
0
  def testGetMostRecentValuesByNames_ReturnsNoneIfNoName(self):
    data_sample = {
        'guid': 'abc',
        'osName': 'linux',
        'type': 'DeviceInfo'
    }

    test_key = utils.TestKey('Chromium/win7/foo')
    entity = histogram.SparseDiagnostic(
        data=json.dumps(data_sample), test=test_key, start_revision=1,
        end_revision=sys.maxint, id=data_sample['guid'])
    entity.put()

    lookup_result = histogram.SparseDiagnostic.GetMostRecentValuesByNames(
        test_key, set([reserved_infos.OWNERS.name,
                       reserved_infos.BUG_COMPONENTS.name]))

    self.assertIsNone(lookup_result.get(reserved_infos.OWNERS.name))
    self.assertIsNone(lookup_result.get(reserved_infos.BUG_COMPONENTS.name))
Esempio n. 30
0
    def testGetMostRecentDiagnosticData_WithoutComponent(self):
        data = json.dumps({
            'type': 'Ownership',
            'guid': 'eb212e80-db58-4cbd-b331-c2245ecbb826',
            'emails': ['*****@*****.**']
        })
        test_key = utils.TestKey('Chromium/win7/foo')
        entity = histogram.SparseDiagnostic(data=data,
                                            test=test_key,
                                            start_revision=1,
                                            end_revision=sys.maxint,
                                            id='abc')
        entity.put()

        lookup_result = find_anomalies.GetMostRecentDiagnosticData(
            test_key, 'Ownership')

        self.assertIsNone(lookup_result.get('component'))
        self.assertListEqual(lookup_result.get('emails'),
                             ['*****@*****.**'])