@@ -31,15 +31,14 @@ type MetricsBackend struct {
31
31
}
32
32
33
33
func (m * MetricsBackend ) IncrementCounter (ctx context.Context , mt taskqueue.Metric , count int , ts time.Time ) error {
34
- roundedTs := ts .Truncate (truncateDur )
35
- roundedTsStr := roundedTs .Format (time .RFC3339 )
34
+ roundedTs := ts .Truncate (truncateDur ).Unix ()
36
35
37
36
hashKey := redisHashKeyCounterMetrics (m .namespace , mt .Name , mt .Labels )
38
37
zsetKey := redisZSetKeyCounterMetrics (m .namespace , mt .Name , mt .Labels )
39
38
40
39
_ , err := m .client .TxPipelined (ctx , func (pipe redis.Pipeliner ) error {
41
- pipe .HIncrBy (ctx , hashKey , roundedTsStr , int64 (count ))
42
- pipe .ZAdd (ctx , zsetKey , redis.Z {Score : float64 (roundedTs . Unix ()) , Member : roundedTsStr })
40
+ pipe .HIncrBy (ctx , hashKey , strconv . FormatInt ( roundedTs , 10 ) , int64 (count ))
41
+ pipe .ZAdd (ctx , zsetKey , redis.Z {Score : float64 (roundedTs ) , Member : roundedTs })
43
42
return nil
44
43
})
45
44
@@ -62,20 +61,31 @@ func (m *MetricsBackend) QueryRangeCounterValues(ctx context.Context, mt taskque
62
61
63
62
result := taskqueue.MetricRangeValue {Metric : mt }
64
63
65
- for _ , z := range zz {
64
+ timestamps := make ([]string , len (zz ))
65
+ for i , z := range zz {
66
66
member , _ := z .Member .(string )
67
- if member == "" {
67
+ timestamps [i ] = member
68
+ }
69
+
70
+ vals , err := m .client .HMGet (ctx , hashKey , timestamps ... ).Result ()
71
+ if err != nil {
72
+ return taskqueue.MetricRangeValue {}, err
73
+ }
74
+
75
+ for i , val := range vals {
76
+ strVal , ok := val .(string )
77
+ if ! ok {
68
78
continue
69
79
}
70
80
71
- val , err := m . client . HGet ( ctx , hashKey , member ). Int ( )
81
+ v , err := strconv . Atoi ( strVal )
72
82
if err != nil {
73
83
continue
74
84
}
75
85
76
86
result .Values = append (result .Values , taskqueue.MetricValue {
77
- TimeStamp : time .Unix (int64 (z .Score ), 0 ),
78
- Value : float64 (val ),
87
+ TimeStamp : time .Unix (int64 (zz [ i ] .Score ), 0 ),
88
+ Value : float64 (v ),
79
89
})
80
90
}
81
91
0 commit comments