> ## Documentation Index
> Fetch the complete documentation index at: https://docs.elementary-data.com/llms.txt
> Use this file to discover all available pages before exploring further.

# event_freshness_anomalies

<Card title="Generate your anomaly test with Elementary AI" icon="wand-magic-sparkles" horizontal="true" href="https://elementary-data.com/community">
  Let our Slack chatbot create the anomaly test you need.
</Card>

`elementary.event_freshness_anomalies`

Monitors the freshness of event data over time, as the expected time it takes each event to load -
that is, the time between when the event actually occurs (the `event timestamp`), and when it is loaded to the
database (the `update timestamp`).

This test complements the `freshness_anomalies` test and is primarily intended for data that is updated in a continuous / streaming fashion.

The test can work in a couple of modes:

* If only an `event_timestamp_column` is supplied, the test measures over time the difference between the current
  timestamp ("now") and the most recent event timestamp.
* If both an `event_timestamp_column` and an `update_timestamp_column` are provided, the test will measure over time
  the difference between these two columns.

### Test configuration

*Required configuration: `event_timestamp_column`*
*Default configuration: `anomaly_direction: spike` to alert only on delays.*

<pre>
  <code>
    data\_tests:
      -- elementary.event\_freshness\_anomalies:
        arguments:
          <a href="/data-tests/anomaly-detection-configuration/event_timestamp_column"><font color="#CD7D55">event\_timestamp\_column: column name</font></a>
          <a href="/data-tests/anomaly-detection-configuration/update_timestamp_column"><font color="#CD7D55">update\_timestamp\_column: column name</font></a>
          <a href="/data-tests/anomaly-detection-configuration/where-expression"><font color="#CD7D55">where\_expression: sql expression</font></a>
          <a href="/data-tests/anomaly-detection-configuration/anomaly-sensitivity"><font color="#CD7D55">anomaly\_sensitivity: int</font></a>
          <a href="/data-tests/anomaly-detection-configuration/detection-period"><font color="#CD7D55">detection\_period:</font></a>
            <a href="/data-tests/anomaly-detection-configuration/detection-period"><font color="#CD7D55">period: \[hour | day | week | month]</font></a>
            <a href="/data-tests/anomaly-detection-configuration/detection-period"><font color="#CD7D55">count: int</font></a>
          <a href="/data-tests/anomaly-detection-configuration/training-period"><font color="#CD7D55">training\_period:</font></a>
            <a href="/data-tests/anomaly-detection-configuration/training-period"><font color="#CD7D55">period: \[hour | day | week | month]</font></a>
            <a href="/data-tests/anomaly-detection-configuration/training-period"><font color="#CD7D55">count: int</font></a>
          <a href="/data-tests/anomaly-detection-configuration/time-bucket"><font color="#CD7D55">time\_bucket:</font></a>
            <a href="/data-tests/anomaly-detection-configuration/time-bucket"><font color="#CD7D55">period: \[hour | day | week | month]</font></a>
            <a href="/data-tests/anomaly-detection-configuration/time-bucket"><font color="#CD7D55">count: int</font></a>
          <a href="/data-tests/anomaly-detection-configuration/seasonality"><font color="#CD7D55">seasonality: day\_of\_week</font></a>
          <a href="/data-tests/anomaly-detection-configuration/detection-delay"><font color="#CD7D55">detection\_delay:</font></a>
            <a href="/data-tests/anomaly-detection-configuration/detection-delay"><font color="#CD7D55">period: \[hour | day | week | month]</font></a>
            <a href="/data-tests/anomaly-detection-configuration/detection-delay"><font color="#CD7D55">count: int</font></a>
          <a href="/data-tests/anomaly-detection-configuration/ignore_small_changes"><font color="#CD7D55">ignore\_small\_changes:</font></a>
            <a href="/data-tests/anomaly-detection-configuration/ignore_small_changes"><font color="#CD7D55">spike\_failure\_percent\_threshold: int</font></a>
            <a href="/data-tests/anomaly-detection-configuration/ignore_small_changes"><font color="#CD7D55">drop\_failure\_percent\_threshold: int</font></a>
          <a href="/data-tests/anomaly-detection-configuration/anomaly-exclude-metrics"><font color="#CD7D55">anomaly\_exclude\_metrics: \[SQL expression]</font></a>
  </code>
</pre>

<RequestExample>
  ```yml Models theme={null}
  models:
    - name: < model name >
      data_tests:
        - elementary.event_freshness_anomalies:
            arguments:
              event_timestamp_column: < timestamp column > # Mandatory
              update_timestamp_column: < timestamp column > # Optional
              where_expression: < sql expression >
              time_bucket: # Daily by default
                period: < time period >
                count: < number of periods >
  ```

  ```yml Models example theme={null}
  models:
    - name: login_events
      data_tests:
        - elementary.event_freshness_anomalies:
            arguments:
              event_timestamp_column: "occurred_at"
              update_timestamp_column: "updated_at"
            config:
              # optional - use tags to run elementary tests on a dedicated run
              tags: ["elementary"]
              # optional - change severity
              severity: warn
  ```
</RequestExample>
