Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/azure-cli-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

DEPENDENCIES = [
'argcomplete~=1.8',
'azure-cli-telemetry==1.0.6.*',
'azure-cli-telemetry==1.0.7.*',
'azure-mgmt-core>=1.2.0,<2',
'cryptography',
'humanfriendly~=10.0',
Expand Down
4 changes: 4 additions & 0 deletions src/azure-cli-telemetry/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Release History
===============
1.0.7
+++++
* Support specifying `telemetry.push_interval_in_hours` to force push telemetry cache file

1.0.6
+++++
* Add `__version__` in `__init__.py`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import shutil
import stat
import tempfile
from knack.config import CLIConfig


class RecordsCollection:
Expand Down Expand Up @@ -35,8 +36,13 @@ def snapshot_and_read(self):
if not os.path.isdir(folder):
return

# Collect all cache.x files. If it has been a long time since last sent, also collect cache file itself.
push_interval = datetime.timedelta(hours=self._get_push_interval_config())
include_cache = datetime.datetime.now() - self._last_sent > push_interval
candidates = [(fn, os.stat(os.path.join(folder, fn))) for fn in os.listdir(folder)
if include_cache or fn != 'cache']

# sort the cache files base on their last modification time.
candidates = [(fn, os.stat(os.path.join(folder, fn))) for fn in os.listdir(folder) if fn != 'cache']
candidates = [(fn, file_stat) for fn, file_stat in candidates if stat.S_ISREG(file_stat.st_mode)]
candidates.sort(key=lambda pair: pair[1].st_mtime, reverse=True) # move the newer cache file first

Expand Down Expand Up @@ -66,6 +72,12 @@ def snapshot_and_read(self):
onerror=lambda _, p, tr: self._logger.error('Fail to remove file %s', p))
self._logger.info('Remove directory %s', tmp)

def _get_push_interval_config(self):
config = CLIConfig(config_dir=self._config_dir)
threshold = config.getint('telemetry', 'push_interval_in_hours', fallback=24)
# the threshold for push telemetry can't be less than 1 hour, default value is 24 hours
return threshold if threshold >= 1 else 24

def _read_file(self, path):
""" Read content of a telemetry cache file and parse them into records. """
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ def test_create_records_collection(self):
# take snapshot and move the files
collection.snapshot_and_read()

# all but one file, the 'cache' file, is moved.
self.assert_cache_files_count(1)
# all files are moved, including the 'cache' file.
self.assert_cache_files_count(0)

# total records
self.assertEqual(1750, len([r for r in collection]))
self.assertEqual(1758, len([r for r in collection]))

def test_create_records_collection_with_last_send(self):
last_send = datetime.datetime(year=2018, month=6, day=5, hour=16, minute=36, second=7)
last_send = datetime.datetime.now() - datetime.timedelta(hours=6)
collection = RecordsCollection(last_send, self.work_dir)
collection.snapshot_and_read()

# the threshold for pushing 'cache' file is 24, so 'cache' file should not be moved
self.assert_cache_files_count(1)
self.assertEqual(453, len([r for r in collection]))
# no new records since last_send
self.assertEqual(0, len([r for r in collection]))

def test_create_records_collection_against_missing_config_folder(self):
collection = RecordsCollection(datetime.datetime.min, tempfile.mktemp())
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-telemetry/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from codecs import open
from setuptools import setup

VERSION = "1.0.6"
VERSION = "1.0.7"

CLASSIFIERS = [
'Development Status :: 5 - Production/Stable',
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ asn1crypto==0.24.0
azure-appconfiguration==1.1.1
azure-batch==12.0.0
azure-cli-core==2.38.0
azure-cli-telemetry==1.0.6
azure-cli-telemetry==1.0.7
azure-cli==2.38.0
azure-common==1.1.22
azure-core==1.24.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ asn1crypto==0.24.0
azure-appconfiguration==1.1.1
azure-batch==12.0.0
azure-cli-core==2.38.0
azure-cli-telemetry==1.0.6
azure-cli-telemetry==1.0.7
azure-cli==2.38.0
azure-common==1.1.22
azure-core==1.24.0
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ asn1crypto==0.24.0
azure-appconfiguration==1.1.1
azure-batch==12.0.0
azure-cli-core==2.38.0
azure-cli-telemetry==1.0.6
azure-cli-telemetry==1.0.7
azure-cli==2.38.0
azure-common==1.1.22
azure-core==1.24.0
Expand Down