Skip to content

Commit 0995e5d

Browse files
authored
[DENG-9557] Add period-over-period docs for metric-hub (#870)
1 parent 3d1497c commit 0995e5d

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

.spelling

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
200-tab
88
24-hour
99
28-day
10+
365-day
1011
2FA
1112
89.0a1
1213
Acryl
@@ -166,6 +167,7 @@ GKE
166167
Glean.js
167168
GoFaster
168169
Grafana
170+
granularities
169171
GUD
170172
gzip
171173
gzipped

src/concepts/metric_hub.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,34 @@ Wildcard expressions can be used to express that a specific statistic should be
189189

190190
New statistics need to be implemented inside the tooling that uses metric definitions.
191191

192+
##### Period-over-Period Statistics (Looker only)
193+
194+
Statistic definitions can be extended with `period_over_period` configurations:
195+
196+
```toml
197+
[metrics.any_content_engagement_clients.statistics.rolling_average]
198+
aggregations = ["ratio", "sum"]
199+
window_sizes = [28]
200+
period_over_period = { periods = [365], kinds = ["previous", "relative_change"] }
201+
```
202+
203+
This is only available in Looker.
204+
205+
This configuration:
206+
207+
- Computes a 28-day rolling average for both ratio and sum.
208+
- Creates period-over-period comparisons over a 365-day window, producing measures for:
209+
- Previous values
210+
- Relative changes
211+
212+
Supported types (`kinds`) of period-over-period comparisons are:
213+
214+
- Previous: Returns the historical value from the prior period.
215+
- Difference: Subtracts the previous period from the current.
216+
- Relative Change: Shows percentage change between periods.
217+
218+
These measures work with different time period granularities (day, week, quarter, ...), with automatic smart period adjustments (e.g., 30 days ≈ 4 weeks ≈ 1 month).
219+
192220
### `[dimensions]` Section
193221

194222
Dimensions define a field or dimension on which the client population should be segmented. Dimensions are used in OpMon. For segmenting client populations clients see the `[segments]` section.
@@ -340,6 +368,9 @@ The side pane is split into different sections:
340368
- **Statistics**: This sections contains the [statistics that have been defined in metric-hub on top of the metric definitions](https://github.com/mozilla/metric-hub/tree/main/looker) as measures. These statistics summarize the distribution of metrics within a specific time frame, population and/or segment and are used to derive insights and patterns from the raw metric data. Statistics have to be defined manually under the [`looker/` directory in metric-hub](https://github.com/mozilla/metric-hub/tree/main/looker).
341369
- **Sample of source data**: Defines the sample size that should be selected from the data source. Decreasing the sample size will speed up getting results in Looker, however it might decrease the accuracy. The results are being adjusted based on the sample size. For example, if a 1% sample is being used, then certain statistic results (like sum, count) will be multiplied by 100.
342370
- **Aggregate Client Metrics Per ...**: This parameter controls the time window over which metrics are aggregated per client. For example, this allows to get a weekly average of a metric, a maximum of a metric over the entire time period. By default, aggregations are on a daily basis.
371+
- **Lookback (Days)**: Adds a configurable buffer of days before the selected analysis period (useful for period-over-period calculations).
372+
- **Analysis Period (with Lookback)**: Defines the primary analysis window for all comparisons.
373+
- **Date Group By Position**: Helps resolve grouping when using week/month/quarter/year granularity in BigQuery.
343374

344375
#### Getting Metrics into Looker
345376

@@ -355,6 +386,7 @@ Statistics on top of these metrics need to be defined in the [`looker/` folder i
355386
- `client_count`: distinct count of clients where the metric value is >0
356387
- `ratio`: ratio between two metrics. When configuring the statistic metric slugs need to be provided for the `numerator` and `denominator` parameters
357388
- `dau_proportion`: Ratio between the metric and active user counts
389+
- `rolling_average`: Configurable rolling average of a statistic
358390

359391
To get more statistics added, please reach out on the [#data-help](https://mozilla.slack.com/archives/C4D5ZA91B) Slack channel.
360392

@@ -429,3 +461,12 @@ Definitions for metrics can be encoded at different levels. It is preferable to
429461
Ideally, metrics should be defined in the `[metrics]` section. However in some cases metrics might rely on more complex logic. For example, if some more complicated unnesting of fields or `JOIN`s across multiple tables are required it might make sense to move the metric computation into the `[data_sources]` definition and then simply reference the field in the `[metrics]` section. The main drawback of this is that if users want to find the definition they will have to go one layer deeper and check how the data source is defined versus just having to look at the metric definition itself.
430462

431463
For computationally expensive metrics it can make sense to set up an ETL job that computes the metrics on a daily basis and writes results to a separate table. This table can serve as basis of a data source which can then be used to define a metric.
464+
465+
### How are period-over-period comparisons computed?
466+
467+
Metric Hub automatically generates LookML for period-over-period measures. It uses:
468+
469+
- LAG functions for standard statistics (e.g., sum, ratio).
470+
- Adjusted rolling windows for rolling averages (window size adapts to chosen time granularity).
471+
472+
If no appropriate `submission` field is selected, Looker will raise an error prompting you to choose one.

0 commit comments

Comments
 (0)