Merge pull request #3845 from ghjm/gather_analytics_dry_run

Add a --dry-run option to gather analytics locally, even if analytics is disabled in settings.
This commit is contained in:
Graham Mainwaring 2019-10-17 16:17:18 -04:00 committed by GitHub
commit a038f9fd78
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -88,8 +88,8 @@ def gather(dest=None, module=None, collection_type='scheduled'):
logger.exception("Invalid License provided, or No License Provided")
return "Error: Invalid License provided, or No License Provided"
if not settings.INSIGHTS_TRACKING_STATE:
logger.error("Automation Analytics not enabled")
if collection_type != 'dry-run' and not settings.INSIGHTS_TRACKING_STATE:
logger.error("Automation Analytics not enabled. Use --dry-run to gather locally without sending.")
return
if module is None:

View File

@ -11,6 +11,8 @@ class Command(BaseCommand):
help = 'Gather AWX analytics data'
def add_arguments(self, parser):
parser.add_argument('--dry-run', dest='dry-run', action='store_true',
help='Gather analytics without shipping. Works even if analytics are disabled in settings.')
parser.add_argument('--ship', dest='ship', action='store_true',
help='Enable to ship metrics to the Red Hat Cloud')
@ -23,9 +25,14 @@ class Command(BaseCommand):
self.logger.propagate = False
def handle(self, *args, **options):
tgz = gather(collection_type='manual')
self.init_logging()
opt_ship = options.get('ship')
opt_dry_run = options.get('dry-run')
if opt_ship and opt_dry_run:
self.logger.error('Both --ship and --dry-run cannot be processed at the same time.')
return
tgz = gather(collection_type='manual' if not opt_dry_run else 'dry-run')
if tgz:
self.logger.debug(tgz)
if options.get('ship'):
if opt_ship:
ship(tgz)