Identify client on connect (#2708)

* Update CLIENT-SETINFO to support suffixes

* Update CLIENT-SETINFO

* fix acl log test

* add setinfo option to cluster

* change to DisableIndentity

* change to DisableIndentity
This commit is contained in:
ofekshenawa 2023-09-20 10:33:09 +03:00 committed by GitHub
parent 54a106ee19
commit 0b6be62b71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 14 deletions

View File

@ -30,6 +30,7 @@ func NewClientStub(resp []byte) *ClientStub {
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
return stub.stubConn(initHello), nil
},
DisableIndentity: true,
})
return stub
}
@ -45,6 +46,8 @@ func NewClusterClientStub(resp []byte) *ClientStub {
Dialer: func(ctx context.Context, network, addr string) (net.Conn, error) {
return stub.stubConn(initHello), nil
},
DisableIndentity: true,
ClusterSlots: func(_ context.Context) ([]ClusterSlot, error) {
return []ClusterSlot{
{

View File

@ -84,6 +84,7 @@ type ClusterOptions struct {
ConnMaxLifetime time.Duration
TLSConfig *tls.Config
DisableIndentity bool // Disable set-lib on connect. Default is false.
}
func (opt *ClusterOptions) init() {
@ -284,7 +285,7 @@ func (opt *ClusterOptions) clientOptions() *Options {
MaxIdleConns: opt.MaxIdleConns,
ConnMaxIdleTime: opt.ConnMaxIdleTime,
ConnMaxLifetime: opt.ConnMaxLifetime,
DisableIndentity: opt.DisableIndentity,
TLSConfig: opt.TLSConfig,
// If ClusterSlots is populated, then we probably have an artificial
// cluster whose nodes are not in clustering mode (otherwise there isn't

View File

@ -4,9 +4,11 @@ import (
"context"
"encoding"
"errors"
"fmt"
"io"
"net"
"reflect"
"runtime"
"strings"
"time"
@ -584,7 +586,8 @@ func (c statefulCmdable) ClientSetInfo(ctx context.Context, info LibraryInfo) *S
var cmd *StatusCmd
if info.LibName != nil {
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-NAME", *info.LibName)
libName := fmt.Sprintf("go-redis(%s,%s)", *info.LibName, runtime.Version())
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-NAME", libName)
} else {
cmd = NewStatusCmd(ctx, "client", "setinfo", "LIB-VER", *info.LibVer)
}

View File

@ -2052,10 +2052,9 @@ var _ = Describe("Commands", func() {
logEntries, err := client.ACLLog(ctx, 10).Result()
Expect(err).NotTo(HaveOccurred())
Expect(len(logEntries)).To(Equal(3))
Expect(len(logEntries)).To(Equal(4))
for _, entry := range logEntries {
Expect(entry.Count).To(BeNumerically("==", 1))
Expect(entry.Reason).To(Equal("command"))
Expect(entry.Context).To(Equal("toplevel"))
Expect(entry.Object).NotTo(BeEmpty())

View File

@ -136,6 +136,9 @@ type Options struct {
// Enables read only queries on slave/follower nodes.
readOnly bool
// // Disable set-lib on connect. Default is false.
DisableIndentity bool
}
func (opt *Options) init() {

View File

@ -299,7 +299,14 @@ func (c *baseClient) initConn(ctx context.Context, cn *pool.Conn) error {
// difficult to rely on error strings to determine all results.
return err
}
if !c.opt.DisableIndentity {
libName := ""
libVer := Version()
libInfo := LibraryInfo{LibName: &libName}
conn.ClientSetInfo(ctx, libInfo)
libInfo = LibraryInfo{LibVer: &libVer}
conn.ClientSetInfo(ctx, libInfo)
}
_, err := conn.Pipelined(ctx, func(pipe Pipeliner) error {
if !auth && password != "" {
if username != "" {