hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.24k stars 4.41k forks source link

How to get the specific key modified through consul watch keyprefix. #8687

Open xiwangqi opened 4 years ago

xiwangqi commented 4 years ago

KV: key: configs/v1/test/test1 value: 111 key: configs/v1/test/test2 value: 222

script:

!/usr/bin/env sh

while read line do echo "line: "$line done

command: consul watch -type keyprefix -prefix configs/v1/test /home/superman/consul-watch-test.sh

RUN result: line: [{"Key":"configs/v1/test/","CreateIndex":3133811,"ModifyIndex":3133811,"LockIndex":0,"Flags":0,"Value":null,"Session":""},{"Key":"configs/v1/test/test1","CreateIndex":3133815,"ModifyIndex":3133815,"LockIndex":0,"Flags":0,"Value":"MTEx","Session":""},{"Key":"configs/v1/test/test2","CreateIndex":3133817,"ModifyIndex":3133817,"LockIndex":0,"Flags":0,"Value":"MjIyMnNk","Session":""}]

If I only modify the values of test2, it still returns all: line: [{"Key":"configs/v1/test/","CreateIndex":3133811,"ModifyIndex":3133811,"LockIndex":0,"Flags":0,"Value":null,"Session":""},{"Key":"configs/v1/test/test1","CreateIndex":3133815,"ModifyIndex":3133815,"LockIndex":0,"Flags":0,"Value":"MTEx","Session":""},{"Key":"configs/v1/test/test2","CreateIndex":3133817,"ModifyIndex":3133826,"LockIndex":0,"Flags":0,"Value":"c2RmYWQ=","Session":""}]

How can I get only the modified value?(Contains: add, modify, delete)

blake commented 4 years ago

Hi @xiwangqi, your request seems to be the same as described in #2791 and should be resolved long term in product by #6366. I don't have a timeline as to when the latter would be available, but it is something we might be able to support in Consul after the streaming foundation ships in Consul 1.9.

At the moment you will need to compare the output from the watch within your script and determine which keys were added, modified, or deleted.