diff --git a/app/js/controllers/home.js b/app/js/controllers/home.js index 92005ed3..698b9afc 100644 --- a/app/js/controllers/home.js +++ b/app/js/controllers/home.js @@ -53,11 +53,20 @@ function HomeController(healthService, startDate, projectService) { }; }; - var loadData = function() { + function loadRunMetadataKeys() { + healthService.getRunMetadataKeys().then(function(response) { + vm.runMetadataKeys = response.data; + }); + } + + var loadData = function(runMetadataKey) { + var groupBy = runMetadataKey || vm.selectedRunMetadataKey; + vm.selectedRunMetadataKey = groupBy; + var start = new Date(startDate); start.setDate(start.getDate() - 20); - healthService.getRunsGroupedByMetadataPerDatetime('project', { + healthService.getRunsGroupedByMetadataPerDatetime(groupBy, { start_date: start, datetime_resolution: 'hour' }).then(function(response) { @@ -68,9 +77,12 @@ function HomeController(healthService, startDate, projectService) { // ViewModel var vm = this; vm.searchProject = ''; + vm.selectedRunMetadataKey = 'project'; + vm.loadRunMetadataKeys = loadRunMetadataKeys; vm.processData = processData; vm.loadData = loadData; vm.loadData(); + vm.loadRunMetadataKeys(); } controllersModule.controller('HomeController', HomeController); diff --git a/app/views/home.html b/app/views/home.html index 5babcdc6..0fe4444a 100644 --- a/app/views/home.html +++ b/app/views/home.html @@ -1,16 +1,16 @@
-

OpenStack Health

- +
+
+

OpenStack Health

+ + +
+
-
-
- -
-
@@ -36,10 +36,19 @@
+
+ + +
- +
@@ -47,7 +56,7 @@
diff --git a/etc/openstack-health-api.conf b/etc/openstack-health-api.conf index 114fe933..f90012c2 100644 --- a/etc/openstack-health-api.conf +++ b/etc/openstack-health-api.conf @@ -1,2 +1,11 @@ [default] db_uri = mysql+pymysql://query:query@logstash.openstack.org/subunit2sql +ignored_run_metadata_keys = + build_change + build_master + build_node + build_patchset + build_ref + build_short_uuid + build_uuid + build_zuul_url diff --git a/openstack_health/api.py b/openstack_health/api.py index 413b0c4e..1f68bde9 100644 --- a/openstack_health/api.py +++ b/openstack_health/api.py @@ -93,9 +93,22 @@ def get_runs_from_build_name(build_name): @app.route('/runs/metadata/keys', methods=['GET']) def get_run_metadata_keys(): - global Session + global config + try: + if config: + ignored_keys = (config + .get('default', 'ignored_run_metadata_keys') + .splitlines()) + else: + ignored_keys = [] + except ConfigParser.NoOptionError: + ignored_keys = [] + session = Session() - return jsonify(api.get_all_run_metadata_keys(session)) + existing_keys = set(api.get_all_run_metadata_keys(session)) + allowed_keys = existing_keys.difference(ignored_keys) + + return jsonify(list(allowed_keys)) def _parse_datetimes(datetime_str): diff --git a/openstack_health/tests/test_api.py b/openstack_health/tests/test_api.py index c49baedf..378c007c 100644 --- a/openstack_health/tests/test_api.py +++ b/openstack_health/tests/test_api.py @@ -62,8 +62,12 @@ class TestRestAPI(base.TestCase): res = self.app.get('/runs/metadata/keys') self.assertEqual(200, res.status_code) api_mock.assert_called_once_with(api.Session()) - expected_response = [u'build_name', u'project', u'build_uuid'] - self.assertEqual(expected_response, json.loads(res.data)) + expected_response = [ + u'build_name', + u'project', + u'build_uuid' + ] + self.assertItemsEqual(expected_response, json.loads(res.data)) @mock.patch('subunit2sql.db.api.get_test_run_dict_by_run_meta_key_value', return_value=[ diff --git a/test/e2e/mocks/run_metadata_keys.js b/test/e2e/mocks/run_metadata_keys.js new file mode 100644 index 00000000..095705d0 --- /dev/null +++ b/test/e2e/mocks/run_metadata_keys.js @@ -0,0 +1,11 @@ +module.exports = { + request: { + method: 'JSONP', + path: '/runs/metadata/keys' + }, + response: { + data: ['build_branch', 'build_change', 'build_master', 'build_name', +'build_node', 'build_patchset', 'build_queue', 'build_ref', 'build_short_uuid', +'build_uuid', 'build_zuul_url', 'filename', 'project', 'voting'] + } +}; diff --git a/test/e2e/routes_spec.js b/test/e2e/routes_spec.js index a44ff03f..49cdb6cf 100644 --- a/test/e2e/routes_spec.js +++ b/test/e2e/routes_spec.js @@ -7,7 +7,7 @@ var mock = require('protractor-http-mock'); describe('E2E: Routes', function() { it('should have a working home route', function() { - mock(['config', 'home_project']); + mock(['config', 'run_metadata_keys', 'home_project']); browser.get('#/'); diff --git a/test/unit/controllers/home_spec.js b/test/unit/controllers/home_spec.js index 8324c7fa..d0bb1f79 100644 --- a/test/unit/controllers/home_spec.js +++ b/test/unit/controllers/home_spec.js @@ -5,6 +5,15 @@ describe('HomeController', function() { var $controller, homeController, projectService; var mockResponse = { data: {} }; + var mockMetadataKeysResponse = { + data: { + runs: { + metadata: { + keys: ['filename', 'project', 'voting'] + } + } + } + }; beforeEach(inject(function(_$controller_) { $controller = _$controller_; @@ -13,6 +22,11 @@ describe('HomeController', function() { var healthService = { getRunsGroupedByMetadataPerDatetime: function(key, options) { return { then: function(callback) { callback(mockResponse); } }; + }, + getRunMetadataKeys: function() { + return { + then: function(callback) { callback(mockMetadataKeysResponse); } + }; } }; projectService = {