|
1 | 1 | package app |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "fmt" |
5 | 6 |
|
6 | 7 | "github.com/grafana/grafana-plugin-sdk-go/backend" |
7 | 8 | "github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt" |
| 9 | + "github.com/grafana/grafana-plugin-sdk-go/backend/tenant" |
8 | 10 | ) |
9 | 11 |
|
10 | 12 | // InstanceFactoryFunc factory method for creating app instances. |
@@ -40,23 +42,28 @@ type instanceProvider struct { |
40 | 42 | factory InstanceFactoryFunc |
41 | 43 | } |
42 | 44 |
|
43 | | -func (ip *instanceProvider) GetKey(pluginContext backend.PluginContext) (interface{}, error) { |
| 45 | +func (ip *instanceProvider) GetKey(ctx context.Context, pluginContext backend.PluginContext) (interface{}, error) { |
44 | 46 | if pluginContext.AppInstanceSettings == nil { |
45 | 47 | // fail fast if there is no app settings |
46 | 48 | return nil, fmt.Errorf("app instance settings cannot be nil") |
47 | 49 | } |
48 | 50 |
|
49 | 51 | // The instance key generated for app plugins should include both plugin ID, and the OrgID, since for a single |
50 | 52 | // Grafana instance there might be different orgs using the same plugin. |
51 | | - return fmt.Sprintf("%s#%v", pluginContext.PluginID, pluginContext.OrgID), nil |
| 53 | + defaultKey := fmt.Sprintf("%s#%v", pluginContext.PluginID, pluginContext.OrgID) |
| 54 | + if tID := tenant.IDFromContext(ctx); tID != "" { |
| 55 | + return fmt.Sprintf("%s#%s", tID, defaultKey), nil |
| 56 | + } |
| 57 | + |
| 58 | + return defaultKey, nil |
52 | 59 | } |
53 | 60 |
|
54 | | -func (ip *instanceProvider) NeedsUpdate(pluginContext backend.PluginContext, cachedInstance instancemgmt.CachedInstance) bool { |
| 61 | +func (ip *instanceProvider) NeedsUpdate(_ context.Context, pluginContext backend.PluginContext, cachedInstance instancemgmt.CachedInstance) bool { |
55 | 62 | curSettings := pluginContext.AppInstanceSettings |
56 | 63 | cachedSettings := cachedInstance.PluginContext.AppInstanceSettings |
57 | 64 | return !curSettings.Updated.Equal(cachedSettings.Updated) |
58 | 65 | } |
59 | 66 |
|
60 | | -func (ip *instanceProvider) NewInstance(pluginContext backend.PluginContext) (instancemgmt.Instance, error) { |
| 67 | +func (ip *instanceProvider) NewInstance(_ context.Context, pluginContext backend.PluginContext) (instancemgmt.Instance, error) { |
61 | 68 | return ip.factory(*pluginContext.AppInstanceSettings) |
62 | 69 | } |
0 commit comments