Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove computed inventory fields from Host and Group #5448

Conversation

ryanpetrello
Copy link
Contributor

@ryanpetrello ryanpetrello commented Dec 4, 2019

'has_inventory_sources',
'total_inventory_sources',
'inventory_sources_with_failures',
'organization_id',
'kind',
'insights_credential_id',),
'host': DEFAULT_SUMMARY_FIELDS + ('has_active_failures',
'has_inventory_sources'),
'group': DEFAULT_SUMMARY_FIELDS + ('has_active_failures',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Group loses all of these - assuming we remove the green/red icons and don't care about API backwards compat at /api/v2/dashboard/, I can't see any tangible reason we spend our time calculating these.

We deprecated these fields recently.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assuming we ... don't care about API backwards compat at /api/v2/dashboard/

I can't imagine that we do

assuming we remove the green/red icons

That is a removal of user-facing functionality. There is very non-trivial meaning in those orbs, because the Ansible notion of membership includes indirect via children groups. At the same time, merely a red/green indicator is a pretty gross over-simplification. Anyway, the final call is within the UX wheelhouse.

'has_inventory_sources',
'total_inventory_sources',
'inventory_sources_with_failures',
'organization_id',
'kind',
'insights_credential_id',),
'host': DEFAULT_SUMMARY_FIELDS + ('has_active_failures',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Host loses all of these, and they're replaced w/ queries that generate the data from other sources:

https://github.com/ansible/awx/pull/5448/files#diff-a81324c523b41de7296fdd5ff9063d10R1748

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the performance differential when handling this in the list views?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matburt the prior case is going to be slightly faster on list views (it's just two boolean field lookups).

The after version has two new generated fields on the list view now:

def get_has_active_failures(self, obj):
    return bool(
        obj.last_job_host_summary and obj.last_job_host_summary.failed
    )

def get_has_inventory_sources(self, obj):
     return obj.inventory_sources.exists()

Here's the /api/v2/hosts/ list view before I preloaded my database with a bunch of data. Note that I've set up an inventory w/ a bunch of hosts:

awx-dev=> SELECT COUNT(*) FROM main_host;
 count
-------
 22809
(1 row)

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next, I made a bunch of inventory sources, and a ton of JobHostSummary objects associated with every host:

In [1]: i = Inventory.objects.first()

In [2]: for s in InventorySource.objects.all():
   ...:     for h in Host.objects.all():
   ...:         h.inventory_sources.add(s)
   ...:
In [24]: for i in range(MANY):
    ...:     j = Job.objects.create()
    ...:     for h in Host.objects.all():
    ...:         j.job_host_summaries.get_or_create(host=h, host_name=h.name, defaults=host_stats)
    ...:
    ...:
awx-dev=> SELECT COUNT(*) FROM main_jobhostsummary;
 count
--------
 633365
(1 row)

awx-dev=> SELECT COUNT(*) FROM main_host_inventory_sources;
 count
-------
 132610
(1 row)

First pass on this shows that it's definitely slower, but not that much slower:

image

I'm going to keep running my data generator all day and see if I can get some of these tables into the millions and see if I notice any additional performance degradation.

I'll also see if I can sprinkle in some ORM prefetching to cut down on these queries a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: I added some more prefetching to speed this up a bit, and it cut the query count in half:

https://github.com/ansible/awx/pull/5448/files#r362574316

@@ -204,20 +204,14 @@ def get(self, request, format=None):
'failed': ec2_inventory_failed.count()}

user_groups = get_user_queryset(request.user, models.Group)
groups_job_failed = (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes group-based failure tracking no longer exist/supported at /api/v2/dashboard/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels like this was for the old inventory model when groups and inventory sources were tied together.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that's my impression, too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ryanpetrello ryanpetrello force-pushed the remove-computed-group-and-host-fields branch 2 times, most recently from 1a3fccd to 2384ccf Compare December 4, 2019 18:11
@ryanpetrello
Copy link
Contributor Author

Inventory failure tracking still works:

image

image

image

@ryanpetrello
Copy link
Contributor Author

Host state and recent jobs tracking works:

image

image

@ryanpetrello
Copy link
Contributor Author

Groups have no status indicators anymore:

image

@ryanpetrello
Copy link
Contributor Author

ryanpetrello commented Dec 4, 2019

Dashboard loads, and the top failure links work when clicked on:

image

image

image

@ryanpetrello ryanpetrello force-pushed the remove-computed-group-and-host-fields branch from 2384ccf to 2db4181 Compare December 4, 2019 18:18
@@ -1756,6 +1745,14 @@ def to_representation(self, obj):
ret['last_job_host_summary'] = None
return ret

def get_has_active_failures(self, obj):
return bool(
obj.last_job_host_summary and obj.last_job_host_summary.failed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so I guess we're already fetching this information and showing it in summary_fields. And fetching it... and even more

awx/awx/main/access.py

Lines 908 to 909 in 90d38a5

select_related = ('created_by', 'modified_by', 'inventory',
'last_job__job_template', 'last_job_host_summary__job',)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

data['hosts'] = {'url': reverse('api:host_list', request=request),
'failures_url': reverse('api:host_list', request=request) + "?has_active_failures=True",
'failures_url': reverse('api:host_list', request=request) + "?last_job_host_summary__failed=True",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing this filter, I get different answers in my own server compared to doing /api/v2/hosts/?last_job__failed=true. Reason still unclear.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, this means that the host had failed tasks.

last job failed means that any host in the last job this host was a part of failed.

@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@ryanpetrello ryanpetrello changed the title remove computed inventory fields from Host and Group WIP: remove computed inventory fields from Host and Group Dec 4, 2019
)

def get_has_inventory_sources(self, obj):
return obj.inventory_sources.exists()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably incur an additional query. However, I see it as a valid candidate for prefetch_related, because there will be a large amount of duplication in many cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I checked, and this does add more queries, so I added it to prefetch_related and watched the query count go down.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. That might exhaust the actionable comments I had. I will go back over the diff one last time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AlanCoding
Copy link
Member

I was worried about this, but much lower concern after seeing this. I would still like to profile the queries from the hosts endpoints.

@ryanpetrello
Copy link
Contributor Author

I was worried about this, but much lower concern after seeing this. I would still like to profile the queries from the hosts endpoints.

I do think we should add an index to main_jobhostsummary.failed

@ryanpetrello ryanpetrello force-pushed the remove-computed-group-and-host-fields branch from 2db4181 to 0171f8a Compare December 4, 2019 20:32
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@ryanpetrello ryanpetrello force-pushed the remove-computed-group-and-host-fields branch from 0171f8a to 057334a Compare December 4, 2019 20:51
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@ryanpetrello ryanpetrello force-pushed the remove-computed-group-and-host-fields branch from 057334a to 1a53f82 Compare December 4, 2019 22:05
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

Copy link
Member

@kdelee kdelee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested the API changes as they effect us, looks good to me! Will leave it up to @dsesami for final approval from UI perspective

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@jakemcdermott jakemcdermott force-pushed the remove-computed-group-and-host-fields branch from af97959 to c2d3357 Compare January 8, 2020 17:19
Copy link
Contributor

@dsesami dsesami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UI changes look good, thanks for this.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@ryanpetrello ryanpetrello force-pushed the remove-computed-group-and-host-fields branch from c2d3357 to dfffa87 Compare January 13, 2020 15:09
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@ryanpetrello ryanpetrello force-pushed the remove-computed-group-and-host-fields branch from 588d460 to ed9222a Compare January 14, 2020 21:38
@softwarefactory-project-zuul
Copy link
Contributor

Build failed.

@ryanpetrello ryanpetrello force-pushed the remove-computed-group-and-host-fields branch from ed9222a to be68a19 Compare January 14, 2020 21:58
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@softwarefactory-project-zuul
Copy link
Contributor

Build failed (gate pipeline). For information on how to proceed, see
http://docs.openstack.org/infra/manual/developers.html#automated-testing

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.

@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 6d075b8 into ansible:devel Jan 15, 2020
AlexSCorey pushed a commit to AlexSCorey/awx that referenced this pull request Dec 7, 2021
Move only_transmit_kwargs calculation out of thread
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants