Add fetching_user_source config option

Launchpad manages many information related to OpenStack at this
time, but the query takes much time for the processor. In addition,
stackalytics can be useful for OSS which are not managed with the
launchpad. So this patch adds a config option fetching_source so
that users can select fetching source. The default option is
'launchpad', so this patch doesn't affect at all on the default
option.

Change-Id: I4b7db745c36545e8897132cf6ccbb1c3fd6f3c07
This commit is contained in:
Ken'ichi Ohmichi
2017-03-13 13:08:27 -07:00
committed by Ken'ichi Ohmichi
parent 887f2c5814
commit df6753fe66
5 changed files with 27 additions and 7 deletions

View File

@@ -3,6 +3,7 @@ usage: stackalytics-processor [-h] [--config-dir DIR] [--config-file PATH]
[--days_to_update_members DAYS_TO_UPDATE_MEMBERS] [--days_to_update_members DAYS_TO_UPDATE_MEMBERS]
[--debug] [--default-data-uri DEFAULT_DATA_URI] [--debug] [--default-data-uri DEFAULT_DATA_URI]
[--driverlog-data-uri DRIVERLOG_DATA_URI] [--driverlog-data-uri DRIVERLOG_DATA_URI]
[--fetching-user-source FETCHING_USER_SOURCE]
[--gerrit-retry GERRIT_RETRY] [--gerrit-retry GERRIT_RETRY]
[--git-base-uri GIT_BASE_URI] [--git-base-uri GIT_BASE_URI]
[--log-config-append PATH] [--log-config-append PATH]
@@ -44,6 +45,8 @@ optional arguments:
file:///path/to/default_data.json file:///path/to/default_data.json
--driverlog-data-uri DRIVERLOG_DATA_URI --driverlog-data-uri DRIVERLOG_DATA_URI
URI for default data URI for default data
--fetching-user-source FETCHING_USER_SOURCE
Source for fetching user profiles
--gerrit-retry GERRIT_RETRY --gerrit-retry GERRIT_RETRY
How many times to retry after Gerrit errors How many times to retry after Gerrit errors
--git-base-uri GIT_BASE_URI --git-base-uri GIT_BASE_URI

View File

@@ -147,6 +147,10 @@
# URI of translation team data (string value) # URI of translation team data (string value)
#translation_team_uri = https://git.openstack.org/cgit/openstack/i18n/plain/tools/zanata/translation_team.yaml #translation_team_uri = https://git.openstack.org/cgit/openstack/i18n/plain/tools/zanata/translation_team.yaml
# Source for fetching user profiles (string value)
# Allowed values: launchpad, <None>
#fetching_user_source = launchpad
# How many member profiles to look ahead after the last (integer value) # How many member profiles to look ahead after the last (integer value)
#members_look_ahead = 250 #members_look_ahead = 250

View File

@@ -54,6 +54,9 @@ PROCESSOR_OPTS = [
default='https://git.openstack.org/cgit/openstack/i18n/' default='https://git.openstack.org/cgit/openstack/i18n/'
'plain/tools/zanata/translation_team.yaml', 'plain/tools/zanata/translation_team.yaml',
help='URI of translation team data'), help='URI of translation team data'),
cfg.StrOpt("fetching-user-source", default='launchpad',
choices=['launchpad', '<None>'],
help="Source for fetching user profiles"),
cfg.IntOpt('members-look-ahead', default=250, cfg.IntOpt('members-look-ahead', default=250,
help='How many member profiles to look ahead after the last'), help='How many member profiles to look ahead after the last'),
cfg.IntOpt('read-timeout', default=120, cfg.IntOpt('read-timeout', default=120,

View File

@@ -19,6 +19,7 @@ import copy
import functools import functools
import time import time
from oslo_config import cfg
from oslo_log import log as logging from oslo_log import log as logging
import six import six
@@ -27,6 +28,7 @@ from stackalytics.processor import user_processor
from stackalytics.processor import utils from stackalytics.processor import utils
CONF = cfg.CONF
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@@ -232,6 +234,9 @@ class RecordProcessor(object):
self.runtime_storage_inst, u) self.runtime_storage_inst, u)
return merged_user return merged_user
def _need_to_fetch_launchpad(self):
return CONF.fetching_user_source == 'launchpad'
def update_user(self, record): def update_user(self, record):
email = record.get('author_email') email = record.get('author_email')
user_e = user_processor.load_user( user_e = user_processor.load_user(
@@ -239,8 +244,8 @@ class RecordProcessor(object):
user_name = record.get('author_name') user_name = record.get('author_name')
launchpad_id = record.get('launchpad_id') launchpad_id = record.get('launchpad_id')
if (email and (not user_e) and (not launchpad_id) and if (self._need_to_fetch_launchpad() and email and (not user_e) and
(not user_e.get('launchpad_id'))): (not launchpad_id) and (not user_e.get('launchpad_id'))):
# query LP # query LP
launchpad_id, lp_user_name = self._get_lp_info(email) launchpad_id, lp_user_name = self._get_lp_info(email)
if lp_user_name: if lp_user_name:
@@ -250,8 +255,8 @@ class RecordProcessor(object):
if gerrit_id: if gerrit_id:
user_g = user_processor.load_user( user_g = user_processor.load_user(
self.runtime_storage_inst, gerrit_id=gerrit_id) or {} self.runtime_storage_inst, gerrit_id=gerrit_id) or {}
if ((not user_g) and (not launchpad_id) and if (self._need_to_fetch_launchpad() and (not user_g) and
(not user_e.get('launchpad_id'))): (not launchpad_id) and (not user_e.get('launchpad_id'))):
# query LP # query LP
guessed_lp_id = gerrit_id guessed_lp_id = gerrit_id
lp_user_name = self._get_lp_user_name(guessed_lp_id) lp_user_name = self._get_lp_user_name(guessed_lp_id)
@@ -264,8 +269,8 @@ class RecordProcessor(object):
if zanata_id: if zanata_id:
user_z = user_processor.load_user( user_z = user_processor.load_user(
self.runtime_storage_inst, zanata_id=zanata_id) or {} self.runtime_storage_inst, zanata_id=zanata_id) or {}
if ((not user_z) and (not launchpad_id) and if (self._need_to_fetch_launchpad() and (not user_z) and
(not user_e.get('launchpad_id'))): (not launchpad_id) and (not user_e.get('launchpad_id'))):
# query LP # query LP
guessed_lp_id = zanata_id guessed_lp_id = zanata_id
user_name = self._get_lp_user_name(guessed_lp_id) user_name = self._get_lp_user_name(guessed_lp_id)
@@ -290,7 +295,7 @@ class RecordProcessor(object):
[user_e, user_l, user_g, user_z, user]) [user_e, user_l, user_g, user_z, user])
else: else:
# create new # create new
if not user_name: if (self._need_to_fetch_launchpad() and not user_name):
user_name = self._get_lp_user_name(launchpad_id) user_name = self._get_lp_user_name(launchpad_id)
if user_name: if user_name:
user['user_name'] = user_name user['user_name'] = user_name

View File

@@ -16,15 +16,19 @@
import time import time
import mock import mock
from oslo_config import cfg
import six import six
import testtools import testtools
from stackalytics.processor import config
from stackalytics.processor import record_processor from stackalytics.processor import record_processor
from stackalytics.processor import runtime_storage from stackalytics.processor import runtime_storage
from stackalytics.processor import user_processor from stackalytics.processor import user_processor
from stackalytics.processor import utils from stackalytics.processor import utils
CONF = cfg.CONF
RELEASES = [ RELEASES = [
{ {
'release_name': 'prehistory', 'release_name': 'prehistory',
@@ -67,6 +71,7 @@ class TestRecordProcessor(testtools.TestCase):
self.lp_profile_by_email = ( self.lp_profile_by_email = (
self.lp_profile_by_email_patch.start()) self.lp_profile_by_email_patch.start())
self.lp_profile_by_email.return_value = None self.lp_profile_by_email.return_value = None
CONF.register_opts(config.CONNECTION_OPTS + config.PROCESSOR_OPTS)
def tearDown(self): def tearDown(self):
super(TestRecordProcessor, self).tearDown() super(TestRecordProcessor, self).tearDown()