forked from LBRYCommunity/lbry-sdk
add installation id, re-initialize lbryid on each start
This commit is contained in:
parent
41d937d1b4
commit
c6648ff6bc
4 changed files with 38 additions and 42 deletions
|
@ -17,18 +17,18 @@ def get_sd_hash(stream_info):
|
|||
|
||||
|
||||
class Events(object):
|
||||
def __init__(self, context, lbryid, session_id):
|
||||
def __init__(self, context, installation_id, session_id):
|
||||
"""Contains all of the analytics events that can be sent
|
||||
|
||||
Attributes:
|
||||
context: usually the output of `make_context`
|
||||
lbryid: id unique to this installation. Can be anything, but
|
||||
installation_id: id unique to this installation. Can be anything, but
|
||||
generally should be base58 encoded.
|
||||
session_id: id for tracking events during this session. Can be
|
||||
anything, but generally should be base58 encoded.
|
||||
"""
|
||||
self.context = context
|
||||
self.lbryid = lbryid
|
||||
self.installation_id = installation_id
|
||||
self.session_id = session_id
|
||||
|
||||
def update_context(self, context):
|
||||
|
@ -88,7 +88,7 @@ class Events(object):
|
|||
def _properties(self, event_properties=None):
|
||||
event_properties = event_properties or {}
|
||||
properties = {
|
||||
'lbry_id': self.lbryid,
|
||||
'lbry_id': self.installation_id,
|
||||
'session_id': self.session_id,
|
||||
}
|
||||
properties.update(event_properties)
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import base58
|
||||
|
||||
from lbrynet.core import looping_call_manager
|
||||
|
||||
from twisted.internet import defer
|
||||
from twisted.internet import task
|
||||
|
||||
from lbrynet.core.system_info import get_platform
|
||||
from lbrynet import conf
|
||||
from lbrynet.core import looping_call_manager
|
||||
from lbrynet.core.system_info import get_platform
|
||||
|
||||
import constants
|
||||
from api import Api
|
||||
|
@ -29,7 +26,7 @@ class Manager(object):
|
|||
if events is None:
|
||||
events = Events(
|
||||
make_context(get_platform(), conf.settings['wallet']),
|
||||
base58.b58encode(conf.settings.get_lbry_id()),
|
||||
conf.settings.installation_id,
|
||||
conf.settings.get_session_id(),
|
||||
)
|
||||
return cls(api, events, Track())
|
||||
|
|
|
@ -212,7 +212,7 @@ class Config(object):
|
|||
def __init__(self, fixed_defaults, adjustable_defaults, persisted_settings=None,
|
||||
environment=None, cli_settings=None):
|
||||
|
||||
self._lbry_id = None
|
||||
self._installation_id = None
|
||||
self._session_id = base58.b58encode(utils.generate_id())
|
||||
|
||||
self._fixed_defaults = fixed_defaults
|
||||
|
@ -429,17 +429,17 @@ class Config(object):
|
|||
else:
|
||||
return yml_path
|
||||
|
||||
def get_lbry_id(self):
|
||||
lbry_id_filename = os.path.join(self.ensure_data_dir(), 'lbryid')
|
||||
if not self._lbry_id:
|
||||
if os.path.isfile(lbry_id_filename):
|
||||
with open(lbry_id_filename, 'r') as lbryid_file:
|
||||
self._lbry_id = base58.b58decode(lbryid_file.read())
|
||||
if not self._lbry_id:
|
||||
self._lbry_id = utils.generate_id()
|
||||
with open(lbry_id_filename, 'w') as lbryid_file:
|
||||
lbryid_file.write(base58.b58encode(self._lbry_id))
|
||||
return self._lbry_id
|
||||
def get_installation_id(self):
|
||||
install_id_filename = os.path.join(self.ensure_data_dir(), "install_id")
|
||||
if not self._installation_id:
|
||||
if os.path.isfile(install_id_filename):
|
||||
with open(install_id_filename, "r") as install_id_file:
|
||||
self._installation_id = install_id_file.read()
|
||||
if not self._installation_id:
|
||||
self._installation_id = base58.b58encode(utils.generate_id())
|
||||
with open(install_id_filename, "w") as install_id_file:
|
||||
install_id_file.write(self._installation_id)
|
||||
return self._installation_id
|
||||
|
||||
def get_session_id(self):
|
||||
return self._session_id
|
||||
|
@ -464,5 +464,7 @@ def initialize_settings(load_conf_file=True):
|
|||
if settings is None:
|
||||
settings = Config(FIXED_SETTINGS, ADJUSTABLE_SETTINGS,
|
||||
environment=get_default_env())
|
||||
settings.installation_id = settings.get_installation_id()
|
||||
if load_conf_file:
|
||||
settings.load_conf_file_settings()
|
||||
|
||||
|
|
|
@ -251,7 +251,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
self.log_uploader = log_support.LogUploader.load('lbrynet', self.log_file)
|
||||
|
||||
self.analytics_manager = analytics_manager
|
||||
self.lbryid = conf.settings.get_lbry_id()
|
||||
self.lbryid = utils.generate_id()
|
||||
|
||||
self.wallet_user = None
|
||||
self.wallet_password = None
|
||||
|
@ -343,21 +343,12 @@ class Daemon(AuthJSONRPCServer):
|
|||
|
||||
def _load_caches(self):
|
||||
name_cache_filename = os.path.join(self.db_dir, "stream_info_cache.json")
|
||||
lbryid_filename = os.path.join(self.db_dir, "lbryid")
|
||||
|
||||
if os.path.isfile(name_cache_filename):
|
||||
with open(name_cache_filename, "r") as name_cache:
|
||||
self.name_cache = json.loads(name_cache.read())
|
||||
log.info("Loaded claim info cache")
|
||||
|
||||
if os.path.isfile(lbryid_filename):
|
||||
with open(lbryid_filename, "r") as lbryid_file:
|
||||
self.lbryid = base58.b58decode(lbryid_file.read())
|
||||
else:
|
||||
with open(lbryid_filename, "w") as lbryid_file:
|
||||
self.lbryid = utils.generate_id()
|
||||
lbryid_file.write(base58.b58encode(self.lbryid))
|
||||
|
||||
def _check_network_connection(self):
|
||||
self.connected_to_internet = utils.check_connection()
|
||||
|
||||
|
@ -519,9 +510,10 @@ class Daemon(AuthJSONRPCServer):
|
|||
|
||||
def _upload_log(self, log_type=None, exclude_previous=False, force=False):
|
||||
if self.upload_log or force:
|
||||
lbryid = base58.b58encode(self.lbryid)[:SHORT_ID_LEN]
|
||||
try:
|
||||
self.log_uploader.upload(exclude_previous, lbryid, log_type)
|
||||
self.log_uploader.upload(exclude_previous,
|
||||
conf.settings.installation_id[:SHORT_ID_LEN],
|
||||
log_type)
|
||||
except requests.RequestException:
|
||||
log.warning('Failed to upload log file')
|
||||
return defer.succeed(None)
|
||||
|
@ -658,7 +650,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
|
||||
def _modify_loggly_formatter(self):
|
||||
log_support.configure_loggly_handler(
|
||||
lbry_id=base58.b58encode(self.lbryid),
|
||||
installation_id=conf.settings.installation_id,
|
||||
session_id=self._session_id
|
||||
)
|
||||
|
||||
|
@ -1039,6 +1031,7 @@ class Daemon(AuthJSONRPCServer):
|
|||
has_wallet = self.session and self.session.wallet
|
||||
response = {
|
||||
'lbry_id': base58.b58encode(self.lbryid)[:SHORT_ID_LEN],
|
||||
'installation_id': conf.settings.get_installation_id()[:SHORT_ID_LEN],
|
||||
'is_running': self.announced_startup,
|
||||
'is_first_run': self.session.wallet.is_first_run if has_wallet else None,
|
||||
'startup_status': {
|
||||
|
@ -1208,7 +1201,12 @@ class Daemon(AuthJSONRPCServer):
|
|||
"""
|
||||
|
||||
platform_name = self._get_platform()['platform']
|
||||
report_bug_to_slack(message, self.lbryid, platform_name, lbrynet_version)
|
||||
report_bug_to_slack(
|
||||
message,
|
||||
conf.settings.installation_id,
|
||||
platform_name,
|
||||
lbrynet_version
|
||||
)
|
||||
return self._render_response(True)
|
||||
|
||||
def jsonrpc_get_settings(self):
|
||||
|
@ -2674,13 +2672,12 @@ def loggly_time_string(dt):
|
|||
return urllib.quote_plus(formatted_dt + milliseconds + "Z")
|
||||
|
||||
|
||||
def get_loggly_query_string(lbry_id):
|
||||
decoded_id = base58.b58encode(lbry_id)
|
||||
def get_loggly_query_string(installation_id):
|
||||
base_loggly_search_url = "https://lbry.loggly.com/search#"
|
||||
now = utils.now()
|
||||
yesterday = now - utils.timedelta(days=1)
|
||||
params = {
|
||||
'terms': 'json.lbry_id:{}*'.format(decoded_id[:SHORT_ID_LEN]),
|
||||
'terms': 'json.installation_id:{}*'.format(installation_id[:SHORT_ID_LEN]),
|
||||
'from': loggly_time_string(yesterday),
|
||||
'to': loggly_time_string(now)
|
||||
}
|
||||
|
@ -2688,13 +2685,13 @@ def get_loggly_query_string(lbry_id):
|
|||
return base_loggly_search_url + data
|
||||
|
||||
|
||||
def report_bug_to_slack(message, lbry_id, platform_name, app_version):
|
||||
webhook = utils.deobfuscate(conf.settings['SLACK_WEBHOOK'])
|
||||
def report_bug_to_slack(message, installation_id, platform_name, app_version):
|
||||
webhook = utils.deobfuscate(conf.settings.SLACK_WEBHOOK)
|
||||
payload_template = "os: %s\n version: %s\n<%s|loggly>\n%s"
|
||||
payload_params = (
|
||||
platform_name,
|
||||
app_version,
|
||||
get_loggly_query_string(lbry_id),
|
||||
get_loggly_query_string(installation_id),
|
||||
message
|
||||
)
|
||||
payload = {
|
||||
|
|
Loading…
Reference in a new issue