https://prefect.io logo
Title
j

Josh Paulin

03/02/2023, 7:41 PM
Is there any documentation available on what each section of the Custom Triggers json for automations controls? For instance I’m looking to set up an automation that would fire a notification if deployments with a specific tag fail 4 times in a row, but it’s not clear to me how exactly the fields need to be set to accomplish that.
1
w

Will Raphaelson

03/02/2023, 7:45 PM
Hey Josh - the in-cloud rest spec has a bunch on that (its a superset of the spec in the general docs with additional cloud-only endpoints) https://app.prefect.cloud/api/docs#tag/Automations
j

Josh Paulin

03/02/2023, 7:49 PM
Been trying to decipher that, but it’s not clear to me what match vs match_related controls, how to specify matching on a tag, etc.
w

Will Raphaelson

03/02/2023, 7:58 PM
Ahh gotcha, i hear you. this will be a little clearer in a few weeks when you can see events in the ui and see what events for example have what resources and related resources. in any case. You’d use the related resource field here, something like
{
  "trigger": {
    "match": {
      "prefect.resource.id": "prefect.flow-run.*"
    },
    "match_related": {
      "prefect.resource.id": [
        "prefect.tag.prod"
      ],
      "prefect.resource.role": "tag"
    },
    "after": [],
    "expect": [
      "prefect.flow-run.Failed"
    ],
    "for_each": [
      "prefect.resource.id"
    ],
    "posture": "Reactive",
    "threshold": 1,
    "within": 10
  }
but you’d make the threshold 4 and the within the number of seconds within which time you want to monitor.
j

Josh Paulin

03/02/2023, 8:24 PM
Got it. Thanks for the example. In this case, if the tag were named
alert
, is it the
match_related
that would be updated to be
prefect.tag.alert
? Also I guess it’s not possible to get quite the setup I’m looking for with 4 consecutive runs? Since I’ve got deployments that take differing amounts of times and schedules, I’m thinking there could be chances for false negatives if I didn’t create different sets of automations more tailored to each deployment characteristics. To paint an extreme scenario, assume I have Flow A that runs very fast (< 1 min) and Flow B that runs very slow (> 1 hour). If I tried to create a single automation to cover both I’d end up with either A alerting too often because the
within
time is so large that it overcounts, or B misses alerts altogether because even though it’s constantly failing it’s not doing so close enough in time.
1
What would be nice would be able to just look at the last
n
runs, no matter how close or far apart they were
w

Will Raphaelson

03/02/2023, 9:07 PM
Yes exactly the tag would change to alert. And yeah the consecutive aspect would be tricky with the current API unfortunately, its not really supported in a first class way but we could look into it in the mid term. For that setup I’d probably create two different automations, and you could either give them different tags, or specify them by flow name. This actually motivates me to file another issue for consideration which is a “compound” match related interface that supports an array, as right now if you wanted an automation to only fire if a run of a specific flow run with specific tags enters a state, it wouldn’t really be possible. I’ll get that on our radar.
🙏 1
👍 1
j

Josh Paulin

03/06/2023, 5:59 PM
Is there anything malformed about the following trigger configuration? (it’s 99% copied from what you posted) When I try and set it there’s no way to set a notification configuration in the UI. Seems fine if I use the default settings that come up when I select a custom trigger though 😕
{
  "trigger": {
    "match": {
      "prefect.resource.id": "prefect.flow-run.*"
    },
    "match_related": {
      "prefect.resource.id": [
        "prefect.tag.alert"
      ],
      "prefect.resource.role": "tag"
    },
    "after": [],
    "expect": [
      "prefect.flow-run.Failed"
    ],
    "for_each": [
      "prefect.resource.id"
    ],
    "posture": "Reactive",
    "threshold": 4,
    "within": 10800
  }
}
w

Will Raphaelson

03/06/2023, 6:13 PM
Thanks josh - here is the tracking issue for the back end side. This looks like a straight up ui bug. Let me get this knocked out, filed ui issue here.
j

Josh Paulin

03/06/2023, 6:13 PM
Thanks!
w

Will Raphaelson

03/06/2023, 6:13 PM
Thank you