Configuration parameters
Use the parameters in this section to configure this processing rule. The Telemetry Pipeline web interface uses the items in the Name column to describe these parameters. Pipeline configuration files use the items in the Key column as YAML keys.| Name | Key | Description | Default |
|---|---|---|---|
| Script | script | Required. Your custom Lua script. | none |
| Comment | comment | A custom note or description of the rule’s function. This text is displayed next to the rule’s name in the Actions list in the processing rules interface. You can also use GPT generation to treat this comment as the prompt for a new Lua script. | none |
GPT generation
Keep in mind that this feature is experimental, and that Chronosphere can’t guarantee
the accuracy or quality of generated scripts.To enable or disable GPT generation, see
Project settings.
Best practices
To ensure that custom Lua scripts run efficiently within your pipelines, Chronosphere recommends following these best practices:- Test new scripts in the processing rules playground. Before adding a custom Lua script to an active pipeline, try running the script in the processing rules playground in the Telemetry Pipeline UI. This lets you test your script on sample input data, view the script’s transformed output, and catch syntax errors.
-
Add
printanderrorstatements to your scripts. These statements help you track the value of variables and see details about specific errors when they occur. - Use profiling. In the processing rules playground, you can toggle the Enable profiling setting to view more information about a script’s transformed output, including how long it took for that script to run.
Example scripts
The following examples show several possible types of Lua scripts you can incorporate into your pipeline.Conditional statement
You can use conditional statements to transform data that meets certain criteria. This example script looks for a key namedlog, and then determines whether
its value is line. If both of these conditions are true, the script sets
the value of log to Y.
Reference to a secret
If your pipeline includes secrets, you can reference these secrets through Lua scripts. Because secrets are stored as environment variables within a pipeline, this example accesses that environment variable, and then stores its value in a new variable namedsecret.
Additionally, this script calls the resolve function only if the secret key
hasn’t been defined before, which helps improve performance.
Call to a third-party API
You can use Lua scripts to call a third-party HTTP API, and then use data from that API to perform various actions. This example imports the Lua JSON library to support the JSON response returned by a specific API, then uses a separate function to call that API, and then creates a new key to store the value of a successful API response.Reading a pipeline file
You can use pipeline files to store arbitrary data, including JSON, and use a Lua script to access that data. This example imports the Lua JSON library, then uploads a file calledschema,
and then converts and returns the data stored in that file.
The processing rules playground can’t access pipeline files. To test a Lua script
that reads files, Chronosphere recommends creating a small pipeline that uses mock
data.