File tree Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Expand file tree Collapse file tree 4 files changed +58
-1
lines changed Original file line number Diff line number Diff line change 6
6
from eppo_metrics_sync .validation import (
7
7
unique_names ,
8
8
valid_fact_references ,
9
- metric_aggregation_is_valid
9
+ metric_aggregation_is_valid ,
10
+ valid_guardrail_cutoff_signs
10
11
)
11
12
12
13
from eppo_metrics_sync .dbt_model_parser import DbtModelParser
@@ -110,6 +111,7 @@ def validate(self):
110
111
unique_names (self )
111
112
valid_fact_references (self )
112
113
metric_aggregation_is_valid (self )
114
+ valid_guardrail_cutoff_signs (self )
113
115
114
116
if self .validation_errors :
115
117
error_count = len (self .validation_errors )
Original file line number Diff line number Diff line change @@ -87,6 +87,33 @@ def metric_aggregation_is_valid(payload):
87
87
)
88
88
89
89
90
+ def valid_guardrail_cutoff_signs (payload ):
91
+ facts = dict ()
92
+ for fact_source in payload .fact_sources :
93
+ for fact in fact_source ['facts' ]:
94
+ facts [fact ['name' ]] = fact
95
+
96
+ for m in payload .metrics :
97
+ numerator_fact_name = m ['numerator' ]['fact_name' ]
98
+ if is_guardrail_cutoff_exist (m ) and numerator_fact_name in facts and 'desired_change' in facts [numerator_fact_name ]:
99
+ error = is_valid_guardrail_cutoff_sign (m , facts [numerator_fact_name ])
100
+ if error :
101
+ payload .validation_errors .append (
102
+ f"{ m ['name' ]} is having invalid guardrail_cutoff sign: { error } "
103
+ )
104
+
105
+
106
+ def is_valid_guardrail_cutoff_sign (metric , numerator_fact ):
107
+ if numerator_fact ['desired_change' ] == 'decrease' and metric ['guardrail_cutoff' ] < 0 :
108
+ return f"guardrail_cutoff value should be positive"
109
+ elif numerator_fact ['desired_change' ] == 'increase' and metric ['guardrail_cutoff' ] > 0 :
110
+ return f"guardrail_cutoff value should be negative"
111
+
112
+
113
+ def is_guardrail_cutoff_exist (metric ):
114
+ return 'is_guardrail' in metric and metric ['is_guardrail' ] and 'guardrail_cutoff' in metric
115
+
116
+
90
117
def distinct_advanced_aggregation_parameter_set (
91
118
aggregation ,
92
119
operation ,
Original file line number Diff line number Diff line change @@ -39,6 +39,16 @@ def test_unique_fact_names():
39
39
eppo_metrics_sync .validate ()
40
40
41
41
42
+ def test_valid_guardrail_cutoff_signs ():
43
+ eppo_metrics_sync = EppoMetricsSync (directory = None )
44
+ eppo_metrics_sync .load_eppo_yaml (
45
+ path = test_yaml_dir + "/invalid_guardrail_cutoff_sign.yaml" )
46
+
47
+ with pytest .raises (ValueError , match = "Total Upgrades to Paid Plan is having invalid guardrail_cutoff sign: "
48
+ "guardrail_cutoff value should be negative" ):
49
+ eppo_metrics_sync .validate ()
50
+
51
+
42
52
"""def test_unique_fact_property_names():
43
53
44
54
eppo_metrics_sync = EppoMetricsSync(directory = None)
Original file line number Diff line number Diff line change
1
+ fact_sources :
2
+ - name : upgrades_table
3
+ sql : select * from upgrades
4
+ timestamp_column : ts
5
+ entities :
6
+ - entity_name : user
7
+ column : user_id
8
+ facts :
9
+ - name : upgrades
10
+ desired_change : increase
11
+ metrics :
12
+ - name : Total Upgrades to Paid Plan
13
+ entity : User
14
+ is_guardrail : true
15
+ guardrail_cutoff : 1
16
+ numerator :
17
+ fact_name : upgrades
18
+ operation : sum
You can’t perform that action at this time.
0 commit comments