Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: redis error for prometheus metric label #2412

Merged
merged 1 commit into from Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 13 additions & 17 deletions core/stores/redis/hook.go
Expand Up @@ -2,10 +2,13 @@ package redis

import (
"context"
"io"
"net"
"strings"
"time"

red "github.com/go-redis/redis/v8"
"github.com/zeromicro/go-zero/core/breaker"
"github.com/zeromicro/go-zero/core/errorx"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/mapping"
Expand Down Expand Up @@ -116,24 +119,17 @@ func formatError(err error) string {
return ""
}

es := err.Error()
switch {
case strings.HasPrefix(es, "read"):
return "read timeout"
case strings.HasPrefix(es, "dial"):
if strings.Contains(es, "connection refused") {
return "connection refused"
}
return "dial timeout"
case strings.HasPrefix(es, "write"):
return "write timeout"
case strings.Contains(es, "EOF"):
opErr, ok := err.(*net.OpError)
if ok && opErr.Timeout() {
return "timeout"
}

switch err {
case io.EOF:
return "eof"
case strings.Contains(es, "reset"):
return "reset"
case strings.Contains(es, "broken"):
return "broken pipe"
case strings.Contains(es, "breaker"):
case context.DeadlineExceeded:
return "context deadline"
case breaker.ErrServiceUnavailable:
return "breaker"
default:
return "unexpected error"
Expand Down