-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Plugin state-persistence #12166
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome. Played with this using the tail plugin and successfully saw it re-start and only ingest the new lines. As usual the code looks great, my concerns are about how to interact with the feature:
-
What is the expected behavior when the state file does not exist? I see an info (not error) log message telling me the file does not exist, but telegraf stops executing.
-
It appears it is up to the user to create an empty JSON file to store state in initially? This seems unnecessary and not straightforward.
-
If the config file changes, telegraf does not tell the user that the ids changed compared to what already existed and the state will reset. It think we need to be more noisy about this.
-
I am wondering if there is a change and the state file will need to be updated, should we keep the old state file around to let a user revert?
-
Does the persister module need specific unit tests. I see it is used throughout config.go, but wondering if something is needed there.
-
Need a doc about this feature in two places: a) for developers about what needs to happen when adding this to a plugin and b) to users in general docs
bc781da
to
ed46e52
Compare
Thanks for the review and comments @powersj. Let me answer your points...
This was an unintended behavior and should be fixed now. If no state-file exists it will be created by Telegraf on exit so the user has to do nothing.
I'm not sure how to do this. I can report the IDs of the plugins that differ (i.e. that are in the state-file but not the current config and vice versa) but does that make sense to the user? Should I store additional information for this report? If so, what do you envision? The complete plugin config?
No. Last time we discussed persistence the consensus was "as simple as possible". If the user wants versioning, he can still wrap telegraf with a script copying the latest state to a
I don't think so. The config tests completely cover the persister, I don't know how a good non-integrated unit-test should look like.
6b) is already in the PR (see change in |
Awesome thank you!
I need to remind myself of how we review files, but off the top of my head is there a way we can keep the sha256 sum of the config file? and report if it changed?
ok
6a should go into Thanks again! |
Basically I keep the ID of the plugin. I could annotate this with the plugin name (like
Sounds good. Will do. |
ok thanks for reminding me why this is more complex :) Let's drop this for now. |
Download PR build artifacts for linux_amd64.tar.gz, darwin_amd64.tar.gz, and windows_amd64.zip. 📦 Click here to get additional PR build artifactsArtifact URLs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this! I think we will want to a) write up a blog post and b) include a highlight of this in the release notes and make it clear this is a new/early feature.
Thanks again for the work!
This is awesome, very much looking forward to this! |
Hi, Feature-Request: That would be the correct location to put this sort of file by default. |
@knollet please open an issue for this and do not hide it in an "old" PR! |
resolves #8352
replaces #9476
This PR adds the machinery to persist the "state" of a plugin over multiple Telegraf runs. A plugin's state is defined by the plugin itself and only has the requirement of being serializable to JSON.
The framework defines an interface that plugins have to adhere to for providing a state (
GetState()
) and restore a state on load (SetState()
). It furthermore implements apersister
to collect and save the states to disk on Telegraf shutdown and to load and distribute the states on Telegraf startup.At the code of the machinery, the framework will generate a unique ID for each configured plugin instance to relate the saved states to the corresponding plugin instance. The ID generation is based on the TOML configuration of each plugin instances and is consistent over restarts of Telegraf as long as the plugin configuration is unchanged. At this, the ID generation is invariant to order changes or reorganization among config-files as long as no options are added, removed or modified.