<@ULVA73B9P> we're working on setting up an automa...
# ask-marvin
y
@Marvin we're working on setting up an automation that has a customer event trigger. I want to trigger that automation based on the flow run logs. If the log error partial matches with a string "The object is not found", the automation needs to be triggered. I tried many ways with the following match_related value, but it's not working. Is it possible to trigger the automation based on the flow run log error?
Copy code
match_related = {
            "prefect.resource.role": "log", #, 
            "prefect.log.error": [ "*The object is not found*"]
        },
m
To trigger automation based on a flow run log error in Prefect 3.x, you can use the
match
and
match_related
fields to filter events. Here are some key points: 1. Filter Configuration: The
match_related
field allows you to filter events based on related resources. Each label in a filter is combined with others using an AND operation, and lists of values are OR'ed together. 2. Custom Triggers: You can define custom triggers that respond to specific log messages. However, your current configuration seems to be incorrect or insufficient for your needs. 3. Log Filtering: Prefect's documentation suggests that you can filter events using fields like
prefect.resource.role
and
prefect.log.error
, but the exact implementation details for log-based triggers are not explicitly documented. You might need to ensure that the log events you want to trigger on are being emitted correctly and are accessible in the context where the automation is evaluated. For more detailed guidance, you might want to review these sections in the Prefect documentation: - Custom Triggers - Automations and Triggers Given that your current configuration isn't working, you may need to verify the structure and content of the emitted logs to ensure they match the filter criteria. If the issue persists, consider reaching out to the Prefect community or support for more tailored assistance.
y
@Marvin Can I use "log" as the prefect.resource.role in the match_related conditions?
m
The search did not yield specific information on using "log" as a
prefect.resource.role
in the
match_related
conditions. The documentation primarily focuses on role-based access controls (RBAC) for user permissions in Prefect Cloud, which is not directly related to event triggers or logs. To determine if "log" can be used as a
prefect.resource.role
, you might need to experiment within your Prefect environment or consult with the Prefect community or support. The existing documentation does not explicitly cover this use case in detail.
k
logs don't come through the event feed as such, but you can emit custom events for anything that happens in your code
Copy code
from prefect import flow, emit_event

@flow
def my_erroring_function():
    try:
        ... # thing that could fail
    except SomeError as e:
       emit_event(event="Object Not Found", resource={"prefect.resource.id": "prefect.log.notfounderror"}
Then your automation trigger could just
Copy code
"match": {
    "prefect.resource.id": [
      "prefect.log.notfounderror"
    ]
},
y
Hey @Kevin Grismore can this also be applied to the crashed job due to out of memory issue? We have some crashed flows which is because the pod memory size is not big enough. But there's also other type of crashed flows. I'm planning to trigger the automation only to the crashed flows due to memory issues. I noticed the flow run log is saying something like
"Job reached backoff limit."
. Can I use the same approach?
k
that log is coming from the worker. an event can't be emitted from the flow run container if it shut off due to OOM
y
If that's the case, are there any way we can trigger the automation only when the crashed flow is due to out of memory issue? We have other types of crashed flows which we don't wanna trigger the automation.
here's what our OOM crashed flow log looks like. I was thinking to use
Job reached backoff limit
as an indicator for this