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

sqlds - Allow ctx mod #127

Merged
merged 3 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ func (ds *SQLDatasource) QueryData(ctx context.Context, req *backend.QueryDataRe

wg.Add(len(req.Queries))

if queryDataMutator, ok := ds.driver().(QueryDataMutator); ok {
ctx, req = queryDataMutator.MutateQueryData(ctx, req)
}

// Execute each query and store the results by query RefID
for _, q := range req.Queries {
go func(query backend.DataQuery) {
Expand Down Expand Up @@ -243,6 +247,9 @@ func (ds *SQLDatasource) handleQuery(ctx context.Context, req backend.DataQuery,

// CheckHealth pings the connected SQL database
func (ds *SQLDatasource) CheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (*backend.CheckHealthResult, error) {
if checkHealthMutator, ok := ds.driver().(CheckHealthMutator); ok {
ctx, req = checkHealthMutator.MutateCheckHealth(ctx, req)
}
healthChecker := &HealthChecker{
Connector: ds.connector,
Metrics: ds.metrics.WithEndpoint(EndpointHealth),
Expand Down
13 changes: 13 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ type Connection interface {
QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
}

// QueryDataMutator is an additional interface that could be implemented by driver.
// This adds ability to the driver to optionally mutate the query before it's run
// with the QueryDataRequest.
type QueryDataMutator interface {
MutateQueryData(ctx context.Context, req *backend.QueryDataRequest) (context.Context, *backend.QueryDataRequest)
}

// CheckHealthMutator is an additional interface that could be implemented by driver.
// This adds ability to the driver to optionally mutate the CheckHealth before it's run
type CheckHealthMutator interface {
MutateCheckHealth(ctx context.Context, req *backend.CheckHealthRequest) (context.Context, *backend.CheckHealthRequest)
}

// QueryMutator is an additional interface that could be implemented by driver.
// This adds ability to the driver it can mutate query before run.
type QueryMutator interface {
Expand Down