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