{"action":"created","comment":{"url":"https://api.github.com/repos/Nitro/traefik/pulls/comments/113909627","pull_request_review_id":35337786,"id":113909627,"diff_hunk":"@@ -70,150 +89,171 @@ func (provider *Sidecar) Provide(configurationChan chan<- types.ConfigMessage, p\n \t\t\t\t\treturn\n \t\t\t\tcase event := <-watcher.Events:\n \t\t\t\t\tif strings.Contains(event.Name, file.Name()) {\n-\t\t\t\t\t\tlog.Debug(\"Sidecar Frontend File event:\", event)\n-\t\t\t\t\t\tstates, errState := provider.fetchState()\n-\t\t\t\t\t\tif errState != nil {\n-\t\t\t\t\t\t\tlog.Errorln(\"Error reloading Sidecar config\", errState)\n+\t\t\t\t\t\tlog.Debug(\"Sidecar config file event: \", event)\n+\t\t\t\t\t\terr = provider.reloadConfig()\n+\t\t\t\t\t\tif err != nil {\n+\t\t\t\t\t\t\tlog.Error(err)\n \t\t\t\t\t\t}\n-\t\t\t\t\t\tprovider.loadSidecarConfig(states.ByService())\n \t\t\t\t\t}\n \t\t\t\tcase errWatcher := <-watcher.Errors:\n-\t\t\t\t\tlog.Errorln(\"Watcher event error\", errWatcher)\n+\t\t\t\t\tlog.Error(\"Watcher event error: \", errWatcher)\n \t\t\t\t}\n \t\t\t}\n \t\t})\n \t\terr = watcher.Add(filepath.Dir(file.Name()))\n \t\tif err != nil {\n-\t\t\tlog.Error(\"Error adding file watcher\", err)\n+\t\t\tlog.Error(\"Error adding file watcher: \", err)\n \t\t\treturn err\n \t\t}\n+\t} else {\n+\t\terr := provider.reloadConfig()\n+\t\tif err != nil {\n+\t\t\tlog.Error(err)\n+\t\t}\n \t}\n+\n+\treturn nil\n+}\n+\n+func (provider *Sidecar) reloadConfig() error {\n \tstates, err := provider.fetchState()\n \tif err != nil {\n-\t\tlog.Fatalln(\"Error reloading Sidecar config\", err)\n+\t\treturn fmt.Errorf(\"Error fetching Sidecar state: %s\", err)\n \t}\n-\terr = provider.loadSidecarConfig(states.ByService())\n+\n+\terr = provider.loadConfig(states.ByService())\n \tif err != nil {\n-\t\treturn err\n+\t\treturn fmt.Errorf(\"Error loading Sidecar config: %s\", err)\n \t}\n+\n \treturn nil\n }\n \n-func (provider *Sidecar) constructConfig(sidecarStates map[string][]*service.Service) (*types.Configuration, error) {\n-\tlog.Infoln(\"loading sidecar config\")\n-\tsidecarConfig := types.Configuration{Backends: provider.makeBackends(sidecarStates)}\n-\tvar err error\n-\tsidecarConfig.Frontends, err = provider.makeFrontend()\n-\tif err != nil {\n-\t\treturn nil, err\n+func (provider *Sidecar) loadConfig(sidecarStates map[string][]*service.Service) error {\n+\tlog.Info(\"Loading sidecar config...\")\n+\n+\tconfig := &types.Configuration{\n+\t\tBackends: make(map[string]*types.Backend),\n \t}\n-\treturn &sidecarConfig, nil\n-}\n \n-func (provider *Sidecar) loadSidecarConfig(sidecarStates map[string][]*service.Service) error {\n-\tconf, err := provider.constructConfig(sidecarStates)\n-\tif err != nil {\n+\tif _, err := toml.DecodeFile(provider.Filename, config); err != nil {\n \t\treturn err\n \t}\n+\n+\t// Create backends from Sidecar state data\n+\tfor serviceName, services := range sidecarStates {\n+\t\tbackend, ok := config.Backends[serviceName]\n+\t\tif !ok {\n+\t\t\tbackend = &types.Backend{}\n+\t\t\tconfig.Backends[serviceName] = backend\n+\t\t}\n+\n+\t\tif backend.LoadBalancer == nil {\n+\t\t\tbackend.LoadBalancer = &types.LoadBalancer{Method: defaultMethod, Sticky: defaultSticky}\n+\t\t}\n+\t\tif backend.Servers == nil {\n+\t\t\tbackend.Servers = make(map[string]types.Server)\n+\t\t}\n+\n+\t\tfor _, serv := range services {\n+\t\t\tif serv.IsAlive() {\n+\t\t\t\tipAddr, err := net.LookupIP(serv.Hostname)","path":"provider/sidecar.go","position":187,"original_position":187,"commit_id":"10dd3327733026fbf57d4f71ff9da114537030bc","original_commit_id":"10dd3327733026fbf57d4f71ff9da114537030bc","user":{"login":"relistan","id":267761,"avatar_url":"https://avatars1.githubusercontent.com/u/267761?v=3","gravatar_id":"","url":"https://api.github.com/users/relistan","html_url":"https://github.com/relistan","followers_url":"https://api.github.com/users/relistan/followers","following_url":"https://api.github.com/users/relistan/following{/other_user}","gists_url":"https://api.github.com/users/relistan/gists{/gist_id}","starred_url":"https://api.github.com/users/relistan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/relistan/subscriptions","organizations_url":"https://api.github.com/users/relistan/orgs","repos_url":"https://api.github.com/users/relistan/repos","events_url":"https://api.github.com/users/relistan/events{/privacy}","received_events_url":"https://api.github.com/users/relistan/received_events","type":"User","site_admin":false},"body":"I guess that ^^ was discussed here earlier. Probably best in a separate PR.","created_at":"2017-04-28T11:43:31Z","updated_at":"2017-04-28T11:43:32Z","html_url":"https://github.com/Nitro/traefik/pull/7#discussion_r113909627","pull_request_url":"https://api.github.com/repos/Nitro/traefik/pulls/7","_links":{"self":{"href":"https://api.github.com/repos/Nitro/traefik/pulls/comments/113909627"},"html":{"href":"https://github.com/Nitro/traefik/pull/7#discussion_r113909627"},"pull_request":{"href":"https://api.github.com/repos/Nitro/traefik/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/Nitro/traefik/pulls/7","id":117024765,"html_url":"https://github.com/Nitro/traefik/pull/7","diff_url":"https://github.com/Nitro/traefik/pull/7.diff","patch_url":"https://github.com/Nitro/traefik/pull/7.patch","issue_url":"https://api.github.com/repos/Nitro/traefik/issues/7","number":7,"state":"open","locked":false,"title":"Add Sidecar maxconn support","user":{"login":"mihaitodor","id":788216,"avatar_url":"https://avatars0.githubusercontent.com/u/788216?v=3","gravatar_id":"","url":"https://api.github.com/users/mihaitodor","html_url":"https://github.com/mihaitodor","followers_url":"https://api.github.com/users/mihaitodor/followers","following_url":"https://api.github.com/users/mihaitodor/following{/other_user}","gists_url":"https://api.github.com/users/mihaitodor/gists{/gist_id}","starred_url":"https://api.github.com/users/mihaitodor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mihaitodor/subscriptions","organizations_url":"https://api.github.com/users/mihaitodor/orgs","repos_url":"https://api.github.com/users/mihaitodor/repos","events_url":"https://api.github.com/users/mihaitodor/events{/privacy}","received_events_url":"https://api.github.com/users/mihaitodor/received_events","type":"User","site_admin":false},"body":"!!! DO NOT MERGE THIS !!! - I'll close it once we agree on the requirements for the future PRs that we want to extract from it.\r\n\r\nHere's my attempt at adding maxconn support for the Sidecar provider... I'm opening a separate PR on top of this one to add the UI support.\r\n\r\nNotes:\r\n- I renamed (used the default) parameter for the sidecar.toml file. It is called \"filename\" now (just like for all the other providers), so we'll need to update the ansible scripts in erector\r\n- Test_SidecarWatcher wasn't exercising the watcher functionality properly because `httpmock` doesn't work out of the box for a custom `http.Client`. We could use `httpmock.ActivateNonDefault`, but it only supports a single custom `http.Client`, so it's easier to overwrite them with `http.DefaultClient` in the test code.\r\n\r\nTODO:\r\n- [ ] Can we fetch the host IP from Sidecar now? If yes, I can remove the part which resolves IPs for hosts.\r\n- [ ] Is there any point to add unreachable hosts?\r\n- [ ] Do we really want to kill Traefik if we can't connect to Sidecar when it starts up? No other provider does that\r\n- [ ] Convey panics inside a goroutine when using `c.So(err, ShouldBeNil)`, if `err != nil`. It might be a bug in Convey, but I'm not sure yet. This is annoying because we shouldn't get a panic when tests fail.","created_at":"2017-04-21T16:43:30Z","updated_at":"2017-04-28T11:43:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5a6850e5224bfba82210915a51580ebb56d1dadf","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/Nitro/traefik/pulls/7/commits","review_comments_url":"https://api.github.com/repos/Nitro/traefik/pulls/7/comments","review_comment_url":"https://api.github.com/repos/Nitro/traefik/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Nitro/traefik/issues/7/comments","statuses_url":"https://api.github.com/repos/Nitro/traefik/statuses/10dd3327733026fbf57d4f71ff9da114537030bc","head":{"label":"Nitro:add-sidecar-maxconn-support","ref":"add-sidecar-maxconn-support","sha":"10dd3327733026fbf57d4f71ff9da114537030bc","user":{"login":"Nitro","id":1775750,"avatar_url":"https://avatars1.githubusercontent.com/u/1775750?v=3","gravatar_id":"","url":"https://api.github.com/users/Nitro","html_url":"https://github.com/Nitro","followers_url":"https://api.github.com/users/Nitro/followers","following_url":"https://api.github.com/users/Nitro/following{/other_user}","gists_url":"https://api.github.com/users/Nitro/gists{/gist_id}","starred_url":"https://api.github.com/users/Nitro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nitro/subscriptions","organizations_url":"https://api.github.com/users/Nitro/orgs","repos_url":"https://api.github.com/users/Nitro/repos","events_url":"https://api.github.com/users/Nitro/events{/privacy}","received_events_url":"https://api.github.com/users/Nitro/received_events","type":"Organization","site_admin":false},"repo":{"id":80852937,"name":"traefik","full_name":"Nitro/traefik","owner":{"login":"Nitro","id":1775750,"avatar_url":"https://avatars1.githubusercontent.com/u/1775750?v=3","gravatar_id":"","url":"https://api.github.com/users/Nitro","html_url":"https://github.com/Nitro","followers_url":"https://api.github.com/users/Nitro/followers","following_url":"https://api.github.com/users/Nitro/following{/other_user}","gists_url":"https://api.github.com/users/Nitro/gists{/gist_id}","starred_url":"https://api.github.com/users/Nitro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nitro/subscriptions","organizations_url":"https://api.github.com/users/Nitro/orgs","repos_url":"https://api.github.com/users/Nitro/repos","events_url":"https://api.github.com/users/Nitro/events{/privacy}","received_events_url":"https://api.github.com/users/Nitro/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Nitro/traefik","description":"Træfɪk, a modern reverse proxy","fork":true,"url":"https://api.github.com/repos/Nitro/traefik","forks_url":"https://api.github.com/repos/Nitro/traefik/forks","keys_url":"https://api.github.com/repos/Nitro/traefik/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Nitro/traefik/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Nitro/traefik/teams","hooks_url":"https://api.github.com/repos/Nitro/traefik/hooks","issue_events_url":"https://api.github.com/repos/Nitro/traefik/issues/events{/number}","events_url":"https://api.github.com/repos/Nitro/traefik/events","assignees_url":"https://api.github.com/repos/Nitro/traefik/assignees{/user}","branches_url":"https://api.github.com/repos/Nitro/traefik/branches{/branch}","tags_url":"https://api.github.com/repos/Nitro/traefik/tags","blobs_url":"https://api.github.com/repos/Nitro/traefik/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Nitro/traefik/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Nitro/traefik/git/refs{/sha}","trees_url":"https://api.github.com/repos/Nitro/traefik/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Nitro/traefik/statuses/{sha}","languages_url":"https://api.github.com/repos/Nitro/traefik/languages","stargazers_url":"https://api.github.com/repos/Nitro/traefik/stargazers","contributors_url":"https://api.github.com/repos/Nitro/traefik/contributors","subscribers_url":"https://api.github.com/repos/Nitro/traefik/subscribers","subscription_url":"https://api.github.com/repos/Nitro/traefik/subscription","commits_url":"https://api.github.com/repos/Nitro/traefik/commits{/sha}","git_commits_url":"https://api.github.com/repos/Nitro/traefik/git/commits{/sha}","comments_url":"https://api.github.com/repos/Nitro/traefik/comments{/number}","issue_comment_url":"https://api.github.com/repos/Nitro/traefik/issues/comments{/number}","contents_url":"https://api.github.com/repos/Nitro/traefik/contents/{+path}","compare_url":"https://api.github.com/repos/Nitro/traefik/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Nitro/traefik/merges","archive_url":"https://api.github.com/repos/Nitro/traefik/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Nitro/traefik/downloads","issues_url":"https://api.github.com/repos/Nitro/traefik/issues{/number}","pulls_url":"https://api.github.com/repos/Nitro/traefik/pulls{/number}","milestones_url":"https://api.github.com/repos/Nitro/traefik/milestones{/number}","notifications_url":"https://api.github.com/repos/Nitro/traefik/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Nitro/traefik/labels{/name}","releases_url":"https://api.github.com/repos/Nitro/traefik/releases{/id}","deployments_url":"https://api.github.com/repos/Nitro/traefik/deployments","created_at":"2017-02-03T17:38:29Z","updated_at":"2017-04-13T00:25:13Z","pushed_at":"2017-04-28T00:27:23Z","git_url":"git://github.com/Nitro/traefik.git","ssh_url":"git@github.com:Nitro/traefik.git","clone_url":"https://github.com/Nitro/traefik.git","svn_url":"https://github.com/Nitro/traefik","homepage":"https://traefik.io/","size":16173,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":2,"default_branch":"master"}},"base":{"label":"Nitro:master","ref":"master","sha":"1fd171d67dd5fc3993b51e55a92e779c6f459976","user":{"login":"Nitro","id":1775750,"avatar_url":"https://avatars1.githubusercontent.com/u/1775750?v=3","gravatar_id":"","url":"https://api.github.com/users/Nitro","html_url":"https://github.com/Nitro","followers_url":"https://api.github.com/users/Nitro/followers","following_url":"https://api.github.com/users/Nitro/following{/other_user}","gists_url":"https://api.github.com/users/Nitro/gists{/gist_id}","starred_url":"https://api.github.com/users/Nitro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nitro/subscriptions","organizations_url":"https://api.github.com/users/Nitro/orgs","repos_url":"https://api.github.com/users/Nitro/repos","events_url":"https://api.github.com/users/Nitro/events{/privacy}","received_events_url":"https://api.github.com/users/Nitro/received_events","type":"Organization","site_admin":false},"repo":{"id":80852937,"name":"traefik","full_name":"Nitro/traefik","owner":{"login":"Nitro","id":1775750,"avatar_url":"https://avatars1.githubusercontent.com/u/1775750?v=3","gravatar_id":"","url":"https://api.github.com/users/Nitro","html_url":"https://github.com/Nitro","followers_url":"https://api.github.com/users/Nitro/followers","following_url":"https://api.github.com/users/Nitro/following{/other_user}","gists_url":"https://api.github.com/users/Nitro/gists{/gist_id}","starred_url":"https://api.github.com/users/Nitro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Nitro/subscriptions","organizations_url":"https://api.github.com/users/Nitro/orgs","repos_url":"https://api.github.com/users/Nitro/repos","events_url":"https://api.github.com/users/Nitro/events{/privacy}","received_events_url":"https://api.github.com/users/Nitro/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Nitro/traefik","description":"Træfɪk, a modern reverse proxy","fork":true,"url":"https://api.github.com/repos/Nitro/traefik","forks_url":"https://api.github.com/repos/Nitro/traefik/forks","keys_url":"https://api.github.com/repos/Nitro/traefik/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Nitro/traefik/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Nitro/traefik/teams","hooks_url":"https://api.github.com/repos/Nitro/traefik/hooks","issue_events_url":"https://api.github.com/repos/Nitro/traefik/issues/events{/number}","events_url":"https://api.github.com/repos/Nitro/traefik/events","assignees_url":"https://api.github.com/repos/Nitro/traefik/assignees{/user}","branches_url":"https://api.github.com/repos/Nitro/traefik/branches{/branch}","tags_url":"https://api.github.com/repos/Nitro/traefik/tags","blobs_url":"https://api.github.com/repos/Nitro/traefik/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Nitro/traefik/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Nitro/traefik/git/refs{/sha}","trees_url":"https://api.github.com/repos/Nitro/traefik/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Nitro/traefik/statuses/{sha}","languages_url":"https://api.github.com/repos/Nitro/traefik/languages","stargazers_url":"https://api.github.com/repos/Nitro/traefik/stargazers","contributors_url":"https://api.github.com/repos/Nitro/traefik/contributors","subscribers_url":"https://api.github.com/repos/Nitro/traefik/subscribers","subscription_url":"https://api.github.com/repos/Nitro/traefik/subscription","commits_url":"https://api.github.com/repos/Nitro/traefik/commits{/sha}","git_commits_url":"https://api.github.com/repos/Nitro/traefik/git/commits{/sha}","comments_url":"https://api.github.com/repos/Nitro/traefik/comments{/number}","issue_comment_url":"https://api.github.com/repos/Nitro/traefik/issues/comments{/number}","contents_url":"https://api.github.com/repos/Nitro/traefik/contents/{+path}","compare_url":"https://api.github.com/repos/Nitro/traefik/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Nitro/traefik/merges","archive_url":"https://api.github.com/repos/Nitro/traefik/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Nitro/traefik/downloads","issues_url":"https://api.github.com/repos/Nitro/traefik/issues{/number}","pulls_url":"https://api.github.com/repos/Nitro/traefik/pulls{/number}","milestones_url":"https://api.github.com/repos/Nitro/traefik/milestones{/number}","notifications_url":"https://api.github.com/repos/Nitro/traefik/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Nitro/traefik/labels{/name}","releases_url":"https://api.github.com/repos/Nitro/traefik/releases{/id}","deployments_url":"https://api.github.com/repos/Nitro/traefik/deployments","created_at":"2017-02-03T17:38:29Z","updated_at":"2017-04-13T00:25:13Z","pushed_at":"2017-04-28T00:27:23Z","git_url":"git://github.com/Nitro/traefik.git","ssh_url":"git@github.com:Nitro/traefik.git","clone_url":"https://github.com/Nitro/traefik.git","svn_url":"https://github.com/Nitro/traefik","homepage":"https://traefik.io/","size":16173,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":3,"forks":0,"open_issues":3,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Nitro/traefik/pulls/7"},"html":{"href":"https://github.com/Nitro/traefik/pull/7"},"issue":{"href":"https://api.github.com/repos/Nitro/traefik/issues/7"},"comments":{"href":"https://api.github.com/repos/Nitro/traefik/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/Nitro/traefik/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/Nitro/traefik/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Nitro/traefik/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/Nitro/traefik/statuses/10dd3327733026fbf57d4f71ff9da114537030bc"}}}}
{"actor":{"display_login":"relistan"}}