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