v0.162.0
What's Changed
- Makes sure go build manifest file is generated with POSIX separators by @academo in #687
 - Use tenant ID from incoming gRPC meta for instance caching by @wbrowne in #676
 
Full Changelog: v0.161.0...v0.162.0
Breaking changes
Both the Instance Manager and Instance Provider interfaces have been updated to require a context.Context as part of their APIs. This affects all plugins which perform manual instance management via the Instance Manager API. Adding context as a parameter to instance management faciliates propagation of contextual information, which is useful particularly for instance caching.
For example:
package plugin
type Plugin struct {
	im instancemgmt.InstanceManager
}
func (p *Plugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
	i, err := p.im.Get(ctx, req.PluginContext) // ctx is now required
	if err != nil {
		return nil, err
	}
	// ..
}Recommended fix
Automatic instance management
Automatic instance management for data sources was added to the SDK in version 0.97.0, which
removes the need for plugin developers to use the Instance Manager directly. Support for app plugins was added in v0.140.0.
To use auto instance management, please refer to the relevant SDK documentation:
The following demonstrates usage of automatic instance management:
package main
func main() {
	err := datasource.Manage("grafana-test-datasource", plugin.New(), datasource.ManageOpts{})
	if err != nil {
		os.Exit(1)
	}
}package plugin
func New(s backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
	cfg := models.LoadCfg(s)
	return &plugin{token: cfg.Token}, nil
}
type plugin struct {
	token string
}
func (p *plugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
	return backend.NewQueryDataResponse(), nil
}Alternative
We highly encourage that all plugin developers make use of automatic instance management. However, as short term solution you can instead pass context.Context from each handler to the instance manager.
For example:
func (p * Plugin) QueryData(ctx context.Context, req *backend.QueryDataRequest) (*backend.QueryDataResponse, error) {
	i, err := p.im.Get(ctx, req.PluginContext) // ctx is now required
	if err != nil {
		return nil, err
	}
	// ..
}
func (p * Plugin) CallResource(ctx context.Context, req *backend.CallResourceRequest, sender backend.CallResourceResponseSender) error {
	i, err := p.im.Get(ctx, req.PluginContext) // ctx is now required
	if err != nil {
		return nil, err
	}
	// ..
}Compatibility
gorelease -base v0.161.0 -version v0.162.0
# github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt
## incompatible changes
InstanceManager.Do: changed from func(github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext, InstanceCallbackFunc) error to func(context.Context, github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext, InstanceCallbackFunc) error
InstanceManager.Get: changed from func(github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext) (Instance, error) to func(context.Context, github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext) (Instance, error)
InstanceProvider.GetKey: changed from func(github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext) (interface{}, error) to func(context.Context, github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext) (interface{}, error)
InstanceProvider.NeedsUpdate: changed from func(github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext, CachedInstance) bool to func(context.Context, github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext, CachedInstance) bool
InstanceProvider.NewInstance: changed from func(github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext) (Instance, error) to func(context.Context, github.com/grafana/grafana-plugin-sdk-go/backend.PluginContext) (Instance, error)
# github.com/grafana/grafana-plugin-sdk-go/backend/tenant
## compatible changes
package added
# github.com/grafana/grafana-plugin-sdk-go/backend/tenant/tenanttest
## compatible changes
package added