Compare commits

...
Sign in to create a new pull request.

2 commits

Author SHA1 Message Date
Victor Shyba
ac06b782a8 remove external ip from analytics 2021-06-28 00:25:33 -03:00
Victor Shyba
6495694ac8 add analytics_id, remove session_id and stop sending installation id 2021-06-28 00:21:51 -03:00
3 changed files with 9 additions and 21 deletions

View file

@ -32,17 +32,15 @@ TIME_TO_FIRST_BYTES = "Time To First Bytes"
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
def _event_properties(installation_id: str, session_id: str, def _event_properties(analytics_id: str, event_properties: typing.Optional[typing.Dict]) -> typing.Dict:
event_properties: typing.Optional[typing.Dict]) -> typing.Dict:
properties = { properties = {
'lbry_id': installation_id, 'analytics_id': analytics_id
'session_id': session_id,
} }
properties.update(event_properties or {}) properties.update(event_properties or {})
return properties return properties
def _download_properties(conf: Config, external_ip: str, resolve_duration: float, def _download_properties(conf: Config, resolve_duration: float,
total_duration: typing.Optional[float], download_id: str, name: str, total_duration: typing.Optional[float], download_id: str, name: str,
outpoint: str, active_peer_count: typing.Optional[int], outpoint: str, active_peer_count: typing.Optional[int],
tried_peers_count: typing.Optional[int], connection_failures_count: typing.Optional[int], tried_peers_count: typing.Optional[int], connection_failures_count: typing.Optional[int],
@ -54,7 +52,6 @@ def _download_properties(conf: Config, external_ip: str, resolve_duration: float
error: typing.Optional[str] = None, error_msg: typing.Optional[str] = None, error: typing.Optional[str] = None, error_msg: typing.Optional[str] = None,
wallet_server: typing.Optional[str] = None) -> typing.Dict: wallet_server: typing.Optional[str] = None) -> typing.Dict:
return { return {
"external_ip": external_ip,
"download_id": download_id, "download_id": download_id,
"total_duration": round(total_duration, 4), "total_duration": round(total_duration, 4),
"resolve_duration": None if not resolve_duration else round(resolve_duration, 4), "resolve_duration": None if not resolve_duration else round(resolve_duration, 4),
@ -105,17 +102,15 @@ def _make_context(platform):
class AnalyticsManager: class AnalyticsManager:
def __init__(self, conf: Config, installation_id: str, session_id: str): def __init__(self, conf: Config):
self.conf = conf self.conf = conf
self.cookies = {} self.cookies = {}
self.url = ANALYTICS_ENDPOINT self.url = ANALYTICS_ENDPOINT
self._write_key = utils.deobfuscate(ANALYTICS_TOKEN) self._write_key = utils.deobfuscate(ANALYTICS_TOKEN)
self._tracked_data = collections.defaultdict(list) self._tracked_data = collections.defaultdict(list)
self.context = _make_context(system_info.get_platform()) self.context = _make_context(system_info.get_platform())
self.installation_id = installation_id self.analytics_id = utils.generate_id().hex()
self.session_id = session_id
self.task: typing.Optional[asyncio.Task] = None self.task: typing.Optional[asyncio.Task] = None
self.external_ip: typing.Optional[str] = None
@property @property
def enabled(self): def enabled(self):
@ -132,7 +127,6 @@ class AnalyticsManager:
async def run(self): async def run(self):
while True: while True:
if self.enabled: if self.enabled:
self.external_ip, _ = await utils.get_external_ip(self.conf.lbryum_servers)
await self._send_heartbeat() await self._send_heartbeat()
await asyncio.sleep(1800) await asyncio.sleep(1800)
@ -194,7 +188,7 @@ class AnalyticsManager:
error_msg: typing.Optional[str] = None, error_msg: typing.Optional[str] = None,
wallet_server: typing.Optional[str] = None): wallet_server: typing.Optional[str] = None):
await self.track(self._event(TIME_TO_FIRST_BYTES, _download_properties( await self.track(self._event(TIME_TO_FIRST_BYTES, _download_properties(
self.conf, self.external_ip, resolve_duration, total_duration, download_id, name, outpoint, self.conf, resolve_duration, total_duration, download_id, name, outpoint,
found_peers_count, tried_peers_count, connection_failures_count, added_fixed_peers, fixed_peers_delay, found_peers_count, tried_peers_count, connection_failures_count, added_fixed_peers, fixed_peers_delay,
sd_hash, sd_download_duration, head_blob_hash, head_blob_length, head_blob_duration, error, error_msg, sd_hash, sd_download_duration, head_blob_hash, head_blob_length, head_blob_duration, error, error_msg,
wallet_server wallet_server
@ -227,7 +221,7 @@ class AnalyticsManager:
return { return {
'userId': 'lbry', 'userId': 'lbry',
'event': event, 'event': event,
'properties': _event_properties(self.installation_id, self.session_id, properties), 'properties': _event_properties(self.analytics_id, properties),
'context': self.context, 'context': self.context,
'timestamp': utils.isonow() 'timestamp': utils.isonow()
} }

View file

@ -325,8 +325,7 @@ class Daemon(metaclass=JSONRPCServerType):
self._video_file_analyzer = VideoFileAnalyzer(conf) self._video_file_analyzer = VideoFileAnalyzer(conf)
self._node_id = None self._node_id = None
self._installation_id = None self._installation_id = None
self.session_id = base58.b58encode(utils.generate_id()).decode() self.analytics_manager = analytics.AnalyticsManager(conf)
self.analytics_manager = analytics.AnalyticsManager(conf, self.installation_id, self.session_id)
self.component_manager = component_manager or ComponentManager( self.component_manager = component_manager or ComponentManager(
conf, analytics_manager=self.analytics_manager, conf, analytics_manager=self.analytics_manager,
skip_components=conf.components_to_skip or [] skip_components=conf.components_to_skip or []

View file

@ -9,7 +9,6 @@ from decimal import Decimal
from lbry.file.file_manager import FileManager from lbry.file.file_manager import FileManager
from tests.unit.blob_exchange.test_transfer_blob import BlobExchangeTestBase from tests.unit.blob_exchange.test_transfer_blob import BlobExchangeTestBase
from lbry.testcase import get_fake_exchange_rate_manager from lbry.testcase import get_fake_exchange_rate_manager
from lbry.utils import generate_id
from lbry.error import InsufficientFundsError from lbry.error import InsufficientFundsError
from lbry.error import KeyFeeAboveMaxAllowedError, ResolveError, DownloadSDTimeoutError, DownloadDataTimeoutError from lbry.error import KeyFeeAboveMaxAllowedError, ResolveError, DownloadSDTimeoutError, DownloadDataTimeoutError
from lbry.wallet import WalletManager, Wallet, Ledger, Transaction, Input, Output, Database from lbry.wallet import WalletManager, Wallet, Ledger, Transaction, Input, Output, Database
@ -140,11 +139,7 @@ class TestStreamManager(BlobExchangeTestBase):
self.sd_hash = descriptor.sd_hash self.sd_hash = descriptor.sd_hash
self.mock_wallet, self.uri = await get_mock_wallet(self.sd_hash, self.client_storage, self.client_wallet_dir, self.mock_wallet, self.uri = await get_mock_wallet(self.sd_hash, self.client_storage, self.client_wallet_dir,
balance, fee) balance, fee)
analytics_manager = AnalyticsManager( analytics_manager = AnalyticsManager(self.client_config)
self.client_config,
binascii.hexlify(generate_id()).decode(),
binascii.hexlify(generate_id()).decode()
)
self.stream_manager = StreamManager( self.stream_manager = StreamManager(
self.loop, self.client_config, self.client_blob_manager, self.mock_wallet, self.loop, self.client_config, self.client_blob_manager, self.mock_wallet,
self.client_storage, get_mock_node(self.server_from_client), self.client_storage, get_mock_node(self.server_from_client),