Metrics

Using dbt Metrics with PipeRider

From dbt 1.6, support for the dbt_metrics package was deprecated and replaced by the Semantic Layer. Likewise, from version 0.33.0 of PipeRider, support for the legacy metric config has also been discontinued. Metrics defined using the old configuration will now be automatically skipped by PipeRider.

PipeRider supports querying dbt metrics and analyzing the impact on metrics between two branches.

How to use

  1. Define semantic models and metrics in your dbt project

  2. Validate metric configuration

  3. Run PipeRider

1. Define semantic models and metrics

For full details on how to define metrics, please refer to the official dbt documentation on the semantic model and creating metrics.

The following serves as a basic example on how to define a metric. Here, we define a metric revenue, which is the sum of the amount column with a status of completed.

models/marts/orders.yml
semantic_models:
  - name: orders
    defaults:
      agg_time_dimension: order_date
    model: ref('orders')
    entities:
      - name: order_id
        type: primary
      - name: customer
        type: foreign
        expr: customer_id
    dimensions:
      - name: order_date
        expr: order_date
        type: time
        type_params:
          time_granularity: day
      - name: status
        type: categorical
    measures:
      - name: revenue
        description: "The total revenue of our jaffle business"
        agg: sum
        expr: amount

metrics:
  - name: revenue
    description: "The total revenue of our jaffle business"
    type: simple
    label: Revenue
    type_params:
      measure: revenue
    filter: |
      {{ Dimension('order_id__status') }} = 'completed'

2. Validate metric configuration

The fastest way to validate the configuration of your dbt project is the dbt-parse command:

$ dbt-parse

dbt has also released a powerful tool, MetricFlow CLI that, among other features, can also validate your metric configuration:

$ mf validate-configs

MetricFlow CLI can also query the metric to ensure it is functional:

$ mf query --metrics revenue --group-by metric_time__month
✔ Success 🦄 - query completed after 0.12 seconds
| metric_time__month   |   revenue |
|:---------------------|----------:|
| 2023-05-01           |     69.00 |
| 2023-06-01           |    420.00 |
| 2023-07-01           |    478.00 |
| 2023-08-01           |    136.00 |

3. Run PipeRider

Once your metrics are correctly configured, run PipeRider:

$ piperider run

View metrics in your PipeRider Report by selecting the metrics page form the project sidebar:

More about metric queries

How PipeRider queries the dbt metric

PipeRider can run daily, monthly, and yearly queries for your metrics. If the time_granularity is defined, the queries will adhere to these settings. For example, if the time_granularity is month, then PipeRider only run the monthly and yearly queries.

For each time grains, PipeRider only queries the last n periods

time_grainmetric query

day

daily result for last 30 days

month

monthly result for last 12 months

year

yearly result for last 10 years

The behavior is identical to the following command in MetricFlow.

$ mf query --metrics revenue --group-by metric_time__day --start-time <30d ago>
$ mf query --metrics revenue --group-by metric_time__month --start-time <12m ago>
$ mf query --metrics revenue --group-by metric_time__year --start-time <10y ago>

Limited Support of DBT Metrics

  • PipeRider no longer supports metric specification prior to dbt v1.6. dbt provides official documentation on how to migrate metrics configs to the new spec.

  • PipeRider doesn't support metrics that use measures with agg , such as sum_boolean, median, and percentile

  • PipeRider doesn't support metrics that use filters with jinja macros other than Dimension

  • PipeRider doesn't support metrics that use filters with Dimension macros that require joins. Referencing the above metrics example:

    • {{ Dimension('order_id__status') }} = 'completed' is supported because order_id is type of primary

    • {{ Dimension('customer__type') }} = 'vip' is not supported because customer is type of foreign, and so requires additional join

  • PipeRider doesn't support derived metrics with offset_window

  • PipeRider doesn't support cumulative metrics.

Query single metric

When developing a new metric, it is time-consuming to run through all the piperider run to test the metric result. PipeRider support dbt node selection to run on single metric

$ piperider run -s 'metric:jaffle_shop.revenue'

Compare metrics

With PipeRider's compare feature, you're also able to compare metrics between reports, which is particularly useful when analyzing the impact of data model or metric definition changes.

Last updated