Golang Lambda Transformer
The Golang Lambda Transformer feature in our platform offers advanced way to transform data before sending it to the Fitness Engine. This feature provides the ability to writing a snippet of Golang code to transform the Signal object before sending it to the Fitness Engine. This is particularly useful for transforming data that is not in the correct format or to add additional data to the Signal object.
Configuration
The transformer is initialized by providing "transformer" object within the Fitness Sensor configuration. The "transformer" object can hold the golang snippet that is used to transform the Signal object.
The Golang snippet provides a "signal" object that holds the json signal collected by the Pulse Sensor as a map[any]interface{} object. The snippet can be used to modify the signal object as needed. The last state of the "signal" object will be used to send the signal to the Fitness Engine - no explicit return is needed.
Example
The example highlights the use of the transformer in conjuction with Mask and prune features.
kind: FitnessSensor
apiVersion: fitness.orcasio.com/v1alpha3
metadata:
name: kube-deploy
namespace: orcas
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
data:
excludeNamespaces:
- '[a-z]*-ops'
tags:
env: dev
org: it
clustername: sample
prune:
- .data.spec.template.metadata
mask:
- .data.spec.template.spec.containers[0].volumeMounts
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