Skip to content

Commit 530b7b0

Browse files
authored
fix(sentry): count triggers deployed through deploy_task (#1436)
Signed-off-by: Kevin Su <pingsutw@apache.org>
1 parent 299045e commit 530b7b0

2 files changed

Lines changed: 67 additions & 1 deletion

File tree

src/flyte/_deploy.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from ._image import Image
2121
from ._initialize import ensure_client, get_client, get_init_config, requires_initialization
2222
from ._logging import logger
23-
from ._sentry import track_operation
23+
from ._sentry import count, track_operation
2424
from ._status import status
2525
from ._task import TaskTemplate
2626
from ._task_environment import TaskEnvironment
@@ -296,6 +296,12 @@ async def _deploy_task(
296296
)
297297
)
298298
status.success(f"Deployed task {task.name} (version {task_id.version})")
299+
if deployable_triggers:
300+
count(
301+
"flyte.operation",
302+
len(deployable_triggers),
303+
tags={"operation": "deploy_trigger", "status": "success"},
304+
)
299305
except ConnectError as e:
300306
if e.code == Code.ALREADY_EXISTS:
301307
status.info(f"Task {task.name} already exists, skipping")

tests/flyte/test_deploy.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,63 @@ def __init__(self):
605605
deployment = await apply(plan, copy_style="loaded_modules", dryrun=True)
606606

607607
assert "e" in deployment.envs
608+
609+
610+
@pytest.mark.asyncio
611+
async def test_deploy_task_counts_deployed_triggers(monkeypatch):
612+
"""Triggers ship inside DeployTaskRequest, so deploy_task is the only place they can be counted."""
613+
from flyteidl2.task import task_definition_pb2
614+
615+
root_dir = pathlib.Path(__file__).parents[2].resolve()
616+
monkeypatch.setattr(sys, "path", [str(root_dir / "src"), *sys.path])
617+
618+
env = flyte.TaskEnvironment(name="test_env", image="python:3.10")
619+
620+
@env.task()
621+
async def task() -> None:
622+
pass
623+
624+
task = replace(task, triggers=(Mock(), Mock()))
625+
context = SerializationContext(version="v1", root_dir=root_dir)
626+
config = Mock(sync_local_sys_paths=False)
627+
628+
with (
629+
patch("flyte._deploy.ensure_client"),
630+
patch("flyte._deploy.get_init_config", return_value=config),
631+
patch("flyte._deploy.get_client", return_value=Mock(task_service=Mock(deploy_task=AsyncMock()))),
632+
patch("flyte._internal.runtime.convert.convert_upload_default_inputs", AsyncMock(return_value=[])),
633+
patch(
634+
"flyte._internal.runtime.trigger_serde.to_task_trigger",
635+
AsyncMock(return_value=task_definition_pb2.TaskTrigger(name="t")),
636+
),
637+
patch("flyte._deploy.count") as count_mock,
638+
):
639+
await _deploy_task(task, context, dryrun=False)
640+
641+
count_mock.assert_called_once_with("flyte.operation", 2, tags={"operation": "deploy_trigger", "status": "success"})
642+
643+
644+
@pytest.mark.asyncio
645+
async def test_deploy_task_without_triggers_emits_no_trigger_count(monkeypatch):
646+
root_dir = pathlib.Path(__file__).parents[2].resolve()
647+
monkeypatch.setattr(sys, "path", [str(root_dir / "src"), *sys.path])
648+
649+
env = flyte.TaskEnvironment(name="test_env", image="python:3.10")
650+
651+
@env.task()
652+
async def task() -> None:
653+
pass
654+
655+
context = SerializationContext(version="v1", root_dir=root_dir)
656+
config = Mock(sync_local_sys_paths=False)
657+
658+
with (
659+
patch("flyte._deploy.ensure_client"),
660+
patch("flyte._deploy.get_init_config", return_value=config),
661+
patch("flyte._deploy.get_client", return_value=Mock(task_service=Mock(deploy_task=AsyncMock()))),
662+
patch("flyte._internal.runtime.convert.convert_upload_default_inputs", AsyncMock(return_value=[])),
663+
patch("flyte._deploy.count") as count_mock,
664+
):
665+
await _deploy_task(task, context, dryrun=False)
666+
667+
count_mock.assert_not_called()

0 commit comments

Comments
 (0)