Skip to content

Commit

Permalink
Merge pull request #228 from dkropachev/dk/change-driver-name
Browse files Browse the repository at this point in the history
Expose driver name/version configuration on cluster config level and change default driver name
  • Loading branch information
dkropachev authored Aug 7, 2024
2 parents 7656329 + 79a6c18 commit 009034a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
12 changes: 12 additions & 0 deletions cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"time"
)

const defaultDriverName = "ScyllaDB GoCQL Driver"

// PoolConfig configures the connection pool used by the driver, it defaults to
// using a round-robin host selection policy and a round-robin connection selection
// policy for each host.
Expand Down Expand Up @@ -145,6 +147,14 @@ type ClusterConfig struct {
// Default: true, only enabled for protocol 3 and above.
DefaultTimestamp bool

// The name of the driver that is going to be reported to the server.
// Default: "ScyllaDB GoLang Driver"
DriverName string

// The version of the driver that is going to be reported to the server.
// Defaulted to current library version
DriverVersion string

// PoolConfig configures the underlying connection pool, allowing the
// configuration of host selection and connection selection policies.
PoolConfig PoolConfig
Expand Down Expand Up @@ -289,6 +299,8 @@ func NewCluster(hosts ...string) *ClusterConfig {
MaxRoutingKeyInfo: 1000,
PageSize: 5000,
DefaultTimestamp: true,
DriverName: defaultDriverName,
DriverVersion: defaultDriverVersion,
MaxWaitSchemaAgreement: 60 * time.Second,
ReconnectInterval: 60 * time.Second,
ConvictionPolicy: &SimpleConvictionPolicy{},
Expand Down
4 changes: 2 additions & 2 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,8 @@ func (s *startupCoordinator) options(ctx context.Context) error {
func (s *startupCoordinator) startup(ctx context.Context) error {
m := map[string]string{
"CQL_VERSION": s.conn.cfg.CQLVersion,
"DRIVER_NAME": driverName,
"DRIVER_VERSION": driverVersion,
"DRIVER_NAME": s.conn.session.cfg.DriverName,
"DRIVER_VERSION": s.conn.session.cfg.DriverVersion,
}

if s.conn.compressor != nil {
Expand Down
10 changes: 3 additions & 7 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@ const (
mainModule = "github.com/gocql/gocql"
)

var driverName string

var driverVersion string
var defaultDriverVersion string

func init() {
buildInfo, ok := debug.ReadBuildInfo()
if ok {
for _, d := range buildInfo.Deps {
if d.Path == mainModule {
driverName = mainModule
driverVersion = d.Version
defaultDriverVersion = d.Version
if d.Replace != nil {
driverName = d.Replace.Path
driverVersion = d.Replace.Version
defaultDriverVersion = d.Replace.Version
}
break
}
Expand Down

0 comments on commit 009034a

Please sign in to comment.