Hey <@ULVA73B9P> with automation, how can I config...
# ask-marvin
f
Hey @Marvin with automation, how can I configure an automation for all failed flows • that have the tag “tag_a” • exluding any flow that have “tag_b” ?
m
To set up an automation in Prefect for all failed flows with a specific tag "tag_a" while excluding any flows that have "tag_b", you can use the Prefect Automations API to customize your triggers and actions based on flow run state changes and tags. Here's a rough outline of how you might configure this: 1. Create an automation with triggers for failed flow runs: Use Prefect's capabilities to set triggers based on state changes. Documented examples describe configuring triggers for flow run state changes, which is a common use case (Automations Triggers Documentation). 2. Filter by tags: Utilize the filtering options to specify the inclusion of "tag_a" and exclusion of "tag_b". The documentation mentions the use of
match
and
match_related
fields to control which events a trigger should consider by filtering on labels (tags in your case) (Custom Triggers Documentation). 3. Specify actions: Once you have determined the triggers, define the actions you want to take when a flow run with the specified conditions fails, such as sending notifications, canceling flow runs, or any custom actions you wish to automate. You may need to write some custom logic to perfectly handle the "OR" and "AND" conditions between tags if necessary, using the Prefect Automations API or existing flow configurations. Remember, the combination of matching and filtering methods allows you to create quite specific trigger conditions to suit your needs. If you have detailed questions about implementing these steps, feel free to ask!
f
@Marvin How can I have a filter that exclude tags ?
m
Excluding tags in Prefect when setting up automations involves creating specific filter conditions using the
match
and
match_related
fields. While it's common to match specific tags, excluding them typically requires a bit more manual setup in the logic you use for automation triggers. Here’s a general approach you might consider: 1. Use the Match Filters: Prefect’s automation triggers allow you to set filters for events, including tags. The basic idea is to set a filter that includes the tags you want but add logic that filters out those you don’t. 2. Custom Logic for Exclusion: Since direct exclusion might not be as straightforward in the default settings, you can implement logic in your automation setup that explicitly checks for both conditions: include
tag_a
and ensure
tag_b
isn't present. This can be done using the Prefect Automations API where you can programmatically define more complex rules. 3. Use Conditional Logic: While Prefect doesn’t have an in-built “exclude tag” syntax directly in the UI, you can achieve this through scripting or additional logic in your automation. You’d typically retrieve the flow run metadata and check the tags associated with it, executing your automation only if the conditions are met. Unfortunately, Prefect's documentation doesn’t specify a direct exclusion mechanism by tags, but by setting up your automation with this logic, you should be able to handle the exclusions effectively. If you're working on a specific implementation and need more detailed code examples or guidance, feel free to share more details!
f
I understand @Marvin. Then how can I have a filter to include flows that have both 2 tags. like tag A + Tag B only
m
To configure a filter in Prefect to include flows that have both tags "tag_a" and "tag_b", you can use the combination of filtering options provided in the Automations API. Here's a general approach you might consider: 1. Combination of Tags in Match Filters: When setting up an automation, you'll need to use the
match
fields to check for the presence of both tags. Each label (or tag) added to a match filter is typically ANDed together, which means only flows that include all specified tags will be selected. 2. Specify Tags in Automation Triggers: - Create a trigger for flow run state changes or any other relevant event. - In your trigger configuration, specify both "tag_a" and "tag_b" as required tags in the event filters. By listing both tags, the automation will only consider events where both tags are present on the flow. 3. Utilize API for Advanced Configurations: If you are defining your automations via the Prefect API, you might need to explicitly specify that both tags should be found in flow metadata before triggering your automation action. Here’s a conceptual breakdown of what the logic would look like: - Trigger only when any flow run undergoes a state change indicating failure. - Use the
match
parameters to ensure that
tags
include ["tag_a", "tag_b"]. By ensuring both tags are required in the match condition, you effectively filter for flows containing both. If you're building this through code or need an example implementation, some YAML or Python within Prefect's systems may also be required to articulate these rules. If you have further questions or need a deeper dive into code-like scripts, don't hesitate to ask!
f
@Marvin pls give me the json for this that you wrote: `In your trigger configuration, specify both "tag_a" and "tag_b" as required tags in the event filters. By listing both tags, the automation will only consider events where both tags are present on the flow.`` I can’t figure it out with the docs
m
Creating a JSON configuration to filter flows that contain both "tag_a" and "tag_b" can be a bit tricky, especially if you're crafting automation using Prefect's Automations API. Here's a rough idea of what your JSON could look like when specifying both tags as required:
Copy code
json
{
  "trigger": {
    "type": "FlowRunStateChange",
    "conditions": [
      {
        "type": "TagsCondition",
        "tags": ["tag_a", "tag_b"],
        "operator": "ALL"  // Hypothetical to illustrate logic for matching all tags provided
      }
    ]
  },
  "actions": [
    {
      "type": "Notify",
      "parameters": {
        "message": "Flow with both tag_a and tag_b has changed state."
      }
    }
  ]
}
### Key Points: - Trigger Type:
FlowRunStateChange
is used to listen for changes in flow run status. - Tags Condition: The
"type": "TagsCondition"
and specifying
"tags": ["tag_a", "tag_b"]
intends to filter down to the flows containing both tags. - Operator: This is hypothetical as a clear
ALL
operator may not directly exist, but represents the logic you want (both tags must be present). ### Note While this template gives a sense of structure, please consult the Prefect Automations API specifications for accurate fields and supported values. Prefect’s filtering capabilities can be implemented differently based on your API version and setup capabilities. The direct features may vary, requiring adjustments in the JSON to fit the exact syntax and capability available in the API documentation. Feel free to ask more if this doesn’t quite align with your requirements! Sometimes API tweaking takes a bit of iteration.