@@ -24,11 +24,14 @@ import (
24
24
"context"
25
25
"sync"
26
26
27
+ "github.com/rs/zerolog"
28
+
27
29
"github.com/arangodb/go-driver"
28
30
"github.com/arangodb/go-driver/agency"
29
31
30
32
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
31
33
"github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions"
34
+ "github.com/arangodb/kube-arangodb/pkg/logging"
32
35
"github.com/arangodb/kube-arangodb/pkg/util/errors"
33
36
"github.com/arangodb/kube-arangodb/pkg/util/globals"
34
37
"github.com/arangodb/kube-arangodb/pkg/util/metrics"
@@ -164,10 +167,14 @@ func NewCache(namespace, name string, mode *api.DeploymentMode) Cache {
164
167
}
165
168
166
169
func NewAgencyCache (namespace , name string ) Cache {
167
- return & cache {
170
+ c := & cache {
168
171
namespace : namespace ,
169
172
name : name ,
170
173
}
174
+
175
+ c .log = logger .WrapObj (c )
176
+
177
+ return c
171
178
}
172
179
173
180
func NewSingleCache () Cache {
@@ -197,6 +204,8 @@ func (c cacheSingle) Data() (State, bool) {
197
204
type cache struct {
198
205
namespace , name string
199
206
207
+ log logging.Logger
208
+
200
209
lock sync.RWMutex
201
210
202
211
valid bool
@@ -208,6 +217,10 @@ type cache struct {
208
217
health Health
209
218
}
210
219
220
+ func (c * cache ) WrapLogger (in * zerolog.Event ) * zerolog.Event {
221
+ return in .Str ("namespace" , c .namespace ).Str ("name" , c .name )
222
+ }
223
+
211
224
func (c * cache ) CommitIndex () uint64 {
212
225
c .lock .RLock ()
213
226
defer c .lock .RUnlock ()
@@ -238,7 +251,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
238
251
c .lock .Lock ()
239
252
defer c .lock .Unlock ()
240
253
241
- leaderCli , leaderConfig , health , err := getLeader (ctx , size , clients )
254
+ leaderCli , leaderConfig , health , err := c . getLeader (ctx , size , clients )
242
255
if err != nil {
243
256
// Invalidate a leader ID and agency state.
244
257
// In the next iteration leaderID will be sat because `valid` will be false.
@@ -258,7 +271,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
258
271
}
259
272
260
273
// A leader should be known even if an agency state is invalid.
261
- if data , err := loadState (ctx , leaderCli ); err != nil {
274
+ if data , err := c . loadState (ctx , leaderCli ); err != nil {
262
275
c .valid = false
263
276
return leaderConfig .CommitIndex , err
264
277
} else {
@@ -271,7 +284,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
271
284
272
285
// getLeader returns config and client to a leader agency, and health to check if agencies are on the same page.
273
286
// If there is no quorum for the leader then error is returned.
274
- func getLeader (ctx context.Context , size int , clients map [string ]agency.Agency ) (agency.Agency , * Config , health , error ) {
287
+ func ( c * cache ) getLeader (ctx context.Context , size int , clients map [string ]agency.Agency ) (agency.Agency , * Config , health , error ) {
275
288
configs := make ([]* Config , len (clients ))
276
289
errs := make ([]error , len (clients ))
277
290
names := make ([]string , 0 , len (clients ))
@@ -324,11 +337,11 @@ func getLeader(ctx context.Context, size int, clients map[string]agency.Agency)
324
337
}
325
338
}
326
339
if err := h .Serving (); err != nil {
327
- logger .Err (err ).Warn ("Agency Not serving" )
340
+ c . log .Err (err ).Warn ("Agency Not serving" )
328
341
return nil , nil , h , err
329
342
}
330
343
if err := h .Healthy (); err != nil {
331
- logger . Err (err ).Warn ("Agency Not healthy" )
344
+ c . log . Err (err ).Debug ("Agency Not healthy" )
332
345
}
333
346
334
347
for id := range names {
0 commit comments