Skip to content

Commit

Permalink
Merge pull request #9335 from beeankha/ee_analytics
Browse files Browse the repository at this point in the history
Detect EE Collections Name and Version Info

Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
  • Loading branch information
softwarefactory-project-zuul[bot] authored Feb 23, 2021
2 parents b42a39a + 2d86c59 commit bc45493
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
5 changes: 3 additions & 2 deletions awx/main/analytics/collectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ def events_table(since, full_path, until, **kwargs):
return _copy_table(table='events', query=events_query, path=full_path)


@register('unified_jobs_table', '1.1', format='csv', description=_('Data on jobs run'), expensive=True)
@register('unified_jobs_table', '1.2', format='csv', description=_('Data on jobs run'), expensive=True)
def unified_jobs_table(since, full_path, until, **kwargs):
unified_job_query = '''COPY (SELECT main_unifiedjob.id,
main_unifiedjob.polymorphic_ctype_id,
Expand All @@ -334,7 +334,8 @@ def unified_jobs_table(since, full_path, until, **kwargs):
main_unifiedjob.finished,
main_unifiedjob.elapsed,
main_unifiedjob.job_explanation,
main_unifiedjob.instance_group_id
main_unifiedjob.instance_group_id,
main_unifiedjob.installed_collections
FROM main_unifiedjob
JOIN django_content_type ON main_unifiedjob.polymorphic_ctype_id = django_content_type.id
LEFT JOIN main_job ON main_unifiedjob.id = main_job.unifiedjob_ptr_id
Expand Down
19 changes: 19 additions & 0 deletions awx/main/migrations/0129_unifiedjob_installed_collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 2.2.16 on 2021-02-16 20:27

import awx.main.fields
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('main', '0128_organiaztion_read_roles_ee_admin'),
]

operations = [
migrations.AddField(
model_name='unifiedjob',
name='installed_collections',
field=awx.main.fields.JSONBField(blank=True, default=dict, editable=False, help_text='The Collections names and versions installed in the execution environment.'),
),
]
8 changes: 7 additions & 1 deletion awx/main/models/unified_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
from awx.main.constants import ACTIVE_STATES, CAN_CANCEL
from awx.main.redact import UriCleaner, REPLACE_STR
from awx.main.consumers import emit_channel_notification
from awx.main.fields import JSONField, AskForField, OrderedManyToManyField
from awx.main.fields import JSONField, JSONBField, AskForField, OrderedManyToManyField

__all__ = ['UnifiedJobTemplate', 'UnifiedJob', 'StdoutMaxBytesExceeded']

Expand Down Expand Up @@ -722,6 +722,12 @@ class Meta:
'Credential',
related_name='%(class)ss',
)
installed_collections = JSONBField(
blank=True,
default=dict,
editable=False,
help_text=_("The Collections names and versions installed in the execution environment."),
)

def get_absolute_url(self, request=None):
RealClass = self.get_real_instance_class()
Expand Down
8 changes: 7 additions & 1 deletion awx/main/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,11 +1179,17 @@ def final_run_hook(self, instance, status, private_data_dir, fact_modification_t
instance.log_lifecycle("finalize_run")
job_profiling_dir = os.path.join(private_data_dir, 'artifacts/playbook_profiling')
awx_profiling_dir = '/var/log/tower/playbook_profiling/'
collections_info = os.path.join(private_data_dir, 'artifacts/', 'collections.json')

if not os.path.exists(awx_profiling_dir):
os.mkdir(awx_profiling_dir)
if os.path.isdir(job_profiling_dir):
shutil.copytree(job_profiling_dir, os.path.join(awx_profiling_dir, str(instance.pk)))

if os.path.exists(collections_info):
with open(collections_info) as ee_json_info:
ee_collections_info = json.loads(ee_json_info.read())
instance.installed_collections = ee_collections_info
instance.save(update_fields=['installed_collections'])

def event_handler(self, event_data):
#
Expand Down

0 comments on commit bc45493

Please sign in to comment.