{"action":"created","comment":{"url":"https://api.github.com/repos/improbable-eng/thanos/pulls/comments/174151845","pull_request_review_id":103454757,"id":174151845,"diff_hunk":"@@ -27,89 +28,153 @@ import (\n // It optionally substitutes environment variables in the configuration.\n // Referenced environment variables must be of the form `$(var)` (not `$var` or `${var}`).\n type Reloader struct {\n-\tlogger           log.Logger\n-\treloadURL        *url.URL\n-\tcfgFilename      string\n-\tcfgSubstFilename string\n-\truleDir          string\n-\tlastCfgHash      []byte\n-\tlastRulesHash    []byte\n+\tlogger          log.Logger\n+\treloadURL       *url.URL\n+\tcfgFile         string\n+\tcfgEnvsubstFile string\n+\truleDir         string\n+\truleInterval    time.Duration\n+\tretryInteval    time.Duration\n+\n+\tlastCfgHash  []byte\n+\tlastRuleHash []byte\n }\n \n // New creates a new reloader that watches the given config file and rule directory\n // and triggers a Prometheus reload upon changes.\n // If cfgEnvsubstFile is not empty, environment variables in the config file will be\n-// substituted and the out put written into the given path. Promethes should then\n+// substituted and the out put written into the given path. Prometheus should then\n // use cfgEnvsubstFile as its config file path.\n-func New(logger log.Logger, reloadURL *url.URL, cfgFile, cfgEnvsubstFile, ruleDir string) *Reloader {\n+func New(logger log.Logger, reloadURL *url.URL, cfgFile string, cfgEnvsubstFile string, ruleDir string) *Reloader {\n+\tif logger == nil {\n+\t\tlogger = log.NewNopLogger()\n+\t}\n \treturn &Reloader{\n-\t\tlogger:           logger,\n-\t\treloadURL:        reloadURL,\n-\t\tcfgFilename:      cfgFile,\n-\t\tcfgSubstFilename: cfgEnvsubstFile,\n+\t\tlogger:          logger,\n+\t\treloadURL:       reloadURL,\n+\t\tcfgFile:         cfgFile,\n+\t\tcfgEnvsubstFile: cfgEnvsubstFile,\n+\t\truleDir:         ruleDir,\n+\t\truleInterval:    3 * time.Minute,\n+\t\tretryInteval:    5 * time.Second,\n \t}\n }\n \n-// Watch starts to watch the config file and processes it until the context\n-// gets canceled.\n+// Watch starts to watch the config file and rules and process them until the context\n+// gets canceled. Config file gets env expanded if cfgEnvsubstFile is specified and reload is trigger if\n+// config or rules changed.\n func (r *Reloader) Watch(ctx context.Context) error {\n-\tw, err := fsnotify.NewWatcher()\n+\tconfigWatcher, err := fsnotify.NewWatcher()\n \tif err != nil {\n \t\treturn errors.Wrap(err, \"create watcher\")\n \t}\n-\tdefer w.Close()\n-\n-\tcfgDir := filepath.Dir(r.cfgFilename)\n+\tdefer configWatcher.Close()\n \n-\tif err := w.Add(cfgDir); err != nil {\n-\t\treturn errors.Wrap(err, \"add config file directory watch\")\n-\t}\n-\tif _, err := r.applyConfig(); err != nil {\n-\t\treturn errors.Wrap(err, \"initial apply\")\n-\t}\n-\tif err := r.triggerReload(ctx); err != nil {\n-\t\tlevel.Error(r.logger).Log(\"msg\", \"triggering reload failed\", \"err\", err)\n+\tinitial := make(chan struct{}, 1)\n+\tif r.cfgFile != \"\" {\n+\t\tif err := configWatcher.Add(r.cfgFile); err != nil {\n+\t\t\treturn errors.Wrap(err, \"add config file watch\")\n+\t\t}\n+\t\tlevel.Info(r.logger).Log(\n+\t\t\t\"msg\", \"started watching config file for changes\",\n+\t\t\t\"in\", r.cfgFile,\n+\t\t\t\"out\", r.cfgEnvsubstFile)\n+\t\tinitial <- struct{}{}","path":"pkg/reloader/reloader.go","position":90,"original_position":90,"commit_id":"9259869c8419d0f0c94dee18d84f93899bdfa4ca","original_commit_id":"9259869c8419d0f0c94dee18d84f93899bdfa4ca","user":{"login":"Bplotka","id":6950331,"avatar_url":"https://avatars2.githubusercontent.com/u/6950331?v=4","gravatar_id":"","url":"https://api.github.com/users/Bplotka","html_url":"https://github.com/Bplotka","followers_url":"https://api.github.com/users/Bplotka/followers","following_url":"https://api.github.com/users/Bplotka/following{/other_user}","gists_url":"https://api.github.com/users/Bplotka/gists{/gist_id}","starred_url":"https://api.github.com/users/Bplotka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bplotka/subscriptions","organizations_url":"https://api.github.com/users/Bplotka/orgs","repos_url":"https://api.github.com/users/Bplotka/repos","events_url":"https://api.github.com/users/Bplotka/events{/privacy}","received_events_url":"https://api.github.com/users/Bplotka/received_events","type":"User","site_admin":false},"body":"mhm, sure I guess we can do so.","created_at":"2018-03-13T14:31:21Z","updated_at":"2018-03-13T14:31:21Z","html_url":"https://github.com/improbable-eng/thanos/pull/243#discussion_r174151845","pull_request_url":"https://api.github.com/repos/improbable-eng/thanos/pulls/243","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/improbable-eng/thanos/pulls/comments/174151845"},"html":{"href":"https://github.com/improbable-eng/thanos/pull/243#discussion_r174151845"},"pull_request":{"href":"https://api.github.com/repos/improbable-eng/thanos/pulls/243"}},"in_reply_to_id":174085670},"pull_request":{"url":"https://api.github.com/repos/improbable-eng/thanos/pulls/243","id":173996642,"html_url":"https://github.com/improbable-eng/thanos/pull/243","diff_url":"https://github.com/improbable-eng/thanos/pull/243.diff","patch_url":"https://github.com/improbable-eng/thanos/pull/243.patch","issue_url":"https://api.github.com/repos/improbable-eng/thanos/issues/243","number":243,"state":"open","locked":false,"title":"reloader: Fixed reloader and added unit tests.","user":{"login":"Bplotka","id":6950331,"avatar_url":"https://avatars2.githubusercontent.com/u/6950331?v=4","gravatar_id":"","url":"https://api.github.com/users/Bplotka","html_url":"https://github.com/Bplotka","followers_url":"https://api.github.com/users/Bplotka/followers","following_url":"https://api.github.com/users/Bplotka/following{/other_user}","gists_url":"https://api.github.com/users/Bplotka/gists{/gist_id}","starred_url":"https://api.github.com/users/Bplotka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Bplotka/subscriptions","organizations_url":"https://api.github.com/users/Bplotka/orgs","repos_url":"https://api.github.com/users/Bplotka/repos","events_url":"https://api.github.com/users/Bplotka/events{/privacy}","received_events_url":"https://api.github.com/users/Bplotka/received_events","type":"User","site_admin":false},"body":"Signed-off-by: Bartek Plotka <bwplotka@gmail.com>","created_at":"2018-03-09T12:44:56Z","updated_at":"2018-03-13T14:31:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"bfe4383af0e140eaa0b9a4ad2bf9d8d2e7e604f3","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/improbable-eng/thanos/pulls/243/commits","review_comments_url":"https://api.github.com/repos/improbable-eng/thanos/pulls/243/comments","review_comment_url":"https://api.github.com/repos/improbable-eng/thanos/pulls/comments{/number}","comments_url":"https://api.github.com/repos/improbable-eng/thanos/issues/243/comments","statuses_url":"https://api.github.com/repos/improbable-eng/thanos/statuses/9259869c8419d0f0c94dee18d84f93899bdfa4ca","head":{"label":"improbable-eng:reloader-fixes","ref":"reloader-fixes","sha":"9259869c8419d0f0c94dee18d84f93899bdfa4ca","user":{"login":"improbable-eng","id":26084283,"avatar_url":"https://avatars2.githubusercontent.com/u/26084283?v=4","gravatar_id":"","url":"https://api.github.com/users/improbable-eng","html_url":"https://github.com/improbable-eng","followers_url":"https://api.github.com/users/improbable-eng/followers","following_url":"https://api.github.com/users/improbable-eng/following{/other_user}","gists_url":"https://api.github.com/users/improbable-eng/gists{/gist_id}","starred_url":"https://api.github.com/users/improbable-eng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/improbable-eng/subscriptions","organizations_url":"https://api.github.com/users/improbable-eng/orgs","repos_url":"https://api.github.com/users/improbable-eng/repos","events_url":"https://api.github.com/users/improbable-eng/events{/privacy}","received_events_url":"https://api.github.com/users/improbable-eng/received_events","type":"Organization","site_admin":false},"repo":{"id":109162639,"name":"thanos","full_name":"improbable-eng/thanos","owner":{"login":"improbable-eng","id":26084283,"avatar_url":"https://avatars2.githubusercontent.com/u/26084283?v=4","gravatar_id":"","url":"https://api.github.com/users/improbable-eng","html_url":"https://github.com/improbable-eng","followers_url":"https://api.github.com/users/improbable-eng/followers","following_url":"https://api.github.com/users/improbable-eng/following{/other_user}","gists_url":"https://api.github.com/users/improbable-eng/gists{/gist_id}","starred_url":"https://api.github.com/users/improbable-eng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/improbable-eng/subscriptions","organizations_url":"https://api.github.com/users/improbable-eng/orgs","repos_url":"https://api.github.com/users/improbable-eng/repos","events_url":"https://api.github.com/users/improbable-eng/events{/privacy}","received_events_url":"https://api.github.com/users/improbable-eng/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/improbable-eng/thanos","description":"Highly available Prometheus setup with long term storage capabilities.","fork":false,"url":"https://api.github.com/repos/improbable-eng/thanos","forks_url":"https://api.github.com/repos/improbable-eng/thanos/forks","keys_url":"https://api.github.com/repos/improbable-eng/thanos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/improbable-eng/thanos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/improbable-eng/thanos/teams","hooks_url":"https://api.github.com/repos/improbable-eng/thanos/hooks","issue_events_url":"https://api.github.com/repos/improbable-eng/thanos/issues/events{/number}","events_url":"https://api.github.com/repos/improbable-eng/thanos/events","assignees_url":"https://api.github.com/repos/improbable-eng/thanos/assignees{/user}","branches_url":"https://api.github.com/repos/improbable-eng/thanos/branches{/branch}","tags_url":"https://api.github.com/repos/improbable-eng/thanos/tags","blobs_url":"https://api.github.com/repos/improbable-eng/thanos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/improbable-eng/thanos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/improbable-eng/thanos/git/refs{/sha}","trees_url":"https://api.github.com/repos/improbable-eng/thanos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/improbable-eng/thanos/statuses/{sha}","languages_url":"https://api.github.com/repos/improbable-eng/thanos/languages","stargazers_url":"https://api.github.com/repos/improbable-eng/thanos/stargazers","contributors_url":"https://api.github.com/repos/improbable-eng/thanos/contributors","subscribers_url":"https://api.github.com/repos/improbable-eng/thanos/subscribers","subscription_url":"https://api.github.com/repos/improbable-eng/thanos/subscription","commits_url":"https://api.github.com/repos/improbable-eng/thanos/commits{/sha}","git_commits_url":"https://api.github.com/repos/improbable-eng/thanos/git/commits{/sha}","comments_url":"https://api.github.com/repos/improbable-eng/thanos/comments{/number}","issue_comment_url":"https://api.github.com/repos/improbable-eng/thanos/issues/comments{/number}","contents_url":"https://api.github.com/repos/improbable-eng/thanos/contents/{+path}","compare_url":"https://api.github.com/repos/improbable-eng/thanos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/improbable-eng/thanos/merges","archive_url":"https://api.github.com/repos/improbable-eng/thanos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/improbable-eng/thanos/downloads","issues_url":"https://api.github.com/repos/improbable-eng/thanos/issues{/number}","pulls_url":"https://api.github.com/repos/improbable-eng/thanos/pulls{/number}","milestones_url":"https://api.github.com/repos/improbable-eng/thanos/milestones{/number}","notifications_url":"https://api.github.com/repos/improbable-eng/thanos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/improbable-eng/thanos/labels{/name}","releases_url":"https://api.github.com/repos/improbable-eng/thanos/releases{/id}","deployments_url":"https://api.github.com/repos/improbable-eng/thanos/deployments","created_at":"2017-11-01T17:38:03Z","updated_at":"2018-03-13T12:16:51Z","pushed_at":"2018-03-13T06:56:12Z","git_url":"git://github.com/improbable-eng/thanos.git","ssh_url":"git@github.com:improbable-eng/thanos.git","clone_url":"https://github.com/improbable-eng/thanos.git","svn_url":"https://github.com/improbable-eng/thanos","homepage":"","size":45279,"stargazers_count":147,"watchers_count":147,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"archived":false,"open_issues_count":26,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":10,"open_issues":26,"watchers":147,"default_branch":"master"}},"base":{"label":"improbable-eng:master","ref":"master","sha":"605e75b0fd991b08663e9cf2364d799d5ce0342c","user":{"login":"improbable-eng","id":26084283,"avatar_url":"https://avatars2.githubusercontent.com/u/26084283?v=4","gravatar_id":"","url":"https://api.github.com/users/improbable-eng","html_url":"https://github.com/improbable-eng","followers_url":"https://api.github.com/users/improbable-eng/followers","following_url":"https://api.github.com/users/improbable-eng/following{/other_user}","gists_url":"https://api.github.com/users/improbable-eng/gists{/gist_id}","starred_url":"https://api.github.com/users/improbable-eng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/improbable-eng/subscriptions","organizations_url":"https://api.github.com/users/improbable-eng/orgs","repos_url":"https://api.github.com/users/improbable-eng/repos","events_url":"https://api.github.com/users/improbable-eng/events{/privacy}","received_events_url":"https://api.github.com/users/improbable-eng/received_events","type":"Organization","site_admin":false},"repo":{"id":109162639,"name":"thanos","full_name":"improbable-eng/thanos","owner":{"login":"improbable-eng","id":26084283,"avatar_url":"https://avatars2.githubusercontent.com/u/26084283?v=4","gravatar_id":"","url":"https://api.github.com/users/improbable-eng","html_url":"https://github.com/improbable-eng","followers_url":"https://api.github.com/users/improbable-eng/followers","following_url":"https://api.github.com/users/improbable-eng/following{/other_user}","gists_url":"https://api.github.com/users/improbable-eng/gists{/gist_id}","starred_url":"https://api.github.com/users/improbable-eng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/improbable-eng/subscriptions","organizations_url":"https://api.github.com/users/improbable-eng/orgs","repos_url":"https://api.github.com/users/improbable-eng/repos","events_url":"https://api.github.com/users/improbable-eng/events{/privacy}","received_events_url":"https://api.github.com/users/improbable-eng/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/improbable-eng/thanos","description":"Highly available Prometheus setup with long term storage capabilities.","fork":false,"url":"https://api.github.com/repos/improbable-eng/thanos","forks_url":"https://api.github.com/repos/improbable-eng/thanos/forks","keys_url":"https://api.github.com/repos/improbable-eng/thanos/keys{/key_id}","collaborators_url":"https://api.github.com/repos/improbable-eng/thanos/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/improbable-eng/thanos/teams","hooks_url":"https://api.github.com/repos/improbable-eng/thanos/hooks","issue_events_url":"https://api.github.com/repos/improbable-eng/thanos/issues/events{/number}","events_url":"https://api.github.com/repos/improbable-eng/thanos/events","assignees_url":"https://api.github.com/repos/improbable-eng/thanos/assignees{/user}","branches_url":"https://api.github.com/repos/improbable-eng/thanos/branches{/branch}","tags_url":"https://api.github.com/repos/improbable-eng/thanos/tags","blobs_url":"https://api.github.com/repos/improbable-eng/thanos/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/improbable-eng/thanos/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/improbable-eng/thanos/git/refs{/sha}","trees_url":"https://api.github.com/repos/improbable-eng/thanos/git/trees{/sha}","statuses_url":"https://api.github.com/repos/improbable-eng/thanos/statuses/{sha}","languages_url":"https://api.github.com/repos/improbable-eng/thanos/languages","stargazers_url":"https://api.github.com/repos/improbable-eng/thanos/stargazers","contributors_url":"https://api.github.com/repos/improbable-eng/thanos/contributors","subscribers_url":"https://api.github.com/repos/improbable-eng/thanos/subscribers","subscription_url":"https://api.github.com/repos/improbable-eng/thanos/subscription","commits_url":"https://api.github.com/repos/improbable-eng/thanos/commits{/sha}","git_commits_url":"https://api.github.com/repos/improbable-eng/thanos/git/commits{/sha}","comments_url":"https://api.github.com/repos/improbable-eng/thanos/comments{/number}","issue_comment_url":"https://api.github.com/repos/improbable-eng/thanos/issues/comments{/number}","contents_url":"https://api.github.com/repos/improbable-eng/thanos/contents/{+path}","compare_url":"https://api.github.com/repos/improbable-eng/thanos/compare/{base}...{head}","merges_url":"https://api.github.com/repos/improbable-eng/thanos/merges","archive_url":"https://api.github.com/repos/improbable-eng/thanos/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/improbable-eng/thanos/downloads","issues_url":"https://api.github.com/repos/improbable-eng/thanos/issues{/number}","pulls_url":"https://api.github.com/repos/improbable-eng/thanos/pulls{/number}","milestones_url":"https://api.github.com/repos/improbable-eng/thanos/milestones{/number}","notifications_url":"https://api.github.com/repos/improbable-eng/thanos/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/improbable-eng/thanos/labels{/name}","releases_url":"https://api.github.com/repos/improbable-eng/thanos/releases{/id}","deployments_url":"https://api.github.com/repos/improbable-eng/thanos/deployments","created_at":"2017-11-01T17:38:03Z","updated_at":"2018-03-13T12:16:51Z","pushed_at":"2018-03-13T06:56:12Z","git_url":"git://github.com/improbable-eng/thanos.git","ssh_url":"git@github.com:improbable-eng/thanos.git","clone_url":"https://github.com/improbable-eng/thanos.git","svn_url":"https://github.com/improbable-eng/thanos","homepage":"","size":45279,"stargazers_count":147,"watchers_count":147,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"archived":false,"open_issues_count":26,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0"},"forks":10,"open_issues":26,"watchers":147,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/improbable-eng/thanos/pulls/243"},"html":{"href":"https://github.com/improbable-eng/thanos/pull/243"},"issue":{"href":"https://api.github.com/repos/improbable-eng/thanos/issues/243"},"comments":{"href":"https://api.github.com/repos/improbable-eng/thanos/issues/243/comments"},"review_comments":{"href":"https://api.github.com/repos/improbable-eng/thanos/pulls/243/comments"},"review_comment":{"href":"https://api.github.com/repos/improbable-eng/thanos/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/improbable-eng/thanos/pulls/243/commits"},"statuses":{"href":"https://api.github.com/repos/improbable-eng/thanos/statuses/9259869c8419d0f0c94dee18d84f93899bdfa4ca"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"Bplotka"}}