Skip to content

Commit

Permalink
Fix redis plugin cannot work in cluster mode (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrproliu authored Sep 5, 2024
1 parent 4db6e41 commit 3ac7e9a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 51 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Release Notes.

#### Bug Fixes
* Fix wrong docker image name and `-version` command.
* Fix redis plugin cannot work in cluster mode.

#### Issues and PR
- All issues are [here](https://github.com/apache/skywalking/milestone/219?closed=1)
Expand Down
109 changes: 58 additions & 51 deletions plugins/go-redisv9/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,39 @@ func (r *redisHook) DialHook(next redis.DialHook) redis.DialHook {

func (r *redisHook) ProcessHook(next redis.ProcessHook) redis.ProcessHook {
return func(ctx context.Context, cmd redis.Cmder) error {
s, err := tracing.CreateExitSpan(
// operationName
GoRedisCacheType+"/"+cmd.FullName(),

// peer
r.Addr,

// injector
func(k, v string) error {
return nil
},

// opts
tracing.WithComponent(GoRedisComponentID),
tracing.WithLayer(tracing.SpanLayerCache),
tracing.WithTag(tracing.TagCacheType, GoRedisCacheType),
tracing.WithTag(tracing.TagCacheOp, getCacheOp(cmd.FullName())),
tracing.WithTag(tracing.TagCacheCmd, cmd.FullName()),
tracing.WithTag(tracing.TagCacheKey, getKey(cmd.Args())),
tracing.WithTag(tracing.TagCacheArgs, maxString(cmd.String(), config.MaxArgsBytes)),
)

if err != nil {
err = fmt.Errorf("go-redis :skyWalking failed to create exit span, got error: %v", err)
return err
var s tracing.Span
var err error
if r.Addr != "" {
s, err = tracing.CreateExitSpan(
// operationName
GoRedisCacheType+"/"+cmd.FullName(),

// peer
r.Addr,

// injector
func(k, v string) error {
return nil
},

// opts
tracing.WithComponent(GoRedisComponentID),
tracing.WithLayer(tracing.SpanLayerCache),
tracing.WithTag(tracing.TagCacheType, GoRedisCacheType),
tracing.WithTag(tracing.TagCacheOp, getCacheOp(cmd.FullName())),
tracing.WithTag(tracing.TagCacheCmd, cmd.FullName()),
tracing.WithTag(tracing.TagCacheKey, getKey(cmd.Args())),
tracing.WithTag(tracing.TagCacheArgs, maxString(cmd.String(), config.MaxArgsBytes)),
)

if err != nil {
err = fmt.Errorf("go-redis :skyWalking failed to create exit span, got error: %v", err)
return err
}

defer s.End()
}

defer s.End()

if err = next(ctx, cmd); err != nil {
recordError(s, err)
return err
Expand All @@ -132,31 +136,34 @@ func (r *redisHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.Pr
summary += "..."
}

s, err := tracing.CreateExitSpan(
// operationName
"redis/pipeline",

// peer
r.Addr,

// injector
func(k, v string) error {
return nil
},

// opts
tracing.WithComponent(GoRedisComponentID),
tracing.WithLayer(tracing.SpanLayerCache),
tracing.WithTag(tracing.TagCacheType, GoRedisCacheType),
tracing.WithTag(tracing.TagCacheCmd, "pipeline:"+strings.TrimRight(summary, "/")),
)
if err != nil {
err = fmt.Errorf("go-redis :skyWalking failed to create exit span, got error: %v", err)
return err
var s tracing.Span
var err error
if r.Addr != "" {
s, err = tracing.CreateExitSpan(
// operationName
"redis/pipeline",

// peer
r.Addr,

// injector
func(k, v string) error {
return nil
},

// opts
tracing.WithComponent(GoRedisComponentID),
tracing.WithLayer(tracing.SpanLayerCache),
tracing.WithTag(tracing.TagCacheType, GoRedisCacheType),
tracing.WithTag(tracing.TagCacheCmd, "pipeline:"+strings.TrimRight(summary, "/")),
)
if err != nil {
err = fmt.Errorf("go-redis :skyWalking failed to create exit span, got error: %v", err)
return err
}
defer s.End()
}

defer s.End()

if err = next(ctx, cmds); err != nil {
recordError(s, err)
return err
Expand All @@ -167,7 +174,7 @@ func (r *redisHook) ProcessPipelineHook(next redis.ProcessPipelineHook) redis.Pr
}

func recordError(span tracing.Span, err error) {
if err != redis.Nil {
if err != redis.Nil && span != nil {
span.Error(err.Error())
}
}
Expand Down

0 comments on commit 3ac7e9a

Please sign in to comment.