From 6123b8e1480c47a243ac8202b20b0a885a1962ff Mon Sep 17 00:00:00 2001 From: Jim Ladd Date: Tue, 6 Apr 2021 14:21:53 -0700 Subject: [PATCH] query for jobevents based on table location * pre-migration jobevents live in unpartitioned table where only created field has index * post-migration jobevents live in partitions where modified field has index (and should be used to ensure no events are missing) --- awx/main/analytics/collectors.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/awx/main/analytics/collectors.py b/awx/main/analytics/collectors.py index 8893e1431c..b220ff7ac5 100644 --- a/awx/main/analytics/collectors.py +++ b/awx/main/analytics/collectors.py @@ -15,7 +15,7 @@ from django.utils.translation import ugettext_lazy as _ from psycopg2.errors import UntranslatableCharacter from awx.conf.license import get_license -from awx.main.utils import get_awx_version, get_custom_venv_choices, camelcase_to_underscore, datetime_hook +from awx.main.utils import get_awx_version, get_custom_venv_choices, camelcase_to_underscore, datetime_hook, get_event_partition_epoch from awx.main import models from awx.main.analytics import register @@ -77,7 +77,17 @@ def events_slicing(key, since, until, last_gather): lower = since or last_gather if not since and last_entries.get(key): lower = horizon - pk_values = models.JobEvent.objects.filter(modified__gte=lower, modified__lte=until).aggregate(Min('pk'), Max('pk')) + partition_epoch = get_event_partition_epoch() + # JobEvent.modified index was created at the partition epoch + # Events created before this are in a separate table that does not + # have this index. + if lower >= partition_epoch: + pk_values = models.JobEvent.objects.filter(modified__gte=lower, modified__lte=until).aggregate(Min('pk'), Max('pk')) + elif until < partition_epoch: + pk_values = models.JobEvent.objects.filter(created__gte=lower, created__lte=until).aggregate(Min('pk'), Max('pk')) + else: + pk_values = models.JobEvent.objects.filter(created__gte=lower, created__lte=partition_epoch).aggregate(Min('pk')) + pk_values.update(models.JobEvent.objects.filter(modified__gte=partition_epoch, modified__lte=until).aggregate(Max('pk'))) previous_pk = pk_values['pk__min'] - 1 if pk_values['pk__min'] is not None else 0 if not since and last_entries.get(key):