How to Create a Snap Plugin - Snap-for-Windows/snap GitHub Wiki
Objective
This document is meant to clarify and aggregate the steps outlined at Plugin Authoring Guidelines and Plugin Best Practices and how it relates specifically to authoring a plugin for Windows. The document will change as our understanding of plugin authoring and best practices grows.
Before You Start Coding
- Read through the recently updated Snap PLUGIN_AUTHORING page. Don't worry if most of it doesn't make sense. This will just give you a general overview of things which will be covered further on.
- Read over the Go By Example website through the Errors section to get a good understanding of concepts/syntax you'll see in the GO plugin code.
- Look at the code and read through the README document for this Snap collector example. This structure is what your plugin code should be generally based off of.
- Examine one or two of the other Linux Snap plugins to get an idea of how a plugin is structured and how they are set up (the psutil plugin is a good one to look at).
- Outline your plugin metrics. Metrics are very easy to add in once the basic plugin structure is set up. Feel free to start out with just a few important metrics.
- Create a repository for the plugin. The plugin name should follow the format: snap-plugin-[type]-[name] The type can be either collector, processor, or publisher.
- Set up the basic plugin file structure. Here is the example given in the PLUGIN_AUTHORING doc:
snap-plugin-[type]-[name]
..|--[name]
....|--[name].go
....|--[name]_test.go
....|--[name]_integration_test.go
..|--main.go
..|--main_test.go
Coding Time
-
Add three mandatory dependencies to import statement of the [name].go file: From PLUGIN_AUTHORING doc: "There are three mandatory packages that every plugin must use. Other than those three packages, you can use other packages as necessary. There is no danger of colliding dependencies as plugins are separated processes. The mandatory packages are:"
.....github.com/intelsdi-x/snap/control/plugin
.....github.com/intelsdi-x/snap/control/plugin/cpolicy
.....github.com/intelsdi-x/snap/core/ctypes
Other dependencies can be added to the project as needed. -
Create a const () section defining variables for the plugin vendor, filesystem (if applicable), plugin name, plugin version, and plugin type. Other variables can be added if needed, but these specific variables define the metadata for the plugin.
-
For each type of plugin, certain methods will need to be included in your [name].go code.
a. If the plugin in a collector plugin, you will need to include the following three methods:
GetConfigPolicy() (*cpolicy.ConfigPolicy, error)
CollectMetrics([]MetricType) ([]MetricType, error)
GetMetricTypes(ConfigType) ([]MetricType, error) -
Create Plugin Meta data by
Still need to include
- What exactly is a CODEC in terms of Snap and why is it needed
- How to implement the functions specifically for each type of plugin (See PLUGIN_AUTHORING doc)
- How do we use pluginsync with plugin
- How do we use snap plugin utilities to help build snap/Do we need it?
- What exactly can glide be used for/is it useful for our plugins/if so, how do we use it?