-
Notifications
You must be signed in to change notification settings - Fork 125
Camunda Pyzeebe Instrumentation #1385
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
khpeet
wants to merge
9
commits into
newrelic:main
Choose a base branch
from
khpeet:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7badc05
add initial pyzeebe instrumentation/tests
khpeet 648c124
second attempt at tests (failing)
khpeet 1514bf6
updated tests - 1/2 passing locally
khpeet 4cb9825
combine function_trace client tests
khpeet 8fb4542
fix: py agent team feedback #1
khpeet d92aa07
fix: pyzeebe tests
khpeet 09a331f
chore: ruff formatting
khpeet cfe9eff
fix: review updates #2
khpeet 90af70e
fix: next round of updates
khpeet File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
from types import SimpleNamespace | ||
from pyzeebe.grpc_internals.zeebe_adapter import ZeebeAdapter | ||
|
||
# Dummy response objects with only required fields | ||
DummyCreateProcessInstanceResponse = SimpleNamespace( | ||
process_instance_key=12345 | ||
) | ||
|
||
DummyCreateProcessInstanceWithResultResponse = SimpleNamespace( | ||
process_instance_key=45678, | ||
variables={"result": "success"} | ||
) | ||
|
||
DummyDeployResourceResponse = SimpleNamespace( | ||
key=67890, | ||
deployments=[], | ||
tenant_id=None | ||
) | ||
|
||
DummyPublishMessageResponse = SimpleNamespace( | ||
key=99999, | ||
tenant_id=None | ||
) | ||
|
||
# Dummy RPC stub coroutines | ||
async def dummy_create_process_instance(self, bpmn_process_id: str, variables: dict = None, version: int = -1, tenant_id: str = None): | ||
"""Simulate ZeebeAdapter.create_process_instance""" | ||
return DummyCreateProcessInstanceResponse | ||
|
||
async def dummy_create_process_instance_with_result(self, bpmn_process_id: str, variables: dict = None, version: int = -1, timeout: int = 0, variables_to_fetch=None, tenant_id: str = None): | ||
"""Simulate ZeebeAdapter.create_process_instance_with_result""" | ||
return DummyCreateProcessInstanceWithResultResponse | ||
|
||
async def dummy_deploy_resource(*resource_file_path: str, tenant_id: str = None): | ||
"""Simulate ZeebeAdapter.deploy_resource""" | ||
# Create dummy deployment metadata for each provided resource path | ||
deployments = [] | ||
for path in resource_file_path: | ||
deployments.append(SimpleNamespace( | ||
resource_name=str(path), | ||
bpmn_process_id="dummy_process", | ||
process_definition_key=123, | ||
version=1, | ||
tenant_id=tenant_id if tenant_id is not None else None | ||
)) | ||
# Create a dummy response with a list of deployments | ||
return SimpleNamespace( | ||
deployment_key=333333, | ||
deployments=deployments, | ||
tenant_id=tenant_id if tenant_id is not None else None | ||
) | ||
|
||
async def dummy_publish_message(self, name: str, correlation_key: str, variables: dict = None, time_to_live_in_milliseconds: int = 60000, message_id: str = None, tenant_id: str = None): | ||
"""Simulate ZeebeAdapter.publish_message""" | ||
# Return the dummy response (contains message key) | ||
return SimpleNamespace( | ||
key=999999, | ||
tenant_id=tenant_id if tenant_id is not None else None | ||
) | ||
|
||
async def dummy_complete_job(self, job_key: int, variables: dict): | ||
"""Simulate JobExecutor.complete_job""" | ||
setattr(self, "_last_complete", {"job_key": job_key, "variables": variables}) | ||
return None | ||
|
||
class DummyZeebeAdapter(ZeebeAdapter): | ||
"""Simulate a ZeebeAdapter so JobExecutor can be instatiated w/o gRPC channel""" | ||
def __init__(self): | ||
self.completed_job_key = None | ||
self.completed_job_vars = None | ||
async def complete_job(self, job_key: int, variables: dict): | ||
self.completed_job_key = job_key | ||
self.completed_job_vars = variables | ||
return None | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<definitions | ||
xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" | ||
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" | ||
xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" | ||
targetNamespace="http://example.com/bpmn" | ||
xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> | ||
|
||
<!-- Define the process with a unique id and name --> | ||
<process id="dummyProcess" name="Dummy Process" isExecutable="true"> | ||
<!-- Start Event --> | ||
<startEvent id="StartEvent_1" name="Start"/> | ||
|
||
<!-- A simple Service Task representing work --> | ||
<serviceTask id="ServiceTask_1" name="Perform Work"/> | ||
|
||
<!-- End Event --> | ||
<endEvent id="EndEvent_1" name="End"/> | ||
|
||
<!-- Sequence Flows connecting Start → Service Task → End --> | ||
<sequenceFlow id="Flow_1" sourceRef="StartEvent_1" targetRef="ServiceTask_1"/> | ||
<sequenceFlow id="Flow_2" sourceRef="ServiceTask_1" targetRef="EndEvent_1"/> | ||
</process> | ||
|
||
<!-- (Optional) BPMNDiagram section can be added for graphical layout, but omitted here --> | ||
</definitions> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import asyncio | ||
import pytest | ||
|
||
from pyzeebe import Job, ZeebeTaskRouter, JobStatus | ||
from pyzeebe.worker.job_executor import JobExecutor, JobController | ||
from pyzeebe.worker.task_state import TaskState | ||
from _mocks import DummyZeebeAdapter | ||
|
||
# from testing_support.validators.validate_transaction_metrics import validate_transaction_metrics | ||
from testing_support.validators.validate_custom_parameters import validate_custom_parameters | ||
|
||
# Set up a router with a dummy async task | ||
router = ZeebeTaskRouter() | ||
|
||
@router.task(task_type="testTask") | ||
async def dummy_task(x: int) -> dict: | ||
""" | ||
Simulate a task function that reads input variable 'x' | ||
and adds 1. | ||
""" | ||
return {"result": x } | ||
|
||
# @validate_transaction_metrics( | ||
khpeet marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# "ZeebeTask/test_process/testTask", | ||
# rollup_metrics=[ | ||
# ("ZeebeTask/test_process/testTask", 1) | ||
# ], | ||
# background_task=True | ||
# ) | ||
@validate_custom_parameters(required_params=[ | ||
("zeebe.job.key", 123), | ||
("zeebe.job.type", "testTask"), | ||
("zeebe.job.bpmnProcessId", "test_process"), | ||
("zeebe.job.processInstanceKey", 456), | ||
("zeebe.job.elementId", "service_task_123") | ||
]) | ||
def test_execute_one_job(): | ||
dummy_adapter = DummyZeebeAdapter() | ||
|
||
# Build a Job with fixed values | ||
job = Job( | ||
key=123, | ||
type="testTask", # must match router.task(task_type="testTask") | ||
bpmn_process_id="test_process", | ||
process_instance_key=456, | ||
process_definition_version=1, | ||
process_definition_key=789, | ||
element_id="service_task_123", | ||
element_instance_key=321, | ||
custom_headers={}, | ||
worker="test_worker", | ||
retries=3, | ||
deadline=0, | ||
variables={"x": 33}, | ||
status=JobStatus.Running | ||
) | ||
|
||
# JobExecutor constructor params init | ||
task_obj = router.get_task("testTask") | ||
assert task_obj is not None | ||
jobs_queue = asyncio.Queue() | ||
task_state = TaskState() | ||
|
||
job_executor = JobExecutor(task_obj, jobs_queue, task_state, dummy_adapter) | ||
|
||
# Build a JobController for completion logic. | ||
job_controller = JobController(job, dummy_adapter) | ||
|
||
asyncio.run(job_executor.execute_one_job(job, job_controller)) | ||
assert job.variables["x"] == 33 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.