diff --git a/dashboard/parameters.py b/dashboard/parameters.py index 3003217dd..bb4e4a886 100644 --- a/dashboard/parameters.py +++ b/dashboard/parameters.py @@ -14,8 +14,10 @@ # limitations under the License. import flask +from oslo.config import cfg from six.moves.urllib import parse +from dashboard import vault from stackalytics.openstack.common import log as logging @@ -23,9 +25,6 @@ LOG = logging.getLogger(__name__) DEFAULTS = { - 'metric': 'commits', - 'release': 'icehouse', - 'project_type': 'openstack', 'review_nth': 5, } @@ -33,7 +32,6 @@ METRIC_LABELS = { 'loc': 'Lines of code', 'commits': 'Commits', 'marks': 'Reviews', - 'tm_marks': 'Top Mentors', 'emails': 'Emails', 'bpd': 'Drafted Blueprints', 'bpc': 'Completed Blueprints', @@ -43,7 +41,6 @@ METRIC_TO_RECORD_TYPE = { 'loc': 'commit', 'commits': 'commit', 'marks': 'mark', - 'tm_marks': 'mark', 'emails': 'email', 'bpd': 'bpd', 'bpc': 'bpc', @@ -54,6 +51,19 @@ DEFAULT_STATIC_ACTIVITY_SIZE = 100 def get_default(param_name): + if 'release' not in DEFAULTS: + release = cfg.CONF.default_release + if not release: + runtime_storage_inst = vault.get_vault()['runtime_storage'] + releases = runtime_storage_inst.get_by_key('releases') + if releases: + release = releases[-1]['release_name'] + else: + release = 'all' + DEFAULTS['release'] = release.lower() + DEFAULTS['metric'] = cfg.CONF.default_metric.lower() + DEFAULTS['project_type'] = cfg.CONF.default_project_type.lower() + if param_name in DEFAULTS: return DEFAULTS[param_name] else: diff --git a/etc/stackalytics.conf b/etc/stackalytics.conf index df382141b..a78055f15 100644 --- a/etc/stackalytics.conf +++ b/etc/stackalytics.conf @@ -37,3 +37,12 @@ # The address of file with list of programs # program_list_uri = https://raw.github.com/openstack/governance/master/reference/programs.yaml + +# Default metric +# default_metric = marks + +# Default release, the most recent if not set +# default_release = + +# Default project type +# default_project_type = openstack diff --git a/stackalytics/processor/config.py b/stackalytics/processor/config.py index 9f2eacfb5..928117a56 100644 --- a/stackalytics/processor/config.py +++ b/stackalytics/processor/config.py @@ -46,4 +46,10 @@ OPTS = [ default=('https://raw.github.com/openstack/governance/' 'master/reference/programs.yaml'), help='The address of file with list of programs'), + cfg.StrOpt('default-metric', default='marks', + help='Default metric'), + cfg.StrOpt('default-release', + help='Default release, the most recent if not set'), + cfg.StrOpt('default-project-type', default='openstack', + help='Default project type'), ] diff --git a/tests/api/test_modules.py b/tests/api/test_modules.py index 0451cd199..d1fe0e753 100644 --- a/tests/api/test_modules.py +++ b/tests/api/test_modules.py @@ -37,7 +37,8 @@ class TestAPIModules(test_api.TestAPI): test_api.make_records(record_type=['commit'], module=['glance', 'nova', 'nova-cli'])): - response = self.app.get('/api/1.0/modules?project_type=all') + response = self.app.get('/api/1.0/modules?' + 'project_type=all&metric=commits') modules = json.loads(response.data)['modules'] self.assertEqual( [{'id': 'glance', 'text': 'glance', 'tag': 'module'}, @@ -50,7 +51,7 @@ class TestAPIModules(test_api.TestAPI): 'project type') response = self.app.get('/api/1.0/modules?module=nova-group&' - 'project_type=integrated') + 'project_type=integrated&metric=commits') modules = json.loads(response.data)['modules'] self.assertEqual( [{'id': 'glance', 'text': 'glance', 'tag': 'module'}, @@ -61,7 +62,7 @@ class TestAPIModules(test_api.TestAPI): 'project type') response = self.app.get('/api/1.0/modules?query=glance&' - 'project_type=all') + 'project_type=all&metric=commits') modules = json.loads(response.data)['modules'] self.assertEqual( [{'id': 'glance', 'text': 'glance', 'tag': 'module'}], diff --git a/tests/api/test_users.py b/tests/api/test_users.py index d372485ff..0a05c0867 100644 --- a/tests/api/test_users.py +++ b/tests/api/test_users.py @@ -34,7 +34,8 @@ class TestAPIUsers(test_api.TestAPI): 'modules': ['nova', 'glance']}]}, test_api.make_records(record_type=['commit'], module=['nova'], user_id=['john_doe', 'bill_smith'])): - response = self.app.get('/api/1.0/users?module=nova') + response = self.app.get('/api/1.0/users?' + 'module=nova&metric=commits') users = json.loads(response.data)['users'] self.assertEqual(2, len(users)) self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users) @@ -49,7 +50,8 @@ class TestAPIUsers(test_api.TestAPI): 'modules': ['nova', 'glance']}]}, test_api.make_records(record_type=['commit'], module=['nova'], user_name=['John Doe', 'Bill Smith'])): - response = self.app.get('/api/1.0/users?module=nova&query=doe') + response = self.app.get('/api/1.0/users?' + 'module=nova&query=doe&metric=commits') users = json.loads(response.data)['users'] self.assertEqual(1, len(users)) self.assertIn({'id': 'john_doe', 'text': 'John Doe'}, users)