accurate state documentation for Starlark

This commit is contained in:
Steven Soroka 2021-03-11 16:35:26 -05:00 committed by GitHub
parent 67904b07ee
commit b263c1fedf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 1 deletions

View File

@ -165,9 +165,12 @@ def apply(metric):
**How can I save values across multiple calls to the script?**
A shared global dictionary named `state` exists, this can be used by the `apply` function.
Telegraf freezes the global scope, which prevents it from being modified, except for a special shared global dictionary
named `state`, this can be used by the `apply` function.
See an example of this in [compare with previous metric](/plugins/processors/starlark/testdata/compare_metrics.star)
Other than the `state` variable, attempting to modify the global scope will fail with an error.
**How to manage errors that occur in the apply function?**
In case you need to call some code that may return an error, you can delegate the call