Skip to content

Commit 6c2e25f

Browse files
krithika369Krithika Sundararajan
and
Krithika Sundararajan
authored
Update Treatment Validation doc with examples (#63)
Co-authored-by: Krithika Sundararajan <krithika.sundararajan@go-jek.com>
1 parent 4e4b099 commit 6c2e25f

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

docs/how-to/03_modifying_settings.md

+26-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,32 @@ From the Validation Detail page, click 'More Actions' -> 'Configure Validation'.
7676

7777
* A response with status code of 200 will be deemed as successful. A timeout of 5 seconds is also configured to treat any hanging call to the validation URL as a failure.
7878

79-
3. Treatment Validation Rules: Rules used to validate treatment configuration of experiments. All rules will be evaluated on the treatment configuration and must return `true` for the operation to be permitted.
79+
3. Treatment Validation Rules: Rules, specified in the form of [Go Templates](https://pkg.go.dev/text/template), used to validate treatment configuration of experiments. In addition to the default Go Template operations, those from the [Sprig library](http://masterminds.github.io/sprig/) are also supported. All rules will be evaluated on the treatment configuration and must return `true` for the operation to be permitted. Some examples below.
80+
81+
To test that the data satisfies one of the following conditions:
82+
* `.field1`=`"abc"` and `.field2`=`"def"` and `.field3.field4` is of type `float`
83+
* (OR) `.field1`=`"xyz"` and `.field2`=`"def"` and `.field3.field4` is of type `int`
84+
85+
```
86+
{{- or (and
87+
(eq .field1 "abc")
88+
(eq .field2 "def")
89+
(contains "float" (typeOf .field3.field4)))
90+
(and
91+
(eq .field1 "xyz")
92+
(eq .field2 "def")
93+
(contains "int" (typeOf .field3.field4))) -}}
94+
```
95+
96+
To test that a certain property `weight` in an array field `.config_details.models` sums to 1 across all elements:
97+
98+
```
99+
{{- $sum := 0 -}}
100+
{{- range $index, $item := .config_details.models -}}
101+
{{- $sum = (addf $sum $item.weight) -}}
102+
{{- end -}}
103+
{{- eq $sum 1.0 -}}
104+
```
80105

81106
### Creating or Updating an Experiment
82107

0 commit comments

Comments
 (0)