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

Rebuild the datasource when settings change #283

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions pkg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,23 @@ import (
)

func main() {
// Start listening to requests sent from Grafana.
s := redshift.New()
ds := awsds.NewAsyncAWSDatasource(s)
ds.Completable = s
ds.CustomRoutes = routes.New(s).Routes()

// newDatasourceForUpgradedPluginSdk adds context to the NewDatasource function, which is the new signature expected
// for an InstanceFactoryFunc in grafana-plugin-sdk-go
// TODO: Remove this function and create a NewDatasource method with Context in grafana-aws-sdk, see https://github.com/grafana/oss-plugin-partnerships/issues/648
newDatasourceForUpgradedPluginSdk := func(ctx context.Context, settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
return ds.NewDatasource(ctx, settings)
}

if err := datasource.Manage(
"grafana-redshift-datasource",
newDatasourceForUpgradedPluginSdk,
MakeDatasourceFactory(),
datasource.ManageOpts{},
); err != nil {
log.DefaultLogger.Error(err.Error())
os.Exit(1)
}
}

func MakeDatasourceFactory() datasource.InstanceFactoryFunc {
return func(ctx context.Context, settings backend.DataSourceInstanceSettings) (instancemgmt.Instance, error) {
log.DefaultLogger.FromContext(ctx).Debug("building new datasource instance")
s := redshift.New()
ds := awsds.NewAsyncAWSDatasource(s)
ds.Completable = s
ds.CustomRoutes = routes.New(s).Routes()
return ds.NewDatasource(ctx, settings)
}
}
Loading