Add some conditions for always-send and never-send event types

Always send websocket messages for
  high priority events like playbook_on_stats

Never send websocket messages for
  events with no output
  unless they are a high priority event type
This commit is contained in:
Alan Rominger 2021-05-06 13:24:28 -04:00
parent b919befc90
commit 15effd7ade
No known key found for this signature in database
GPG Key ID: C2D7EAAA12B63559
3 changed files with 20 additions and 13 deletions

View File

@ -41,6 +41,7 @@ STANDARD_INVENTORY_UPDATE_ENV = {
}
CAN_CANCEL = ('new', 'pending', 'waiting', 'running')
ACTIVE_STATES = CAN_CANCEL
MINIMAL_EVENTS = set(['playbook_on_play_start', 'playbook_on_task_start', 'playbook_on_stats', 'EOF'])
CENSOR_VALUE = '************'
ENV_BLOCKLIST = frozenset(
(

View File

@ -17,6 +17,7 @@ from awx.api.versioning import reverse
from awx.main import consumers
from awx.main.managers import DeferJobCreatedManager
from awx.main.fields import JSONField
from awx.main.constants import MINIMAL_EVENTS
from awx.main.models.base import CreatedModifiedModel
from awx.main.utils import ignore_inventory_computed_fields, camelcase_to_underscore
@ -57,9 +58,6 @@ def create_host_status_counts(event_data):
return dict(host_status_counts)
MINIMAL_EVENTS = set(['playbook_on_play_start', 'playbook_on_task_start', 'playbook_on_stats', 'EOF'])
def emit_event_detail(event):
if settings.UI_LIVE_UPDATES_ENABLED is False and event.event not in MINIMAL_EVENTS:
return

View File

@ -57,7 +57,7 @@ from receptorctl.socket_interface import ReceptorControl
# AWX
from awx import __version__ as awx_application_version
from awx.main.constants import PRIVILEGE_ESCALATION_METHODS, STANDARD_INVENTORY_UPDATE_ENV
from awx.main.constants import PRIVILEGE_ESCALATION_METHODS, STANDARD_INVENTORY_UPDATE_ENV, MINIMAL_EVENTS
from awx.main.access import access_registry
from awx.main.redact import UriCleaner
from awx.main.models import (
@ -1158,17 +1158,25 @@ class BaseTask(object):
first_window_time = self.recent_event_timings[0]
last_window_time = self.recent_event_timings[-1]
should_emit = bool(
# if 30the most recent websocket message was sent over 1 second ago
cpu_time - first_window_time > 1.0
# if the very last websocket message came in over 1/30 seconds ago
or self.recent_event_timings.maxlen * (cpu_time - last_window_time) > 1.0
# if the queue is not yet full
or (len(self.recent_event_timings) != self.recent_event_timings.maxlen)
)
if event_data.get('event') in MINIMAL_EVENTS:
should_emit = True # always send some types like playbook_on_stats
if event_data.get('stdout') == '' and event_data['start_line'] == event_data['end_line']:
should_emit = False # exclude events with no output
else:
should_emit = any(
[
# if 30the most recent websocket message was sent over 1 second ago
cpu_time - first_window_time > 1.0,
# if the very last websocket message came in over 1/30 seconds ago
self.recent_event_timings.maxlen * (cpu_time - last_window_time) > 1.0,
# if the queue is not yet full
len(self.recent_event_timings) != self.recent_event_timings.maxlen,
]
)
logger.debug(
'Event {} websocket send {}, queue {}, avg rate {}, last rate {}'.format(
'Job {} event {} websocket send {}, queued: {}, rate - avg: {:.3f}, last: {:.3f}'.format(
self.instance.id,
event_data.get('counter', 0),
should_emit,
len(self.recent_event_timings),