Skip to content

Commit

Permalink
fix: Rebuild the datasource when settings change
Browse files Browse the repository at this point in the history
  • Loading branch information
njvrzm committed Feb 28, 2024
1 parent 5dbfac1 commit 6637f0b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/athena/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (r *AthenaResourceHandler) workgroups(rw http.ResponseWriter, req *http.Req
routes.SendResources(rw, res, err)
}

func (r *(AthenaResourceHandler)) workgroupEngineVersion(rw http.ResponseWriter, req *http.Request) {
func (r *AthenaResourceHandler) workgroupEngineVersion(rw http.ResponseWriter, req *http.Request) {
reqBody, err := routes.ParseBody(req.Body)
if err != nil {
rw.WriteHeader(http.StatusBadRequest)
Expand Down
23 changes: 16 additions & 7 deletions pkg/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package main

import (
"context"
"github.com/grafana/grafana-plugin-sdk-go/backend"
"github.com/grafana/grafana-plugin-sdk-go/backend/instancemgmt"
"os"

"github.com/grafana/athena-datasource/pkg/athena"
Expand All @@ -12,18 +15,24 @@ import (

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

if err := datasource.Manage(
"grafana-athena-datasource",
ds.NewDatasource,
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 := athena.New()
ds := awsds.NewAsyncAWSDatasource(s)
ds.Completable = s
ds.EnableMultipleConnections = true
ds.CustomRoutes = routes.New(s).Routes()
return ds.NewDatasource(ctx, settings)
}
}

0 comments on commit 6637f0b

Please sign in to comment.