mirror of
https://github.com/ansible/awx.git
synced 2026-02-18 11:40:05 -03:30
Properly parse datetimes from AUTOMATION_ANALYTICS_LAST_ENTRIES
This commit is contained in:
@@ -12,7 +12,7 @@ from django.utils.timezone import now, timedelta
|
|||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from awx.conf.license import get_license
|
from awx.conf.license import get_license
|
||||||
from awx.main.utils import get_awx_version, get_custom_venv_choices, camelcase_to_underscore
|
from awx.main.utils import get_awx_version, get_custom_venv_choices, camelcase_to_underscore, datetime_hook
|
||||||
from awx.main import models
|
from awx.main import models
|
||||||
from django.contrib.sessions.models import Session
|
from django.contrib.sessions.models import Session
|
||||||
from awx.main.analytics import register
|
from awx.main.analytics import register
|
||||||
@@ -42,7 +42,7 @@ def trivial_slicing(key, since, until):
|
|||||||
|
|
||||||
horizon = until - timedelta(weeks=4)
|
horizon = until - timedelta(weeks=4)
|
||||||
last_entries = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_ENTRIES').first()
|
last_entries = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_ENTRIES').first()
|
||||||
last_entries = json.loads((last_entries.value if last_entries is not None else '') or '{}')
|
last_entries = json.loads((last_entries.value if last_entries is not None else '') or '{}', object_hook=datetime_hook)
|
||||||
last_entry = max(last_entries.get(key) or settings.AUTOMATION_ANALYTICS_LAST_GATHER or horizon, horizon)
|
last_entry = max(last_entries.get(key) or settings.AUTOMATION_ANALYTICS_LAST_GATHER or horizon, horizon)
|
||||||
return [(last_entry, until)]
|
return [(last_entry, until)]
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ def four_hour_slicing(key, since, until):
|
|||||||
|
|
||||||
horizon = until - timedelta(weeks=4)
|
horizon = until - timedelta(weeks=4)
|
||||||
last_entries = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_ENTRIES').first()
|
last_entries = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_ENTRIES').first()
|
||||||
last_entries = json.loads((last_entries.value if last_entries is not None else '') or '{}')
|
last_entries = json.loads((last_entries.value if last_entries is not None else '') or '{}', object_hook=datetime_hook)
|
||||||
last_entry = max(last_entries.get(key) or settings.AUTOMATION_ANALYTICS_LAST_GATHER or horizon, horizon)
|
last_entry = max(last_entries.get(key) or settings.AUTOMATION_ANALYTICS_LAST_GATHER or horizon, horizon)
|
||||||
|
|
||||||
start, end = last_entry, None
|
start, end = last_entry, None
|
||||||
@@ -70,7 +70,7 @@ def events_slicing(key, since, until):
|
|||||||
|
|
||||||
last_gather = settings.AUTOMATION_ANALYTICS_LAST_GATHER
|
last_gather = settings.AUTOMATION_ANALYTICS_LAST_GATHER
|
||||||
last_entries = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_ENTRIES').first()
|
last_entries = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_ENTRIES').first()
|
||||||
last_entries = json.loads((last_entries.value if last_entries is not None else '') or '{}')
|
last_entries = json.loads((last_entries.value if last_entries is not None else '') or '{}', object_hook=datetime_hook)
|
||||||
horizon = until - timedelta(weeks=4)
|
horizon = until - timedelta(weeks=4)
|
||||||
|
|
||||||
lower = since or last_gather or horizon
|
lower = since or last_gather or horizon
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import requests
|
|||||||
from awx.conf.license import get_license
|
from awx.conf.license import get_license
|
||||||
from awx.main.models import Job
|
from awx.main.models import Job
|
||||||
from awx.main.access import access_registry
|
from awx.main.access import access_registry
|
||||||
from awx.main.utils import get_awx_http_client_headers, set_environ
|
from awx.main.utils import get_awx_http_client_headers, set_environ, datetime_hook
|
||||||
from awx.main.utils.pglock import advisory_lock
|
from awx.main.utils.pglock import advisory_lock
|
||||||
|
|
||||||
__all__ = ['register', 'gather', 'ship']
|
__all__ = ['register', 'gather', 'ship']
|
||||||
@@ -163,7 +163,7 @@ def gather(dest=None, module=None, subset=None, since=None, until=None, collecti
|
|||||||
last_gather = max(settings.AUTOMATION_ANALYTICS_LAST_GATHER or horizon, horizon)
|
last_gather = max(settings.AUTOMATION_ANALYTICS_LAST_GATHER or horizon, horizon)
|
||||||
|
|
||||||
last_entries = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_ENTRIES').first()
|
last_entries = Setting.objects.filter(key='AUTOMATION_ANALYTICS_LAST_ENTRIES').first()
|
||||||
last_entries = json.loads((last_entries.value if last_entries is not None else '') or '{}')
|
last_entries = json.loads((last_entries.value if last_entries is not None else '') or '{}', object_hook=datetime_hook)
|
||||||
|
|
||||||
collector_module = module if module else collectors
|
collector_module = module if module else collectors
|
||||||
collector_list = [
|
collector_list = [
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ from functools import reduce, wraps
|
|||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
from dateutil import parser
|
||||||
|
|
||||||
# Django
|
# Django
|
||||||
from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
|
from django.core.exceptions import ObjectDoesNotExist, FieldDoesNotExist
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
@@ -54,6 +56,7 @@ __all__ = [
|
|||||||
'copy_m2m_relationships',
|
'copy_m2m_relationships',
|
||||||
'prefetch_page_capabilities',
|
'prefetch_page_capabilities',
|
||||||
'to_python_boolean',
|
'to_python_boolean',
|
||||||
|
'datetime_hook',
|
||||||
'ignore_inventory_computed_fields',
|
'ignore_inventory_computed_fields',
|
||||||
'ignore_inventory_group_removal',
|
'ignore_inventory_group_removal',
|
||||||
'_inventory_updates',
|
'_inventory_updates',
|
||||||
@@ -115,6 +118,16 @@ def to_python_boolean(value, allow_none=False):
|
|||||||
raise ValueError(_(u'Unable to convert "%s" to boolean') % value)
|
raise ValueError(_(u'Unable to convert "%s" to boolean') % value)
|
||||||
|
|
||||||
|
|
||||||
|
def datetime_hook(d):
|
||||||
|
new_d = {}
|
||||||
|
for key, value in d.items():
|
||||||
|
try:
|
||||||
|
new_d[key] = parser.parse(value)
|
||||||
|
except Exception:
|
||||||
|
new_d[key] = value
|
||||||
|
return new_d
|
||||||
|
|
||||||
|
|
||||||
def camelcase_to_underscore(s):
|
def camelcase_to_underscore(s):
|
||||||
"""
|
"""
|
||||||
Convert CamelCase names to lowercase_with_underscore.
|
Convert CamelCase names to lowercase_with_underscore.
|
||||||
|
|||||||
Reference in New Issue
Block a user