{"action":"created","issue":{"url":"https://api.github.com/repos/hashicorp/consul/issues/3890","repository_url":"https://api.github.com/repos/hashicorp/consul","labels_url":"https://api.github.com/repos/hashicorp/consul/issues/3890/labels{/name}","comments_url":"https://api.github.com/repos/hashicorp/consul/issues/3890/comments","events_url":"https://api.github.com/repos/hashicorp/consul/issues/3890/events","html_url":"https://github.com/hashicorp/consul/issues/3890","id":297376421,"number":3890,"title":"X-Consul-Index reflects global service churn when watching a single service causing issues with sleeping between blocking calls","user":{"login":"pierresouchay","id":8089033,"avatar_url":"https://avatars3.githubusercontent.com/u/8089033?v=4","gravatar_id":"","url":"https://api.github.com/users/pierresouchay","html_url":"https://github.com/pierresouchay","followers_url":"https://api.github.com/users/pierresouchay/followers","following_url":"https://api.github.com/users/pierresouchay/following{/other_user}","gists_url":"https://api.github.com/users/pierresouchay/gists{/gist_id}","starred_url":"https://api.github.com/users/pierresouchay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pierresouchay/subscriptions","organizations_url":"https://api.github.com/users/pierresouchay/orgs","repos_url":"https://api.github.com/users/pierresouchay/repos","events_url":"https://api.github.com/users/pierresouchay/events{/privacy}","received_events_url":"https://api.github.com/users/pierresouchay/received_events","type":"User","site_admin":false},"labels":[{"id":64219393,"url":"https://api.github.com/repos/hashicorp/consul/labels/enhancement","name":"enhancement","color":"c5def5","default":true}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":{"url":"https://api.github.com/repos/hashicorp/consul/milestones/22","html_url":"https://github.com/hashicorp/consul/milestone/22","labels_url":"https://api.github.com/repos/hashicorp/consul/milestones/22/labels","id":3185626,"number":22,"title":"1.0.7","description":"","creator":{"login":"pearkes","id":846194,"avatar_url":"https://avatars0.githubusercontent.com/u/846194?v=4","gravatar_id":"","url":"https://api.github.com/users/pearkes","html_url":"https://github.com/pearkes","followers_url":"https://api.github.com/users/pearkes/followers","following_url":"https://api.github.com/users/pearkes/following{/other_user}","gists_url":"https://api.github.com/users/pearkes/gists{/gist_id}","starred_url":"https://api.github.com/users/pearkes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pearkes/subscriptions","organizations_url":"https://api.github.com/users/pearkes/orgs","repos_url":"https://api.github.com/users/pearkes/repos","events_url":"https://api.github.com/users/pearkes/events{/privacy}","received_events_url":"https://api.github.com/users/pearkes/received_events","type":"User","site_admin":false},"open_issues":2,"closed_issues":5,"state":"open","created_at":"2018-03-13T22:31:03Z","updated_at":"2018-03-14T00:07:31Z","due_on":null,"closed_at":null},"comments":17,"created_at":"2018-02-15T09:24:28Z","updated_at":"2018-03-14T18:04:16Z","closed_at":"2018-03-02T16:30:04Z","author_association":"NONE","body":"After https://github.com/hashicorp/consul/issues/3712 (which is not really a big issue for us) we found another weird issue with X-Consul-Index while trying to improve Consul discovery within Prometheus: https://github.com/prometheus/prometheus/pull/3814\r\n\r\nWhen watching a service using a X-Consul-Index, if waiting more than 3 seconds before watching again the same path, the next call won't block and will return immediately the same data (which has not changed)\r\n\r\nIs there a reason for that or is it a bug ?\r\n\r\nIn order to reproduce, here is a script:\r\n```shell\r\n#!/bin/bash\r\nif test ${1:-none} = \"none\"\r\nthen\r\n  echo \"USAGE: $0 Consul_URL\"\r\n  echo \"       Example: localhost:8500/v1/health/service/MY_SUPER_SERVICE\"\r\n  exit 1\r\nfi\r\nurl_to_check=$1\r\n\r\nheaders=$(mktemp)\r\ncontent=$(mktemp)\r\nindex=0\r\nwhile true;\r\ndo\r\n  url=\"${url_to_check}?wait=5m&index=${index}&pretty=true&stale\"\r\n  curl -fs --dump-header \"$headers\" -o \"${content}.new\" \"${url}\" || { \"echo Failed to query ${url}\"; exit 1; }\r\n  if test $index -ne 0\r\n  then\r\n    diff -u \"$content\" \"$content.new\" && echo \" diff: No Differences found in service\"\r\n  fi\r\n  index=$(grep \"X-Consul-Index\" \"$headers\" | sed 's/[^0-9]*\\([0-9][0-9]*\\)[^0-9]*/\\1/g')\r\n  if test \"${index:-not_found}\" = \"not_found\"\r\n  then\r\n    # We are in a part of Consul that does not output X-Consul-Index in headers, switch to poll\r\n    sleep 5\r\n    index=1\r\n  fi\r\n  if test ${CONSUL_SLEEP_DELAY:-0} -gt 0\r\n  then\r\n    sleep ${CONSUL_SLEEP_DELAY}\r\n  fi\r\n  mv \"$content.new\" \"$content\"\r\n  printf \"X-Consul-Index: $index at $(date) \\b\"\r\ndone\r\n```\r\n\r\nWhen launching at the same time on our cluster the same script with a different delay between watches, here is what we observe:\r\n\r\nWith delay < 3 : the calls do block\r\n```\r\nexport CONSUL_SLEEP_DELAY=1; consul_check_services_changes.sh my-consul-agent:8500/v1/catalog/service/graphite-relay\r\nX-Consul-Index: 851481857 at Thu 15 Feb 2018 10:18:20 CET\r\n```\r\n\r\nWith delay > 3, the calls do not block, and return immediately\r\n```\r\nexport CONSUL_SLEEP_DELAY=4; consul_check_services_changes.sh consul05-par.central.criteo.prod:8500/v1/catalog/service/graphite-relay\r\nX-Consul-Index: 851481857 at Thu 15 Feb 2018 10:18:24 CET diff: No Differences found in service\r\nX-Consul-Index: 851482009 at Thu 15 Feb 2018 10:18:28 CET diff: No Differences found in service\r\nX-Consul-Index: 851482140 at Thu 15 Feb 2018 10:18:32 CET diff: No Differences found in service\r\nX-Consul-Index: 851482260 at Thu 15 Feb 2018 10:18:36 CET diff: No Differences found in service\r\nX-Consul-Index: 851482374 at Thu 15 Feb 2018 10:18:40 CET diff: No Differences found in service\r\n```"},"comment":{"url":"https://api.github.com/repos/hashicorp/consul/issues/comments/373119830","html_url":"https://github.com/hashicorp/consul/issues/3890#issuecomment-373119830","issue_url":"https://api.github.com/repos/hashicorp/consul/issues/3890","id":373119830,"user":{"login":"pierresouchay","id":8089033,"avatar_url":"https://avatars3.githubusercontent.com/u/8089033?v=4","gravatar_id":"","url":"https://api.github.com/users/pierresouchay","html_url":"https://github.com/pierresouchay","followers_url":"https://api.github.com/users/pierresouchay/followers","following_url":"https://api.github.com/users/pierresouchay/following{/other_user}","gists_url":"https://api.github.com/users/pierresouchay/gists{/gist_id}","starred_url":"https://api.github.com/users/pierresouchay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pierresouchay/subscriptions","organizations_url":"https://api.github.com/users/pierresouchay/orgs","repos_url":"https://api.github.com/users/pierresouchay/repos","events_url":"https://api.github.com/users/pierresouchay/events{/privacy}","received_events_url":"https://api.github.com/users/pierresouchay/received_events","type":"User","site_admin":false},"created_at":"2018-03-14T18:04:16Z","updated_at":"2018-03-14T18:04:16Z","author_association":"NONE","body":"Oh, ok, sorry about that :(\r\n\r\nJust curious, how did it break the code? What is the assumption broken?"}}
{"actor":{"display_login":"pierresouchay"}}