Skip to content

Commit f8b4e22

Browse files
Fix validation for threshold metrics (#41)
* Fix validation for threshold metrics * Fix failing test * Update package version
1 parent fb38625 commit f8b4e22

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ Each advanced aggregation type requires its specific parameter and cannot use ot
9292
- `aggregation_type`: "sum" or "count" (**not** count_distinct)
9393
- `breach_value`: numeric threshold value
9494
- **Cannot use**: `retention_threshold_days`, `conversion_threshold_days`
95+
- **Cannot use**: Timeframe parameters (`aggregation_timeframe_start_value`, `aggregation_timeframe_end_value`, `aggregation_timeframe_unit`)
9596

9697
#### Retention Metrics
9798
- **Required**: `retention_threshold_days` (numeric)

eppo_metrics_sync/validation.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,13 @@ def aggregation_is_valid(aggregation):
217217
matched[0] + ' specified, but operation is ' + aggregation['operation']
218218
)
219219

220-
# if threshold:
220+
# threshold operations cannot use timeframe parameters
221221
if aggregation['operation'] == 'threshold':
222-
# TODO
223-
pass
222+
matched = [p for p in timeframe_parameters if p in aggregation]
223+
if matched:
224+
error_message.append(
225+
f"Cannot specify {', '.join(matched)} for operation threshold"
226+
)
224227

225228
distinct_advanced_aggregation_parameter_set(
226229
aggregation,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "eppo_metrics_sync"
7-
version = "0.1.12"
7+
version = "0.1.13"
88
description = "Sync metrics to Eppo"
99
readme = "README.md"
1010
requires-python = ">=3.7"

tests/test_validation.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,38 @@ def test_extra_parameter_on_retention_metric():
133133
assert res == 'Invalid parameter for retention aggregation: conversion_threshold_days'
134134

135135

136+
def test_threshold_with_timeframe_parameters():
137+
test_agg = {
138+
'operation': 'threshold',
139+
'aggregation_timeframe_end_value': 7,
140+
'aggregation_timeframe_unit': 'days',
141+
'threshold_metric_settings': {
142+
'comparison_operator': 'gt',
143+
'aggregation_type': 'sum',
144+
'breach_value': 100
145+
}
146+
}
147+
148+
res = aggregation_is_valid(test_agg)
149+
assert res == 'Cannot specify aggregation_timeframe_end_value, aggregation_timeframe_unit for operation threshold'
150+
151+
152+
def test_threshold_with_single_timeframe_parameter():
153+
test_agg = {
154+
'operation': 'threshold',
155+
'aggregation_timeframe_start_value': 1,
156+
'aggregation_timeframe_unit': 'days', # Add unit to avoid the unit validation error
157+
'threshold_metric_settings': {
158+
'comparison_operator': 'gte',
159+
'aggregation_type': 'count',
160+
'breach_value': 5
161+
}
162+
}
163+
164+
res = aggregation_is_valid(test_agg)
165+
assert res == 'Cannot specify aggregation_timeframe_start_value, aggregation_timeframe_unit for operation threshold'
166+
167+
136168
def test_count_distinct():
137169
test_agg = {
138170
'operation': 'count_distinct',

0 commit comments

Comments
 (0)