Skip to content

Commit 4f153d2

Browse files
authored
Add instrumentation for step functions and CREATE, UPDATE, and COMMENT operations (#752)
1 parent c1deed7 commit 4f153d2

File tree

2 files changed

+62
-1
lines changed

2 files changed

+62
-1
lines changed

jbi/runner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __call__(self, context: ActionContext) -> ActionResult:
105105
try:
106106
step_kwargs = self.build_step_kwargs(step)
107107
context = step(context=context, **step_kwargs)
108+
statsd.incr(f"jbi.steps.{step.__name__}.count")
108109
except IncompleteStepError as exc:
109110
# Step did not execute all its operations.
110111
context = exc.context
@@ -248,7 +249,7 @@ def execute_action(
248249
)
249250
executor = Executor(parameters=action.parameters)
250251
handled, details = executor(context=action_context)
251-
252+
statsd.incr(f"jbi.operation.{action_context.operation.lower()}.count")
252253
logger.info(
253254
"Action %r executed successfully for Bug %s",
254255
action.whiteboard_tag,

tests/unit/test_runner.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,3 +440,63 @@ def test_counter_is_incremented_when_workflows_was_incomplete(
440440
callable_object(context=context_create_example)
441441

442442
mocked.incr.assert_called_with("jbi.action.fnx.incomplete.count")
443+
444+
445+
def test_step_function_counter_incremented(
446+
action_params_factory, action_context_factory
447+
):
448+
context = action_context_factory(operation=Operation.CREATE)
449+
executor = Executor(action_params_factory(steps={"new": ["create_issue"]}))
450+
with mock.patch("jbi.runner.statsd") as mocked:
451+
executor(context=context)
452+
mocked.incr.assert_called_with("jbi.steps.create_issue.count")
453+
454+
455+
def test_counter_is_incremented_for_create(
456+
webhook_factory, actions_factory, mocked_bugzilla, bug_factory
457+
):
458+
webhook_payload = webhook_factory(
459+
event__target="bug",
460+
bug__see_also=[],
461+
)
462+
mocked_bugzilla.get_bug.return_value = webhook_payload.bug
463+
with mock.patch("jbi.runner.statsd") as mocked:
464+
result = execute_action(
465+
request=webhook_factory(),
466+
actions=actions_factory(),
467+
)
468+
mocked.incr.assert_any_call("jbi.operation.create.count")
469+
470+
471+
def test_counter_is_incremented_for_update(
472+
actions_factory, webhook_factory, mocked_bugzilla, mocked_jira
473+
):
474+
webhook_payload = webhook_factory(
475+
event__target="bug",
476+
bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
477+
)
478+
mocked_bugzilla.get_bug.return_value = webhook_payload.bug
479+
mocked_jira.get_issue.return_value = {"fields": {"project": {"key": "JBI"}}}
480+
with mock.patch("jbi.runner.statsd") as mocked:
481+
result = execute_action(
482+
request=webhook_payload,
483+
actions=actions_factory(),
484+
)
485+
mocked.incr.assert_any_call("jbi.operation.update.count")
486+
487+
488+
def test_counter_is_incremented_for_comment(
489+
actions_factory, webhook_factory, mocked_bugzilla, mocked_jira
490+
):
491+
webhook_payload = webhook_factory(
492+
event__target="comment",
493+
bug__see_also=["https://mozilla.atlassian.net/browse/JBI-234"],
494+
)
495+
mocked_bugzilla.get_bug.return_value = webhook_payload.bug
496+
mocked_jira.get_issue.return_value = {"fields": {"project": {"key": "JBI"}}}
497+
with mock.patch("jbi.runner.statsd") as mocked:
498+
result = execute_action(
499+
request=webhook_payload,
500+
actions=actions_factory(),
501+
)
502+
mocked.incr.assert_any_call("jbi.operation.comment.count")

0 commit comments

Comments
 (0)