5
5
"io"
6
6
"strings"
7
7
8
- "github.com/gomodule/redigo/redis"
9
8
"github.com/prometheus/client_golang/prometheus"
10
9
dto "github.com/prometheus/client_model/go"
11
10
"github.com/prometheus/common/expfmt"
@@ -20,16 +19,6 @@ type Store interface {
20
19
prometheus.Gatherer
21
20
}
22
21
23
- func NewDefaultStore () Store {
24
- return & defaultStore {}
25
- }
26
-
27
- type defaultStore struct {}
28
-
29
- func (* defaultStore ) Gather () ([]* dto.MetricFamily , error ) {
30
- return prometheus .DefaultGatherer .Gather ()
31
- }
32
-
33
22
type DistributedStore interface {
34
23
Store
35
24
Ingest (instance string , mfs []* dto.MetricFamily ) error
@@ -48,13 +37,10 @@ type distributedStore struct {
48
37
}
49
38
50
39
func (d * distributedStore ) Gather () ([]* dto.MetricFamily , error ) {
51
- pool := redispool .Cache .Pool ()
52
-
53
- reConn := pool .Get ()
54
- defer reConn .Close ()
40
+ cache := redispool .Cache
55
41
56
42
// First, list all the keys for which we hold metrics.
57
- keys , err := redis . Values ( reConn . Do ( "KEYS" , d .prefix + "*" ) )
43
+ keys , err := cache . Keys ( d .prefix + "*" )
58
44
if err != nil {
59
45
return nil , errors .Wrap (err , "listing entries from redis" )
60
46
}
@@ -64,7 +50,7 @@ func (d *distributedStore) Gather() ([]*dto.MetricFamily, error) {
64
50
}
65
51
66
52
// Then bulk retrieve all the metrics blobs for all the instances.
67
- encodedMetrics , err := redis . Strings ( reConn . Do ( "MGET" , keys ... ) )
53
+ encodedMetrics , err := cache . MGet ( keys ). Strings ( )
68
54
if err != nil {
69
55
return nil , errors .Wrap (err , "retrieving blobs from redis" )
70
56
}
@@ -92,7 +78,7 @@ func (d *distributedStore) Gather() ([]*dto.MetricFamily, error) {
92
78
}
93
79
94
80
func (d * distributedStore ) Ingest (instance string , mfs []* dto.MetricFamily ) error {
95
- pool := redispool .Cache . Pool ()
81
+ cache := redispool .Cache
96
82
97
83
// First, encode the metrics to text format so we can store them.
98
84
var enc bytes.Buffer
@@ -106,13 +92,10 @@ func (d *distributedStore) Ingest(instance string, mfs []*dto.MetricFamily) erro
106
92
107
93
encodedMetrics := enc .String ()
108
94
109
- reConn := pool .Get ()
110
- defer reConn .Close ()
111
-
112
95
// Store the metrics and set an expiry on the key, if we haven't retrieved
113
96
// an updated set of metric data, we consider the host down and prune it
114
97
// from the gatherer.
115
- err := reConn . Send ( "SETEX" , d .prefix + instance , d .expiry , encodedMetrics )
98
+ err := cache . SetEx ( d .prefix + instance , d .expiry , encodedMetrics )
116
99
if err != nil {
117
100
return errors .Wrap (err , "writing metrics blob to redis" )
118
101
}
0 commit comments