Raffael Campos
11/04/2024, 1:45 PMpython
flow_emit_metrics.serve(
name="emit-metrics",
triggers=[ DeploymentEventTrigger(
name="emit-metrics-on-event",
threshold=1,
posture=Posture.Reactive,
description="Emit metrics on event",
enabled=True,
within=1,
expect=[insert_metrics_event_name],
parameters={
"metrics_config": "{{event.payload.metrics_config}} | tojson",
"labels": "{{event.payload.labels}} | tojson",
}
) ],
)
but then I get this error:
Action failed: 'Validation error occurred for \'run-deployment\' - Error creating flow run: Validation failed for field \'metrics_config\'. Failure reason: "{\'number_of_rows\': [10, \'Number of rows inserted\', \'counter\']}" is not of type \'object\''
the signature of the flow is
def flow_emit_metrics(metrics_config: dict, labels: dict):
I imagine jinja is converting the objects to strings, but I want to keep them as objects. Can I do that?Marvin
11/04/2024, 1:45 PM{{ event.payload.metrics_config }} | tojson
in your template, ensure that when using it in your Python logic, you parse it back into an object using the json.loads
method from Python's standard library. Here's an example:
python
import json
def flow_emit_metrics(metrics_config: dict, labels: dict):
metrics_config = json.loads(metrics_config)
labels = json.loads(labels)
# Your flow logic here
This adjustment should help keep your payload fields as objects rather than plain strings. If humor could debug your code, it might say something like, "I think you ought to know I'm feeling very parsed now."
For further details, you might want to look at Prefect's webhook guides or track activity through events. The unsuccessful GitHub query indicated no existing issues closely matching your precise problem, which suggests your approach might be slightly unique or less documented.
Let me know if you need more help!Nate
11/04/2024, 1:56 PMNate
11/04/2024, 1:57 PMtrigger = DeploymentEventTrigger( # type: ignore
expect={"prefecthq/prefect*"},
parameters={
"event": {
"__prefect_kind": "json",
"value": {
"__prefect_kind": "jinja",
"template": "{{ event.payload | tojson }}",
},
}
},
)