def test_trace_component_for_trigger_instance(self): # action_trigger trace_component = trace_service.get_trace_component_for_trigger_instance( self.action_trigger) expected = { 'id': str(self.action_trigger.id), 'ref': self.action_trigger.trigger, 'caused_by': { 'type': 'action_execution', 'id': self.action_trigger.payload['execution_id'] } } self.assertEqual(trace_component, expected) # notify_trigger trace_component = trace_service.get_trace_component_for_trigger_instance( self.notify_trigger) expected = { 'id': str(self.notify_trigger.id), 'ref': self.notify_trigger.trigger, 'caused_by': { 'type': 'action_execution', 'id': self.notify_trigger.payload['execution_id'] } } self.assertEqual(trace_component, expected) # non_internal_trigger trace_component = trace_service.get_trace_component_for_trigger_instance( self.non_internal_trigger) expected = { 'id': str(self.non_internal_trigger.id), 'ref': self.non_internal_trigger.trigger, 'caused_by': {} } self.assertEqual(trace_component, expected)
def test_trace_component_for_trigger_instance(self): # action_trigger trace_component = trace_service.get_trace_component_for_trigger_instance( self.action_trigger) expected = { 'id': str(self.action_trigger.id), 'ref': self.action_trigger.trigger, 'caused_by': { 'type': 'action_execution', 'id': self.action_trigger.payload['execution_id'] } } self.assertEqual(trace_component, expected) # notify_trigger trace_component = trace_service.get_trace_component_for_trigger_instance( self.notify_trigger) expected = { 'id': str(self.notify_trigger.id), 'ref': self.notify_trigger.trigger, 'caused_by': { 'type': 'action_execution', 'id': self.notify_trigger.payload['execution_id'] } } self.assertEqual(trace_component, expected) # non_internal_trigger trace_component = trace_service.get_trace_component_for_trigger_instance( self.non_internal_trigger) expected = { 'id': str(self.non_internal_trigger.id), 'ref': self.non_internal_trigger.trigger, 'caused_by': {} } self.assertEqual(trace_component, expected)
def test_trace_component_for_trigger_instance(self): # action_trigger trace_component = trace_service.get_trace_component_for_trigger_instance( self.action_trigger) expected = { "id": str(self.action_trigger.id), "ref": self.action_trigger.trigger, "caused_by": { "type": "action_execution", "id": self.action_trigger.payload["execution_id"], }, } self.assertEqual(trace_component, expected) # notify_trigger trace_component = trace_service.get_trace_component_for_trigger_instance( self.notify_trigger) expected = { "id": str(self.notify_trigger.id), "ref": self.notify_trigger.trigger, "caused_by": { "type": "action_execution", "id": self.notify_trigger.payload["execution_id"], }, } self.assertEqual(trace_component, expected) # non_internal_trigger trace_component = trace_service.get_trace_component_for_trigger_instance( self.non_internal_trigger) expected = { "id": str(self.non_internal_trigger.id), "ref": self.non_internal_trigger.trigger, "caused_by": {}, } self.assertEqual(trace_component, expected)
def process(self, pre_ack_response): trigger_instance, message = self._decompose_pre_ack_process_response( pre_ack_response) if not trigger_instance: raise ValueError("No trigger_instance provided for processing.") get_driver().inc_counter("trigger.%s.processed" % (trigger_instance.trigger)) try: # Use trace_context from the message and if not found create a new context # and use the trigger_instance.id as trace_tag. trace_context = message.get(TRACE_CONTEXT, None) if not trace_context: trace_context = { TRACE_ID: "trigger_instance-%s" % str(trigger_instance.id) } # add a trace or update an existing trace with trigger_instance trace_service.add_or_update_given_trace_context( trace_context=trace_context, trigger_instances=[ trace_service.get_trace_component_for_trigger_instance( trigger_instance) ], ) container_utils.update_trigger_instance_status( trigger_instance, trigger_constants.TRIGGER_INSTANCE_PROCESSING) with CounterWithTimer(key="rule.processed"): with Timer(key="trigger.%s.processed" % (trigger_instance.trigger)): self.rules_engine.handle_trigger_instance(trigger_instance) container_utils.update_trigger_instance_status( trigger_instance, trigger_constants.TRIGGER_INSTANCE_PROCESSED) except: # TODO : Capture the reason for failure. container_utils.update_trigger_instance_status( trigger_instance, trigger_constants.TRIGGER_INSTANCE_PROCESSING_FAILED) # This could be a large message but at least in case of an exception # we get to see more context. # Beyond this point code cannot really handle the exception anyway so # eating up the exception. LOG.exception("Failed to handle trigger_instance %s.", trigger_instance) return
def process(self, instance): trigger = instance['trigger'] payload = instance['payload'] trigger_instance = None try: trigger_instance = container_utils.create_trigger_instance( trigger, payload or {}, date_utils.get_datetime_utc_now(), raise_on_no_trigger=True) except: # We got a trigger ref but we were unable to create a trigger instance. # This could be because a trigger object wasn't found in db for the ref. LOG.exception('Failed to create trigger_instance %s.', instance) return if trigger_instance: try: # Use trace_context from the instance and if not found create a new context # and use the trigger_instance.id as trace_tag. trace_context = instance.get(TRACE_CONTEXT, None) if not trace_context: trace_context = { TRACE_ID: 'trigger_instance-%s' % str(trigger_instance.id) } # add a trace or update an existing trace with trigger_instance trace_service.add_or_update_given_trace_context( trace_context=trace_context, trigger_instances=[ trace_service.get_trace_component_for_trigger_instance( trigger_instance) ]) self.rules_engine.handle_trigger_instance(trigger_instance) except: # This could be a large message but at least in case of an exception # we get to see more context. # Beyond this point code cannot really handle the exception anyway so # eating up the exception. LOG.exception('Failed to handle trigger_instance %s.', instance) return
def process(self, pre_ack_response): trigger_instance, message = self._decompose_pre_ack_process_response(pre_ack_response) if not trigger_instance: raise ValueError('No trigger_instance provided for processing.') get_driver().inc_counter('trigger.%s.processed' % (trigger_instance.trigger)) try: # Use trace_context from the message and if not found create a new context # and use the trigger_instance.id as trace_tag. trace_context = message.get(TRACE_CONTEXT, None) if not trace_context: trace_context = { TRACE_ID: 'trigger_instance-%s' % str(trigger_instance.id) } # add a trace or update an existing trace with trigger_instance trace_service.add_or_update_given_trace_context( trace_context=trace_context, trigger_instances=[ trace_service.get_trace_component_for_trigger_instance(trigger_instance) ] ) container_utils.update_trigger_instance_status( trigger_instance, trigger_constants.TRIGGER_INSTANCE_PROCESSING) with CounterWithTimer(key='rule.processed'): with Timer(key='trigger.%s.processed' % (trigger_instance.trigger)): self.rules_engine.handle_trigger_instance(trigger_instance) container_utils.update_trigger_instance_status( trigger_instance, trigger_constants.TRIGGER_INSTANCE_PROCESSED) except: # TODO : Capture the reason for failure. container_utils.update_trigger_instance_status( trigger_instance, trigger_constants.TRIGGER_INSTANCE_PROCESSING_FAILED) # This could be a large message but at least in case of an exception # we get to see more context. # Beyond this point code cannot really handle the exception anyway so # eating up the exception. LOG.exception('Failed to handle trigger_instance %s.', trigger_instance) return
def process(self, instance): trigger = instance['trigger'] payload = instance['payload'] trigger_instance = None try: trigger_instance = container_utils.create_trigger_instance( trigger, payload or {}, date_utils.get_datetime_utc_now(), raise_on_no_trigger=True) except: # We got a trigger ref but we were unable to create a trigger instance. # This could be because a trigger object wasn't found in db for the ref. LOG.exception('Failed to create trigger_instance %s.', instance) return if trigger_instance: try: # Use trace_context from the instance and if not found create a new context # and use the trigger_instance.id as trace_tag. trace_context = instance.get(TRACE_CONTEXT, None) if not trace_context: trace_context = { TRACE_ID: 'trigger_instance-%s' % str(trigger_instance.id) } # add a trace or update an existing trace with trigger_instance trace_service.add_or_update_given_trace_context( trace_context=trace_context, trigger_instances=[ trace_service.get_trace_component_for_trigger_instance(trigger_instance) ]) self.rules_engine.handle_trigger_instance(trigger_instance) except: # This could be a large message but at least in case of an exception # we get to see more context. # Beyond this point code cannot really handle the exception anyway so # eating up the exception. LOG.exception('Failed to handle trigger_instance %s.', instance) return