Skip to content
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

Provide a capability / interface for trigger a config reload #1043

Open
jkroepke opened this issue Aug 5, 2024 · 2 comments
Open

Provide a capability / interface for trigger a config reload #1043

jkroepke opened this issue Aug 5, 2024 · 2 comments
Labels
enhancement New feature or request stale Issue or PR without activity

Comments

@jkroepke
Copy link
Contributor

jkroepke commented Aug 5, 2024

What would you like to be added:

I'm develop an Grafana App and I have no clue, what happens, if the user updates the settings at admin panel. I guess, the setting will be saved on Grafana side, but not propagated to the plugin.

Having if a interface where implement I can implement a configReload function, would be great.

_ backend.ConfigReloadHandler    = (*App)(nil)

I the code, I can see a NeedsUpdate function, no clue what it does.

func (ip *instanceProvider) NeedsUpdate(_ context.Context, pluginContext backend.PluginContext, cachedInstance instancemgmt.CachedInstance) bool {

Why is this needed:

Reading the https://grafana.com/developers/plugin-tools/key-concepts/backend-plugins/#caching-and-connection-pooling It's recommend to setup the client on init and re-use it every time.

But, if settings are updated by admin, I have to re-create some clients on reload.

@jkroepke jkroepke added the enhancement New feature or request label Aug 5, 2024
@wbrowne
Copy link
Member

wbrowne commented Aug 15, 2024

Hi @jkroepke.

if the user updates the settings at admin panel. I guess, the setting will be saved on Grafana side, but not propagated to the plugin.

Where are you storing settings? Inside jsonData / secureJsonData? Please see below which shows a demonstration of the instance factory function (NewApp), which is invoked when settings are changed.

package main

func main() {
	if err := app.Manage("myorg-withbackend-app", plugin.NewApp, app.ManageOpts{}); err != nil {
		log.DefaultLogger.Error(err.Error())
		os.Exit(1)
	}
}
package plugin

// NewApp creates a new example *App instance. This function will be invoked every time there is an update 
// to the `Updated` timestamp of the `AppInstanceSettings` (controlled by Grafana)
func NewApp(_ context.Context, _ backend.AppInstanceSettings) (instancemgmt.Instance, error) {
	var app App

	mux := http.NewServeMux()
	app.registerRoutes(mux)
	app.CallResourceHandler = httpadapter.New(mux)

	return &app, nil
}

// Dispose here tells plugin SDK that plugin wants to clean up resources when a new instance
// created.
func (a *App) Dispose() {
	// cleanup
}

// CheckHealth handles health checks sent from Grafana to the plugin.
func (a *App) CheckHealth(_ context.Context, _ *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
	return &backend.CheckHealthResult{
		Status:  backend.HealthStatusOk,
		Message: "ok",
	}, nil
}

@jkroepke
Copy link
Contributor Author

Where are you storing settings? Inside jsonData / secureJsonData?

Yes.

I'm a bit aware that Grafana invoke Dispose/NewApp on config change. But from plugin point of view, that a full restart rather an a soft-reload.

For example, the app holds some long-living requests/connection and they should not interrupt on config-change.

@github-actions github-actions bot added the stale Issue or PR without activity label Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request stale Issue or PR without activity
Projects
None yet
Development

No branches or pull requests

2 participants