Skip to content
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
13 changes: 10 additions & 3 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,16 @@ const userAgent = "go-sql-spanner/1.0.2"
// - disableRouteToLeader: Boolean that indicates if all the requests of type read-write and PDML
// need to be routed to the leader region.
// The default is false
// - enableEndToEndTracing: Boolean that indicates if end-to-end tracing is enabled
// The default is false
// - minSessions: The minimum number of sessions in the backing session pool. The default is 100.
// - maxSessions: The maximum number of sessions in the backing session pool. The default is 400.
// - numChannels: The number of gRPC channels to use to communicate with Cloud Spanner. The default is 4.
// - optimizerVersion: Sets the default query optimizer version to use for this connection.
// - optimizerStatisticsPackage: Sets the default query optimizer statistic package to use for this connection.
// - rpcPriority: Sets the priority for all RPC invocations from this connection (HIGH/MEDIUM/LOW). The default is HIGH.
//
// Example: `localhost:9010/projects/test-project/instances/test-instance/databases/test-database;usePlainText=true;disableRouteToLeader=true`
// Example: `localhost:9010/projects/test-project/instances/test-instance/databases/test-database;usePlainText=true;disableRouteToLeader=true;enableEndToEndTracing=true`
var dsnRegExp = regexp.MustCompile(`((?P<HOSTGROUP>[\w.-]+(?:\.[\w\.-]+)*[\w\-\._~:/?#\[\]@!\$&'\(\)\*\+,;=.]+)/)?projects/(?P<PROJECTGROUP>(([a-z]|[-.:]|[0-9])+|(DEFAULT_PROJECT_ID)))(/instances/(?P<INSTANCEGROUP>([a-z]|[-]|[0-9])+)(/databases/(?P<DATABASEGROUP>([a-z]|[-]|[_]|[0-9])+))?)?(([\?|;])(?P<PARAMSGROUP>.*))?`)

var _ driver.DriverContext = &Driver{}
Expand Down Expand Up @@ -268,6 +270,11 @@ func newConnector(d *Driver, dsn string) (*connector, error) {
config.DisableRouteToLeader = val
}
}
if strval, ok := connectorConfig.params["enableendtoendtracing"]; ok {
if val, err := strconv.ParseBool(strval); err == nil {
config.EnableEndToEndTracing = val
}
}
config.UserAgent = userAgent

c := &connector{
Expand Down Expand Up @@ -1143,8 +1150,8 @@ var valuerReflectType = reflect.TypeOf((*driver.Valuer)(nil)).Elem()
// to those types to mean nil/NULL, just like the Go database/sql package.
func callValuerValue(vr driver.Valuer) (v driver.Value, err error) {
if rv := reflect.ValueOf(vr); rv.Kind() == reflect.Ptr &&
rv.IsNil() &&
rv.Type().Elem().Implements(valuerReflectType) {
rv.IsNil() &&
rv.Type().Elem().Implements(valuerReflectType) {
return nil, nil
}
return vr.Value()
Expand Down
18 changes: 10 additions & 8 deletions driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func TestExtractDnsParts(t *testing.T) {
},
},
{
input: "spanner.googleapis.com/projects/p/instances/i/databases/d?minSessions=200;maxSessions=1000;numChannels=10;disableRouteToLeader=true;rpcPriority=Medium;optimizerVersion=1;optimizerStatisticsPackage=latest;databaseRole=child",
input: "spanner.googleapis.com/projects/p/instances/i/databases/d?minSessions=200;maxSessions=1000;numChannels=10;disableRouteToLeader=true;enableEndToEndTracing=true;rpcPriority=Medium;optimizerVersion=1;optimizerStatisticsPackage=latest;databaseRole=child",
wantConnectorConfig: connectorConfig{
host: "spanner.googleapis.com",
project: "p",
Expand All @@ -165,6 +165,7 @@ func TestExtractDnsParts(t *testing.T) {
"maxsessions": "1000",
"numchannels": "10",
"disableroutetoleader": "true",
"enableendtoendtracing": "true",
"rpcpriority": "Medium",
"optimizerversion": "1",
"optimizerstatisticspackage": "latest",
Expand All @@ -183,13 +184,14 @@ func TestExtractDnsParts(t *testing.T) {
TrackSessionHandles: spanner.DefaultSessionPoolConfig.TrackSessionHandles,
InactiveTransactionRemovalOptions: spanner.DefaultSessionPoolConfig.InactiveTransactionRemovalOptions,
},
NumChannels: 10,
UserAgent: userAgent,
DisableRouteToLeader: true,
QueryOptions: spanner.QueryOptions{Priority: spannerpb.RequestOptions_PRIORITY_MEDIUM, Options: &spannerpb.ExecuteSqlRequest_QueryOptions{OptimizerVersion: "1", OptimizerStatisticsPackage: "latest"}},
ReadOptions: spanner.ReadOptions{Priority: spannerpb.RequestOptions_PRIORITY_MEDIUM},
TransactionOptions: spanner.TransactionOptions{CommitPriority: spannerpb.RequestOptions_PRIORITY_MEDIUM},
DatabaseRole: "child",
NumChannels: 10,
UserAgent: userAgent,
DisableRouteToLeader: true,
EnableEndToEndTracing: true,
QueryOptions: spanner.QueryOptions{Priority: spannerpb.RequestOptions_PRIORITY_MEDIUM, Options: &spannerpb.ExecuteSqlRequest_QueryOptions{OptimizerVersion: "1", OptimizerStatisticsPackage: "latest"}},
ReadOptions: spanner.ReadOptions{Priority: spannerpb.RequestOptions_PRIORITY_MEDIUM},
TransactionOptions: spanner.TransactionOptions{CommitPriority: spannerpb.RequestOptions_PRIORITY_MEDIUM},
DatabaseRole: "child",
},
},
{
Expand Down
Loading