Add some metric instrumentation to the notifer service code.
# limitations under the License.
from __future__ import absolute_import
+
from datetime import datetime
import json
@@ -45,6 +46,7 @@ from st2common.constants.action import ACTION_RESULTS_KV_PREFIX
from st2common.constants.keyvalue import FULL_SYSTEM_SCOPE, SYSTEM_SCOPE, DATASTORE_PARENT_SCOPE
from st2common.services.keyvalues import KeyValueLookup
from st2common.transport.queues import NOTIFIER_ACTIONUPDATE_WORK_QUEUE
+from st2common.metrics.base import CounterWithTimer
__all__ = [
'Notifier',
@@ -73,6 +75,7 @@ class Notifier(consumers.MessageHandler):
pack=ACTION_TRIGGER_TYPE['pack'],
name=ACTION_TRIGGER_TYPE['name'])
+ @CounterWithTimer(key='notifier.action.executions')
def process(self, execution_db):
execution_id = str(execution_db.id)
extra = {'execution': execution_db}
@@ -86,11 +89,15 @@ class Notifier(consumers.MessageHandler):
# action execution will be applied by the workflow engine. A policy may affect the
# final state of the action execution thereby impacting the state of the workflow.
if not workflow_service.is_action_execution_under_workflow_context(execution_db):
+ with CounterWithTimer(key='notifier.apply_post_run_policies'):
policy_service.apply_post_run_policies(liveaction_db)
if liveaction_db.notify is not None:
- self._post_notify_triggers(liveaction_db=liveaction_db, execution_db=execution_db)
+ with CounterWithTimer(key='notifier.notify_trigger.post'):
+ self._post_notify_triggers(liveaction_db=liveaction_db,
+ execution_db=execution_db)
+ with CounterWithTimer(key='notifier.generic_trigger.post'):
self._post_generic_trigger(liveaction_db=liveaction_db, execution_db=execution_db)
def _get_execution_for_liveaction(self, liveaction):
@@ -142,12 +149,14 @@ class Notifier(consumers.MessageHandler):
)
try:
+ with CounterWithTimer(key='notifier.transform_message'):
message = self._transform_message(message=message,
context=jinja_context)
except:
LOG.exception('Failed (Jinja) transforming `message`.')
try:
+ with CounterWithTimer(key='notifier.transform_data'):
data = self._transform_data(data=data, context=jinja_context)
except:
LOG.exception('Failed (Jinja) transforming `data`.')
@@ -187,6 +196,8 @@ class Notifier(consumers.MessageHandler):
payload['channel'] = route
LOG.debug('POSTing %s for %s. Payload - %s.', NOTIFY_TRIGGER_TYPE['name'],
liveaction_db.id, payload)
+
+ with CounterWithTimer(key='notifier.notify_trigger.dispatch'):
self._trigger_dispatcher.dispatch(self._notify_trigger, payload=payload,
trace_context=trace_context)
except:
@@ -254,6 +265,8 @@ class Notifier(consumers.MessageHandler):
trace_context = self._get_trace_context(execution_id=execution_id)
LOG.debug('POSTing %s for %s. Payload - %s. TraceContext - %s',
ACTION_TRIGGER_TYPE['name'], liveaction_db.id, payload, trace_context)
+
+ with CounterWithTimer(key='notifier.generic_trigger.dispatch'):
self._trigger_dispatcher.dispatch(self._action_trigger, payload=payload,
trace_context=trace_context)
