Skip to content

Commit

Permalink
fix(config): watch etcd from last revision (#199)
Browse files Browse the repository at this point in the history
* chore: upgrade go kit to 0.12.0

* chore: upgrade go kit to 0.12.0

* fix: etcd context issue

* fix: keep track of etcd revision
  • Loading branch information
Reasno committed Sep 24, 2021
1 parent 79f94e1 commit 9dac159
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 3 additions & 2 deletions config/remote/etcd/etcd.go
Expand Up @@ -17,6 +17,7 @@ import (
type ETCD struct {
key string
clientConfig clientv3.Config
rev int64
}

// Provider create a *ETCD
Expand Down Expand Up @@ -49,7 +50,7 @@ func (r *ETCD) ReadBytes() ([]byte, error) {
if resp.Count == 0 {
return nil, fmt.Errorf("no such config key: %s", r.key)
}

r.rev = resp.Header.Revision
return resp.Kvs[0].Value, nil
}

Expand All @@ -69,7 +70,7 @@ func (r *ETCD) Watch(ctx context.Context, reload func() error) error {
}
defer client.Close()

rch := client.Watch(ctx, r.key)
rch := client.Watch(ctx, r.key, clientv3.WithRev(r.rev))
for {
select {
case resp := <-rch:
Expand Down
2 changes: 0 additions & 2 deletions config/remote/etcd/etcd_test.go
Expand Up @@ -53,8 +53,6 @@ func TestRemote(t *testing.T) {
return nil
})

time.Sleep(1 * time.Second)

if err := put(r, testVal); err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 9dac159

Please sign in to comment.