@@ -24,11 +24,14 @@ import (
2424 "context"
2525 "sync"
2626
27+ "github.com/rs/zerolog"
28+
2729 "github.com/arangodb/go-driver"
2830 "github.com/arangodb/go-driver/agency"
2931
3032 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3133 "github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions"
34+ "github.com/arangodb/kube-arangodb/pkg/logging"
3235 "github.com/arangodb/kube-arangodb/pkg/util/errors"
3336 "github.com/arangodb/kube-arangodb/pkg/util/globals"
3437 "github.com/arangodb/kube-arangodb/pkg/util/metrics"
@@ -164,10 +167,14 @@ func NewCache(namespace, name string, mode *api.DeploymentMode) Cache {
164167}
165168
166169func NewAgencyCache (namespace , name string ) Cache {
167- return & cache {
170+ c := & cache {
168171 namespace : namespace ,
169172 name : name ,
170173 }
174+
175+ c .log = logger .WrapObj (c )
176+
177+ return c
171178}
172179
173180func NewSingleCache () Cache {
@@ -197,6 +204,8 @@ func (c cacheSingle) Data() (State, bool) {
197204type cache struct {
198205 namespace , name string
199206
207+ log logging.Logger
208+
200209 lock sync.RWMutex
201210
202211 valid bool
@@ -208,6 +217,10 @@ type cache struct {
208217 health Health
209218}
210219
220+ func (c * cache ) WrapLogger (in * zerolog.Event ) * zerolog.Event {
221+ return in .Str ("namespace" , c .namespace ).Str ("name" , c .name )
222+ }
223+
211224func (c * cache ) CommitIndex () uint64 {
212225 c .lock .RLock ()
213226 defer c .lock .RUnlock ()
@@ -238,7 +251,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
238251 c .lock .Lock ()
239252 defer c .lock .Unlock ()
240253
241- leaderCli , leaderConfig , health , err := getLeader (ctx , size , clients )
254+ leaderCli , leaderConfig , health , err := c . getLeader (ctx , size , clients )
242255 if err != nil {
243256 // Invalidate a leader ID and agency state.
244257 // 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.
258271 }
259272
260273 // 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 {
262275 c .valid = false
263276 return leaderConfig .CommitIndex , err
264277 } else {
@@ -271,7 +284,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
271284
272285// getLeader returns config and client to a leader agency, and health to check if agencies are on the same page.
273286// 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 ) {
275288 configs := make ([]* Config , len (clients ))
276289 errs := make ([]error , len (clients ))
277290 names := make ([]string , 0 , len (clients ))
@@ -324,11 +337,11 @@ func getLeader(ctx context.Context, size int, clients map[string]agency.Agency)
324337 }
325338 }
326339 if err := h .Serving (); err != nil {
327- logger .Err (err ).Warn ("Agency Not serving" )
340+ c . log .Err (err ).Warn ("Agency Not serving" )
328341 return nil , nil , h , err
329342 }
330343 if err := h .Healthy (); err != nil {
331- logger . Err (err ).Warn ("Agency Not healthy" )
344+ c . log . Err (err ).Debug ("Agency Not healthy" )
332345 }
333346
334347 for id := range names {
0 commit comments