# AlertPolicy

> AlertPolicy says when a tenant hears about its flows, and where.

Source: https://docs.go-lumen.ai/he/reference/resources/alertpolicy

## At a glance

| מאפיין | ערך |
| --- | --- |
| **apiVersion** | `lumen.ai/v1alpha1` |
| **kind** | `AlertPolicy` |
| **Resource name** | `alertpolicies` |
| **Scope** | Namespaced (lives in a workspace's namespace) |

## Spec

Fields under `spec:`. Nested fields are indented under their parent.

| Field | סוג | ברירת מחדל | תיאור |
| --- | --- | --- | --- |
| `flows` | object |  | Flows selects by label; empty selects every flow in the namespace. |
| `flows.matchExpressions` | list of object |  | matchExpressions is a list of label selector requirements. The requirements are ANDed. |
| `flows.matchExpressions[].key` (חובה) | string |  | key is the label key that the selector applies to. |
| `flows.matchExpressions[].operator` (חובה) | string |  | operator represents a key's relationship to a set of values. Valid operators are In, NotIn, Exists and DoesNotExist. |
| `flows.matchExpressions[].values` | list of string |  | values is an array of string values. If the operator is In or NotIn, the values array must be non-empty. If the operator is Exists or DoesNotExist, the values array must be empty. This array is replaced during a strategic merge patch. |
| `flows.matchLabels` | map of string |  | matchLabels is a map of `{key,value}` pairs. A single `{key,value}` in the matchLabels map is equivalent to an element of matchExpressions, whose key field is "key", the operator is "In", and the values array contains only "value". The requirements are ANDed. |
| `notify` (חובה) | list of object |  | (minItems 1) |
| `notify[].connectorRef` | object |  | LocalObjectReference names an object in the same namespace. |
| `notify[].connectorRef.name` (חובה) | string |  | (minLength 1) |
| `notify[].email` | string |  |  |
| `when` (חובה) | object |  | AlertCondition is a discriminated union on type. **Rule:** costOver is set exactly when type is CostOver **Rule:** anomaly is set exactly when type is Anomaly |
| `when.anomaly` | object |  |  |
| `when.anomaly.sensitivity` | string | `"medium"` | Sensitivity is the z-score threshold. (one of low, medium, high) |
| `when.costOver` | object |  |  |
| `when.costOver.amountUSD` (חובה) | string |  | USD is a non-negative decimal amount in US dollars, as a string because floats do not round-trip through the Kubernetes API. (pattern \`^\[0-9\]+(\\.\[0-9\]{1,6})?$\`) |
| `when.costOver.window` (חובה) | string |  | Window is a Prometheus duration, e.g. 1h, 1d. (pattern \`^\[0-9\]+(m|h|d)$\`) |
| `when.type` (חובה) | string |  | (one of RunFailed, CostOver, Anomaly) |

## Status

Written by Lumen; do not set it. Only the phase and the conditions are described here.

| Field | סוג | ברירת מחדל | תיאור |
| --- | --- | --- | --- |
| `conditions` | list of object |  |  |
| `conditions[].lastTransitionTime` (חובה) | string |  | lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable. |
| `conditions[].message` (חובה) | string |  | message is a human readable message indicating details about the transition. This may be an empty string. (maxLength 32768) |
| `conditions[].observedGeneration` | integer |  | observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions\[x\].observedGeneration is 9, the condition is out of date with respect to the current state of the instance. (minimum 0) |
| `conditions[].reason` (חובה) | string |  | reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty. (minLength 1; maxLength 1024; pattern \`^\[A-Za-z\](\[A-Za-z0-9\_,:\]\*\[A-Za-z0-9\_\])?$\`) |
| `conditions[].status` (חובה) | string |  | status of the condition, one of True, False, Unknown. (one of True, False, Unknown) |
| `conditions[].type` (חובה) | string |  | type of condition in CamelCase or in foo.example.com/CamelCase. (maxLength 316; pattern \`^(\[a-z0-9\](\[-a-z0-9\]\*\[a-z0-9\])?(\\.\[a-z0-9\](\[-a-z0-9\]\*\[a-z0-9\])?)\*/)?((\[A-Za-z0-9\]\[-A-Za-z0-9\_.\]\*)?\[A-Za-z0-9\])$\`) |

## kubectl columns

| Column | Type | JSONPath |
| --- | --- | --- |
| When | string | `.spec.when.type` |
| Ready | string | `.status.conditions[?(@.type=="Ready")].status` |
| Age | date | `.metadata.creationTimestamp` |

## Example

```yaml title="alertpolicy.yaml"
apiVersion: lumen.ai/v1alpha1
kind: AlertPolicy
metadata:
  name: invoice-failures
  namespace: tenant-acme
spec:
  flows:
    matchLabels: {lumen.ai/owner: git}
  when:
    type: RunFailed
  notify:
    - email: ops@acme.example
```
