Skip to content

Commit 8a6720e

Browse files
committed
adds client type on kvrocks_command_seconds
1 parent db98659 commit 8a6720e

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

cmd/reader/client.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@ type Client interface {
2424

2525
// Close closes the client connection
2626
Close()
27-
}
2827

28+
Name() string
29+
}

cmd/reader/main.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ func intToAlphabetKey(n int64) string {
3939
return string(result)
4040
}
4141

42-
var (
43-
hGetAllSeconds = metrics.GetOrCreateHistogram(`kvrocks_command_seconds{command="hgetall"}`)
44-
hGetAllErrorsTotal = metrics.GetOrCreateCounter(`kvrocks_command_errors_total{command="hgetall"}`)
45-
)
46-
4742
func main() {
4843
logger.InitLogger(true)
4944
logger.InitNewLogger(true)
@@ -200,11 +195,12 @@ func hGetAll(
200195
timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
201196
defer cancel()
202197
start := time.Now()
198+
hGetAllSeconds := metrics.GetOrCreateHistogram(fmt.Sprintf(`kvrocks_command_seconds{command="hgetall",client="%s"}`, client.Name()))
203199
defer hGetAllSeconds.UpdateDuration(start)
204200

205201
data, err := client.HGetAll(timeoutCtx, key)
206202
if err != nil {
207-
hGetAllErrorsTotal.Inc()
203+
metrics.GetOrCreateCounter(fmt.Sprintf(`kvrocks_command_errors_total{command="hgetall",client="%s"}`, client.Name())).Inc()
208204
return nil, err
209205
}
210206

cmd/reader/reader

90.9 KB
Binary file not shown.

cmd/reader/redis.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ func NewRedisClient(addrs []string, writeTimeout, readTimeout, dialTimeout time.
2323
}
2424
}
2525

26+
func (r *RedisClient) Name() string {
27+
return "redis"
28+
}
29+
2630
func (r *RedisClient) Hmget(ctx context.Context, key string, fields ...string) ([]interface{}, error) {
2731
result, err := r.clusterClient.HMGet(ctx, key, fields...).Result()
2832
return result, err

cmd/reader/rueidis.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ type RueidisClient struct {
1313
client rueidis.Client
1414
}
1515

16+
func (r *RueidisClient) Name() string {
17+
return "rueidis"
18+
}
19+
1620
func NewRueidisClient(options rueidis.ClientOption) (*RueidisClient, error) {
1721
client, err := rueidis.NewClient(options)
1822
if err != nil {
@@ -87,4 +91,3 @@ func (r *RueidisClient) HSetExpire(ctx context.Context, key string, cols []strin
8791
func (r *RueidisClient) Close() {
8892
r.client.Close()
8993
}
90-

0 commit comments

Comments
 (0)