Overview
The Orcasio Pulse Platform enables you to seamlessly integrate custom logic into Fitness Rule processing and Pulse Sensor data transformer processing. This custom logic is implemented as a Lambda function written in Go, conveniently as a snippet without the need for a full-fledged Go project. The Go Lambda snippet has access to the Fitness Signal object and can utilize standard Go libraries without the need for explicit imports. In addition to standard Go libraries, the Go Lambda snippet also has access to Orcasio Pulse's helper libraries.
Fitness Rule
In order to use the Go Lambda in a rule you need to take into account that you will be able to use the following values:
Request
- Key: the key where the measure is specified
- Value: the value coming from the signal with the specified key
- Signal: the hole signal object
Response
- Message: result of processing the signal
- FitnessPercent: value from 0 to 100
- Tags: addition tags
Example
In this example the sensor provides data from a kubertes deployment.
kind: OrcasRule
apiVersion: orcasio.com/v1alpha3
metadata:
name: avail-deploy
namespace: sample
spec:
version: v1.0.0
rule:
spec:
replicas:
orcas:enabled: true
orcas:measure: "replicas"
orcas:value: |
# golang
v, _ := pulsenumber.ToInt(request.Value)
response.Measure = "replicas"
switch v {
case 0:
response.Message = "No active replicas"
response.FitnessPercent = 0
case 1:
response.Message = "Does not meet the minimum number of replicas"
response.FitnessPercent = 25
case 2:
response.Message = "Does not meet the minimum number of replicas"
response.FitnessPercent = 50
default:
response.Message = "Meets the minimum number of replicas"
response.FitnessPercent = 100
}
Fitness Sensor
Go Lambdas can also be used in Fitness Sensors to transform collected data before sending it to the stream.
kind: FitnessSensor
apiVersion: fitness.orcasio.com/v1alpha3
metadata:
name: kube-deploy
namespace: sample
spec:
sensor: sensor://fitness.orcasio.net/kubernetes
source: deployment
configmap: kubernetes
secret: kubernetes
trigger:
name: kubewatch
kubewatch:
apiVersion: "apps/v1"
kind: "Deployment"
namespace: orcas
enabled: true
transformer: |
# golang
signal["apiVersion"] = "def" # => result will be to rename the apiVersion to "def" in the signal object
pulsejson.Delete(".metadata.labels", signal) # => result will be to delete the labels object from the signal.metadata object
# Creating dynamic tags
t := map[string]any{}
t["newTagKey"] = "newTagValue"
signal["tags"] = t