Skip to content

Commit

Permalink
cel functions (#231)
Browse files Browse the repository at this point in the history
* docs: added few methods on list/map

* docs: kubernetes methods

* chore: spelling fixes
  • Loading branch information
adityathebe authored Jun 24, 2024
1 parent 0cac7f1 commit 8d425e1
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 5 deletions.
2 changes: 1 addition & 1 deletion canary-checker/docs/concepts/_artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Artifacts allow you to archive files generated by some checks to a file store of

## Setting up artifact store

One of the above filestores can be used as the global artifact store. To setup an artifact store, pass the connection name of the store using the `artifact-connection` flag. If the artifact connection isn't setup, the artifacts are simply ignored.
One of the above Filestores can be used as the global artifact store. To setup an artifact store, pass the connection name of the store using the `artifact-connection` flag. If the artifact connection isn't setup, the artifacts are simply ignored.

Check failure on line 17 in canary-checker/docs/concepts/_artifacts.md

View workflow job for this annotation

GitHub Actions / vale

[vale] canary-checker/docs/concepts/_artifacts.md#L17

[Vale.Terms] Use 'filestores' instead of 'Filestores'.
Raw output
{"message": "[Vale.Terms] Use 'filestores' instead of 'Filestores'.", "location": {"path": "canary-checker/docs/concepts/_artifacts.md", "range": {"start": {"line": 17, "column": 18}}}, "severity": "ERROR"}

Example:

Expand Down
4 changes: 2 additions & 2 deletions canary-checker/docs/reference/1-exec.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ title: Exec



Executes a bash (linux) or powershell (windows) script. The check is considered passing if the script exits with `0`
Executes a bash (Linux) or powershell (Windows) script. The check is considered passing if the script exits with `0`

:::tip Docker Image variants
See [image-variants](/reference/canary-checker/image-variants)
Expand All @@ -20,7 +20,7 @@ See [image-variants](/reference/canary-checker/image-variants)

{
field: "script",
description: " Script can be a inline script or a path to a script that needs to be executed. On windows executed via Powershell and in darwin and linux executed using bash",
description: " Script can be a inline script or a path to a script that needs to be executed. On windows executed via Powershell and in darwin and Linux executed using bash",
required: true
},
{
Expand Down
202 changes: 202 additions & 0 deletions canary-checker/docs/scripting/cel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,124 @@ base64.decode("aGVsbG8=") // return b'hello'
## collections
### .keys
The `keys` method on a map returns a list of keys..
Syntax:
```javascript
e.keys()
// Where:
// `e` is a map .
```
Examples:
```javascript
{"first": "John", "last": "Doe"}.keys() // ["first", "last"]
```
### .merge
The `merge` method on a map takes in a second map to merge with.
Syntax:
```javascript
e.merge(x)
// Where:
// `e` is the map you want to merge to.
// `x` is the second map to merge from.
```
Examples:
```javascript
{"first": "John"}.merge({"last": "Doe"}) // {"first": "John", "last": "Doe"}
```
### .omit
The `omit` method on a map takes a list of keys to omit from the map.
Syntax:
```javascript
e.omit(x)
// Where:
// `e` is a list .
// `x` is a list of keys to omit.
```
Examples:
```javascript
{"first": "John", "last": "Doe"}.omit(["first"]) // {"last": "Doe"}
```
### .sort
The `sort` method on a list returns the reversed list.
Syntax:
```javascript
e.sort()
// Where:
// `e` is a list .
```
Examples:
```javascript
[3, 2, 1].sort() // [1, 2, 3]
['c', 'b', 'a'].sort() // ['a', 'b', 'c']
```
### .uniq
The `uniq` method on a list returns a list of the unique elements.
Syntax:
```javascript
e.uniq()
// Where:
// `e` is a list .
```
Examples:
```javascript
[1,2,3,3,3,].uniq().sum() // 10
["a", "b", "b"].uniq().join() // "ab"
```
### .values
The `values` method on a map returns a list of values.
Syntax:
```javascript
e.values()
// Where:
// `e` is a map .
```
Examples:
```javascript
{'a': 1, 'b': 2}.values().sum() // 3
```
### all
The `all` macro tests whether a predicate holds for **all** elements of a list `e` or keys of a map `e`. It returns a boolean value based on the evaluation.
Expand Down Expand Up @@ -1069,6 +1187,44 @@ k8s.getStatus(service) // "Active" if the service is active
k8s.getStatus(deployment) // "Deployed" if the deployment is successful
```
### k8s.getResourcesLimit
`k8s.getResourcesLimit` retrieves the resource (cpu/memory) limit of a Kubernetes resource.
Syntax:
k8s.getResourcesLimit(pod, resource)
Where:
- `pod` is the pod object
- `resource` is either 'cpu' or 'memory'
```javascript
// Retrieving the status of a pod:
k8s.getResourcesLimit(pod, "cpu") // 2
k8s.getResourcesLimit(pod, "memory") // 200
```
### k8s.getResourcesRequests
`k8s.getResourcesRequests` retrieves the status of a Kubernetes resource as a string. It provides detailed information about the current state of the resource.
Syntax:
k8s.getResourcesRequests(pod, resource)
Where:
- `pod` is the pod object
- `resource` is either 'cpu' or 'memory'
```javascript
// Retrieving the status of a pod:
k8s.getResourcesRequests(pod, "cpu") // 2
k8s.getResourcesRequests(pod, "memory") // 200
```
### k8s.isHealthy
`k8s.isHealthy` determine if a Kubernetes resource is healthy. It returns a boolean value indicating the health status of the resource.
Expand All @@ -1088,6 +1244,21 @@ k8s.isHealthy(service) // false if the service is not healthy
k8s.isHealthy(deployment) // true if the deployment is healthy
```
### k8s.labels
`k8s.labels` takes in a kubernetes object & returns a map of all the labels.
:::tip
- The namespace is also returned as a label for namespaced objects.
- Any labels ending with `-hash` are removed from the map.
:::
```javascript
// Checking if a pod is healthy:
k8s.labels(pod) // {"namespace": "kube-system", "app": "kube-dns"}
```
### k8s.memoryAsBytes
`k8s.memoryAsBytes` converts the memory string to bytes.
Expand All @@ -1100,6 +1271,37 @@ k8s.memoryAsBytes("10Ki") // 10240
k8s.memoryAsBytes("1.234gi") // 1324997410
```
### k8s.nodeProperties
`k8s.nodeProperties` is a helper function that takes in a kubernetes Node object and returns a map of the following node's properties
- ephemeral-storage (in bytes)
- cpu
- memory
- zone (extracted from topology.kubernetes.io/zone)
```javascript
// Checking if a pod is healthy:
k8s.nodeProperties(pod) // {"cpu": 2, "memory": 200, ephemeral-storage": 100000, zone": "us-east-1a"}
```
### k8s.podProperties
`k8s.podProperties` is a helper function that takes in a kubernetes pod object and returns a map of the following pod's properties
- image
- cpu
- memory
- node
- created-at
- namespace
```javascript
// Checking if a pod is healthy:
k8s.podProperties(pod) // {"image": "postgres:14", "node": "saka", ...}
```
---
## math
Expand Down
2 changes: 1 addition & 1 deletion mission-control/docs/installation/artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ title: Artifacts

## Setting up artifact store

One of the above filestores can be used as the global artifact store. To setup an artifact store, pass the connection name of the store using the `artifact-connection` flag. If the artifact connection isn't setup, the artifacts are simply ignored.
One of the above Filestores can be used as the global artifact store. To setup an artifact store, pass the connection name of the store using the `artifact-connection` flag. If the artifact connection isn't setup, the artifacts are simply ignored.

Check failure on line 15 in mission-control/docs/installation/artifacts.md

View workflow job for this annotation

GitHub Actions / vale

[vale] mission-control/docs/installation/artifacts.md#L15

[Vale.Terms] Use 'filestores' instead of 'Filestores'.
Raw output
{"message": "[Vale.Terms] Use 'filestores' instead of 'Filestores'.", "location": {"path": "mission-control/docs/installation/artifacts.md", "range": {"start": {"line": 15, "column": 18}}}, "severity": "ERROR"}

Example:

Expand Down
2 changes: 1 addition & 1 deletion mission-control/docs/topology/lookups/exec.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ spec:

| Field | Description | Scheme | Required |
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------- | -------- |
| **`script`** | Script can be a inline script or a path to a script that needs to be executed. On windows executed via powershell and in darwin and linux executed using bash. | `Path`, `Bash`or`Powershell` | Yes |
| **`script`** | Script can be a inline script or a path to a script that needs to be executed. On windows executed via powershell and in darwin and Linux executed using bash. | `Path`, `Bash`or`Powershell` | Yes |
| `display` | Template to display server response in text (overrides default bar format for UI) | [_Template_](../concepts/templating) | |
| `labels` | Labels for the check | Labels | |
| `transform` | Template to transform results by excluding or including certain fields in result | [_Template_](../concepts/templating) | |
Expand Down

0 comments on commit 8d425e1

Please sign in to comment.