[VOL-2310] Logging - Implement dynamic log levels in OpenOLT adapter
Working on Logging design changes.
Change-Id: I99a8ab22eb291332bf6528c8912fcbf16873232f
diff --git a/pkg/db/backend.go b/pkg/db/backend.go
index 96829c5..04fe35d 100644
--- a/pkg/db/backend.go
+++ b/pkg/db/backend.go
@@ -247,14 +247,14 @@
}
// CreateWatch starts watching events for the specified key
-func (b *Backend) CreateWatch(ctx context.Context, key string) chan *kvstore.Event {
+func (b *Backend) CreateWatch(ctx context.Context, key string, withPrefix bool) chan *kvstore.Event {
b.Lock()
defer b.Unlock()
formattedPath := b.makePath(key)
logger.Debugw("creating-key-watch", log.Fields{"key": key, "path": formattedPath})
- return b.Client.Watch(ctx, formattedPath)
+ return b.Client.Watch(ctx, formattedPath, withPrefix)
}
// DeleteWatch stops watching events for the specified key
diff --git a/pkg/db/backend_test.go b/pkg/db/backend_test.go
index ac1d0df..8a7e07f 100644
--- a/pkg/db/backend_test.go
+++ b/pkg/db/backend_test.go
@@ -398,7 +398,7 @@
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
backend := provisionBackendWithEmbeddedEtcdServer(t)
- eventChan := backend.CreateWatch(ctx, "key5")
+ eventChan := backend.CreateWatch(ctx, "key5", false)
assert.NotNil(t, eventChan)
assert.Equal(t, 0, len(eventChan))
diff --git a/pkg/db/kvstore/client.go b/pkg/db/kvstore/client.go
index d30e049..b9cb1ee 100644
--- a/pkg/db/kvstore/client.go
+++ b/pkg/db/kvstore/client.go
@@ -81,7 +81,7 @@
ReleaseReservation(ctx context.Context, key string) error
ReleaseAllReservations(ctx context.Context) error
RenewReservation(ctx context.Context, key string) error
- Watch(ctx context.Context, key string) chan *Event
+ Watch(ctx context.Context, key string, withPrefix bool) chan *Event
AcquireLock(ctx context.Context, lockName string, timeout int) error
ReleaseLock(lockName string) error
IsConnectionUp(ctx context.Context) bool // timeout in second
diff --git a/pkg/db/kvstore/consulclient.go b/pkg/db/kvstore/consulclient.go
index fdf39be..bdf2d10 100644
--- a/pkg/db/kvstore/consulclient.go
+++ b/pkg/db/kvstore/consulclient.go
@@ -360,7 +360,7 @@
// Watch provides the watch capability on a given key. It returns a channel onto which the callee needs to
// listen to receive Events.
-func (c *ConsulClient) Watch(ctx context.Context, key string) chan *Event {
+func (c *ConsulClient) Watch(ctx context.Context, key string, withPrefix bool) chan *Event {
// Create a new channel
ch := make(chan *Event, maxClientChannelBufferSize)
diff --git a/pkg/db/kvstore/etcdclient.go b/pkg/db/kvstore/etcdclient.go
index 2d126f7..1014ada 100644
--- a/pkg/db/kvstore/etcdclient.go
+++ b/pkg/db/kvstore/etcdclient.go
@@ -298,10 +298,15 @@
// Watch provides the watch capability on a given key. It returns a channel onto which the callee needs to
// listen to receive Events.
-func (c *EtcdClient) Watch(ctx context.Context, key string) chan *Event {
+func (c *EtcdClient) Watch(ctx context.Context, key string, withPrefix bool) chan *Event {
w := v3Client.NewWatcher(c.ectdAPI)
ctx, cancel := context.WithCancel(ctx)
- channel := w.Watch(ctx, key)
+ var channel v3Client.WatchChan
+ if withPrefix {
+ channel = w.Watch(ctx, key, v3Client.WithPrefix())
+ } else {
+ channel = w.Watch(ctx, key)
+ }
// Create a new channel
ch := make(chan *Event, maxClientChannelBufferSize)