From 4db223389aa4ed6ba04d6e203e90239995b09f8f Mon Sep 17 00:00:00 2001 From: tellet-q Date: Mon, 16 Dec 2024 12:56:45 +0100 Subject: [PATCH 1/3] Send client version in user-agent --- qdrant/grpc_client.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/qdrant/grpc_client.go b/qdrant/grpc_client.go index f38dc6c..be378c5 100644 --- a/qdrant/grpc_client.go +++ b/qdrant/grpc_client.go @@ -1,6 +1,10 @@ package qdrant import ( + "fmt" + "os/exec" + "strings" + "google.golang.org/grpc" ) @@ -35,6 +39,12 @@ func NewGrpcClient(config *Config) (*GrpcClient, error) { config.getAPIKeyInterceptor(), }, config.GrpcOptions...) + clientVersion, err := getClientVersion() + if err != nil { + return nil, fmt.Errorf("failed to get client version: %w", err) + } + config.GrpcOptions = append(config.GrpcOptions, grpc.WithUserAgent(fmt.Sprintf("go-client/%s", clientVersion))) + conn, err := grpc.NewClient(config.getAddr(), config.GrpcOptions...) if err != nil { @@ -84,3 +94,13 @@ func (c *GrpcClient) Snapshots() SnapshotsClient { func (c *GrpcClient) Close() error { return c.conn.Close() } + +func getClientVersion() (string, error) { + packageName := "github.com/qdrant/go-client" + cmd := exec.Command("go", "list", "-m", "-f", "{{.Version}}", packageName) + output, err := cmd.Output() + if err != nil { + return "", err + } + return strings.TrimSpace(string(output)), nil +} From 3f99bdd79d2bb5ed35f928842511778a6b14abe9 Mon Sep 17 00:00:00 2001 From: tellet-q Date: Mon, 16 Dec 2024 16:13:44 +0100 Subject: [PATCH 2/3] Address review --- qdrant/grpc_client.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/qdrant/grpc_client.go b/qdrant/grpc_client.go index be378c5..95dfaad 100644 --- a/qdrant/grpc_client.go +++ b/qdrant/grpc_client.go @@ -34,16 +34,15 @@ func NewDefaultGrpcClient() (*GrpcClient, error) { func NewGrpcClient(config *Config) (*GrpcClient, error) { // We append config.GrpcOptions in the end // so that user's explicit options take precedence - config.GrpcOptions = append([]grpc.DialOption{ - config.getTransportCreds(), - config.getAPIKeyInterceptor(), - }, config.GrpcOptions...) - clientVersion, err := getClientVersion() if err != nil { return nil, fmt.Errorf("failed to get client version: %w", err) } - config.GrpcOptions = append(config.GrpcOptions, grpc.WithUserAgent(fmt.Sprintf("go-client/%s", clientVersion))) + config.GrpcOptions = append([]grpc.DialOption{ + config.getTransportCreds(), + config.getAPIKeyInterceptor(), + grpc.WithUserAgent(fmt.Sprintf("go-client/%s", clientVersion)), + }, config.GrpcOptions...) conn, err := grpc.NewClient(config.getAddr(), config.GrpcOptions...) From ff1a4da30031fb8244f13b0fd4407654100a0c49 Mon Sep 17 00:00:00 2001 From: tellet-q Date: Tue, 17 Dec 2024 08:26:02 +0100 Subject: [PATCH 3/3] Do not throw error --- qdrant/grpc_client.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/qdrant/grpc_client.go b/qdrant/grpc_client.go index 95dfaad..2b42a9b 100644 --- a/qdrant/grpc_client.go +++ b/qdrant/grpc_client.go @@ -34,10 +34,7 @@ func NewDefaultGrpcClient() (*GrpcClient, error) { func NewGrpcClient(config *Config) (*GrpcClient, error) { // We append config.GrpcOptions in the end // so that user's explicit options take precedence - clientVersion, err := getClientVersion() - if err != nil { - return nil, fmt.Errorf("failed to get client version: %w", err) - } + clientVersion := getClientVersion() config.GrpcOptions = append([]grpc.DialOption{ config.getTransportCreds(), config.getAPIKeyInterceptor(), @@ -94,12 +91,12 @@ func (c *GrpcClient) Close() error { return c.conn.Close() } -func getClientVersion() (string, error) { +func getClientVersion() string { packageName := "github.com/qdrant/go-client" cmd := exec.Command("go", "list", "-m", "-f", "{{.Version}}", packageName) output, err := cmd.Output() if err != nil { - return "", err + return "Unknown" } - return strings.TrimSpace(string(output)), nil + return strings.TrimSpace(string(output)) }