Skip to content

Commit

Permalink
fix: update language on handling of lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
j-lanson committed Oct 10, 2024
1 parent 301df64 commit 779faf0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions hipcheck/src/policy/config_to_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,8 +421,8 @@ fn parse_entropy(
let value_threshold = entropy.value_threshold;
let percent_threshold = entropy.percent_threshold;
let expression = format!(
"(eq {} (count (filter (gt {}) $)))",
percent_threshold, value_threshold
"(lte (divz (count (filter (gt {}) $)) (count $)) {})",
value_threshold, percent_threshold
);

// Add the plugin
Expand Down
2 changes: 1 addition & 1 deletion hipcheck/src/policy/test_example.kdl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ analyze {
}

analysis "mitre/churn" policy="(lte (divz (count (filter (gt 3) $)) (count $)) 0.02)" weight=1
analysis "mitre/entropy" policy="(eq 0 (count (filter (gt 10) $)))" weight=1
analysis "mitre/entropy" policy="(lte (divz (count (filter (gt 10) $)) (count $)) 0)" weight=1
}
}
}
9 changes: 6 additions & 3 deletions site/content/docs/guide/plugin/policy-expr.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,11 @@ function call. When we do the following:

It will apply the lambda to each element of the float array, resulting in an
array of three booleans that correspond to whether the element at that index in
the float array was greater than `8.0` ("greater than" because the first operand
of `lte` is `8.0`, not the array element).
the float array was less than `8.0`.

Note that for this to work, the array element is inserted as the first operand
in a binary operand function.


##### Lambda Function Reference

Expand Down Expand Up @@ -189,7 +192,7 @@ pointers. As an example, this can be useful if you want to calculate the
percentage of elements of an array that pass a filter:

```
(lt (divz (count (filter (gt 10) $) (count $))) 0.5)
(lt (divz (count (filter (lt 10) $) (count $))) 0.5)
```

This policy expression will check that less than half of the elements in `$` are
Expand Down

0 comments on commit 779faf0

Please sign in to comment.