| OLD | NEW |
| 1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 """URL endpoint to add new histograms to the datastore.""" | 5 """URL endpoint to add new histograms to the datastore.""" |
| 6 | 6 |
| 7 import json | 7 import json |
| 8 | 8 |
| 9 from dashboard import add_histograms | 9 from dashboard import add_histograms |
| 10 # TODO(eakuefner): Move these helpers so we don't have to import add_point_queue |
| 11 # directly. |
| 12 from dashboard import add_point_queue |
| 10 from dashboard.common import datastore_hooks | 13 from dashboard.common import datastore_hooks |
| 11 from dashboard.common import request_handler | 14 from dashboard.common import request_handler |
| 12 from dashboard.common import utils | 15 from dashboard.common import stored_object |
| 16 from dashboard.models import anomaly |
| 13 from dashboard.models import histogram | 17 from dashboard.models import histogram |
| 14 | 18 |
| 15 | |
| 16 class AddHistogramsQueueHandler(request_handler.RequestHandler): | 19 class AddHistogramsQueueHandler(request_handler.RequestHandler): |
| 17 """Request handler to process a histogram and add it to the datastore. | 20 """Request handler to process a histogram and add it to the datastore. |
| 18 | 21 |
| 19 This request handler is intended to be used only by requests using the | 22 This request handler is intended to be used only by requests using the |
| 20 task queue; it shouldn't be directly from outside. | 23 task queue; it shouldn't be directly from outside. |
| 21 """ | 24 """ |
| 22 | 25 |
| 23 def get(self): | 26 def get(self): |
| 24 self.post() | 27 self.post() |
| 25 | 28 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 | 39 |
| 37 Request parameters: | 40 Request parameters: |
| 38 data: JSON encoding of a histogram or shared diagnostic. | 41 data: JSON encoding of a histogram or shared diagnostic. |
| 39 revision: a revision, given as an int. | 42 revision: a revision, given as an int. |
| 40 test_path: the test path to which this diagnostic or histogram should be | 43 test_path: the test path to which this diagnostic or histogram should be |
| 41 attached. | 44 attached. |
| 42 """ | 45 """ |
| 43 datastore_hooks.SetPrivilegedRequest() | 46 datastore_hooks.SetPrivilegedRequest() |
| 44 | 47 |
| 45 data = self.request.get('data') | 48 data = self.request.get('data') |
| 49 revision = int(self.request.get('revision')) |
| 50 test_path = self.request.get('test_path') |
| 51 |
| 46 data_dict = json.loads(data) | 52 data_dict = json.loads(data) |
| 47 revision = int(self.request.get('revision')) | |
| 48 test_key = utils.TestKey(self.request.get('test_path')) | |
| 49 guid = data_dict['guid'] | 53 guid = data_dict['guid'] |
| 54 is_diagnostic = ( |
| 55 data_dict.get('type') in add_histograms.SPARSE_DIAGNOSTIC_TYPES) |
| 50 | 56 |
| 51 if data_dict.get('type') in add_histograms.SPARSE_DIAGNOSTIC_TYPES: | 57 test_path_parts = test_path.split('/') |
| 58 master = test_path_parts[0] |
| 59 bot = test_path_parts[1] |
| 60 test_name = '/'.join(test_path_parts[2:]) |
| 61 bot_whitelist = stored_object.Get(add_point_queue.BOT_WHITELIST_KEY) |
| 62 internal_only = add_point_queue.BotInternalOnly(bot, bot_whitelist) |
| 63 extra_args = {} if is_diagnostic else GetUnitArgs(data_dict['unit']) |
| 64 # TDOO(eakuefner): Populate benchmark_description once it appears in |
| 65 # diagnostics. |
| 66 test_key = add_point_queue.GetOrCreateAncestors( |
| 67 master, bot, test_name, internal_only, **extra_args).key |
| 68 |
| 69 if is_diagnostic: |
| 52 entity = histogram.SparseDiagnostic( | 70 entity = histogram.SparseDiagnostic( |
| 53 id=guid, data=data, test=test_key, start_revision=revision, | 71 id=guid, data=data, test=test_key, start_revision=revision, |
| 54 end_revision=revision) | 72 end_revision=revision) |
| 55 else: | 73 else: |
| 56 entity = histogram.Histogram( | 74 entity = histogram.Histogram( |
| 57 id=guid, data=data, test=test_key, revision=revision) | 75 id=guid, data=data, test=test_key, revision=revision) |
| 58 | 76 |
| 59 entity.put() | 77 entity.put() |
| 78 |
| 79 |
| 80 def GetUnitArgs(unit): |
| 81 unit_args = { |
| 82 'units': unit |
| 83 } |
| 84 # TODO(eakuefner): Port unit system to Python and use that here |
| 85 histogram_improvement_direction = unit.split('_')[-1] |
| 86 if histogram_improvement_direction == 'biggerIsBetter': |
| 87 unit_args['improvement_direction'] = anomaly.UP |
| 88 elif histogram_improvement_direction == 'smallerIsBetter': |
| 89 unit_args['improvement_direction'] = anomaly.DOWN |
| 90 else: |
| 91 unit_args['improvement_direction'] = anomaly.UNKNOWN |
| 92 return unit_args |
| OLD | NEW |