Develop Plugins
Setup
- Setup your dev environment. Follow this guide.
- Read up the concepts documentation about provider and plugins.
Identify which provider interface you need to implement
- Choose the provider which is used to implement the data you like to integrate.
dynres
implements energy usage, cpu frequency etc.staticres
implements cloud provider, hypervisors etc. that manage your infrastructure resources.dynenv
implements energy grid APIs
- Setup your starting point (one of these)
dynres
: Copy the folderpkg/plugin/dynresplugins/mockenergy
and rename it to your plugins namestaticres
: Copy the folderpkg/plugin/staticresplugins/mockcloudplugin
and rename it to your plugins namedynenv
: Copy the folderpkg/plugin/dynenvplugins/mockenergymix
and rename it to your plugins name
Implement your Plugin
- Implement the provider interface. Add unit, integration and optional end to end testing.
- Make sure to add the provider reference to the plugin file:
- For
dynres
add it topkg/plugin/dynresplugins/dynresplugins.go
- For
staticres
add it topkg/plugin/staticresplugins/staticresplugins.go
- For
dynenv
add it topkg/plugin/dynenvplugins/dynenvplugins.go
- For
- Make sure to add the provider reference to the plugin file:
- If applicable add caching.
type p struct {
// ...
cache *cache.Cache
}
func New(cfg *Config) (p, error) {
// Create a cache with an expiration time of 60 seconds, and which
// purges expired items every 5 minutes
c := cache.New(60*time.Second, 5*time.Minute)
// ...
}
func reqData(id string) (*Data, error) {
// ...
if cachedData, found := p.cache.Get(id); found {
return cachedData, nil
}
// ...
if err := p.cache.Add(id, data, cache.DefaultExpiration); err != nil {
return nil, errors.New("unable to add data to internal cache")
}
// ...
}
Push changes
Push changes and open a PR to propose merging changes to Carbonaut. See contribution guide.