{"action":"created","comment":{"url":"https://api.github.com/repos/prometheus/prometheus/pulls/comments/178736248","pull_request_review_id":108839026,"id":178736248,"diff_hunk":"@@ -97,71 +106,73 @@ func (m *Manager) ApplyConfig(cfg *config.Config) error {\n \treturn nil\n }\n \n-// TargetMap returns map of active and dropped targets and their corresponding scrape config job name.\n-func (m *Manager) TargetMap() map[string][]*Target {\n-\tm.mtx.Lock()\n-\tdefer m.mtx.Unlock()\n-\n-\ttargets := make(map[string][]*Target)\n-\tfor jobName, sp := range m.scrapePools {\n-\t\tsp.mtx.RLock()\n-\t\tfor _, t := range sp.targets {\n-\t\t\ttargets[jobName] = append(targets[jobName], t)\n-\t\t}\n-\t\ttargets[jobName] = append(targets[jobName], sp.droppedTargets...)\n-\t\tsp.mtx.RUnlock()\n-\t}\n+// TargetsAll returns active and dropped targets.\n+func (m *Manager) TargetsAll() map[string][]*Target {\n+\tm.mtxTargets.Lock()\n+\tdefer m.mtxTargets.Unlock()\n+\treturn m.targetsAll\n+}\n \n-\treturn targets\n+// TargetsActive returns the active targets currently being scraped.\n+func (m *Manager) TargetsActive() []*Target {\n+\tm.mtxTargets.Lock()\n+\tdefer m.mtxTargets.Unlock()\n+\treturn m.targetsActive\n }\n \n-// Targets returns the targets currently being scraped.\n-func (m *Manager) Targets() []*Target {\n-\tm.mtx.Lock()\n-\tdefer m.mtx.Unlock()\n+// TargetsDropped returns the dropped targets during relabelling.\n+func (m *Manager) TargetsDropped() []*Target {\n+\tm.mtxTargets.Lock()\n+\tdefer m.mtxTargets.Unlock()\n+\treturn m.targetsDropped\n+}\n \n-\tvar targets []*Target\n-\tfor _, p := range m.scrapePools {\n-\t\tp.mtx.RLock()\n-\t\tfor _, tt := range p.targets {\n-\t\t\ttargets = append(targets, tt)\n-\t\t}\n-\t\tp.mtx.RUnlock()\n-\t}\n+func (m *Manager) targetsUpdate(active, dropped map[string][]*Target) {\n+\tm.mtxTargets.Lock()\n+\tdefer m.mtxTargets.Unlock()\n \n-\treturn targets\n-}\n+\tm.targetsAll = make(map[string][]*Target)\n+\tm.targetsActive = nil\n+\tm.targetsDropped = nil\n+\tfor jobName, targets := range active {\n+\t\tm.targetsAll[jobName] = append(m.targetsAll[jobName], targets...)\n+\t\tm.targetsActive = append(m.targetsActive, targets...)\n \n-// DroppedTargets returns the targets dropped during relabelling.\n-func (m *Manager) DroppedTargets() []*Target {\n-\tm.mtx.Lock()\n-\tdefer m.mtx.Unlock()\n-\tvar droppedTargets []*Target\n-\tfor _, p := range m.scrapePools {\n-\t\tp.mtx.RLock()\n-\t\tdroppedTargets = append(droppedTargets, p.droppedTargets...)\n-\t\tp.mtx.RUnlock()\n \t}\n-\treturn droppedTargets\n+\tfor jobName, targets := range dropped {\n+\t\tm.targetsAll[jobName] = append(m.targetsAll[jobName], targets...)\n+\t\tm.targetsDropped = append(m.targetsDropped, targets...)\n+\t}\n }\n \n func (m *Manager) reload(t map[string][]*targetgroup.Group) {\n+\ttDropped := make(map[string][]*Target)\n+\ttActive := make(map[string][]*Target)\n+\tvar sp *scrapePool\n \tfor tsetName, tgroup := range t {\n-\t\tscrapeConfig, ok := m.scrapeConfigs[tsetName]\n-\t\tif !ok {\n-\t\t\tlevel.Error(m.logger).Log(\"msg\", \"error reloading target set\", \"err\", fmt.Sprintf(\"invalid config id:%v\", tsetName))\n-\t\t\tcontinue\n+\t\tm.mtx.Lock()\n+\t\tif existing, ok := m.scrapePools[tsetName]; !ok {\n+\t\t\tscrapeConfig, ok := m.scrapeConfigs[tsetName]\n+\t\t\tif !ok {\n+\t\t\t\tlevel.Error(m.logger).Log(\"msg\", \"error reloading target set\", \"err\", fmt.Sprintf(\"invalid config id:%v\", tsetName))\n+\t\t\t\tcontinue\n+\t\t\t}\n+\t\t\tsp = newScrapePool(scrapeConfig, m.append, log.With(m.logger, \"scrape_pool\", tsetName))\n+\t\t\tm.scrapePools[tsetName] = sp\n+\t\t} else {\n+\t\t\tsp = existing\n \t\t}\n+\t\tm.mtx.Unlock()\n \n-\t\t// Scrape pool doesn't exist so start a new one.\n-\t\texisting, ok := m.scrapePools[tsetName]\n-\t\tif !ok {\n-\t\t\tsp := newScrapePool(scrapeConfig, m.append, log.With(m.logger, \"scrape_pool\", tsetName))\n-\t\t\tm.scrapePools[tsetName] = sp\n-\t\t\tsp.Sync(tgroup)\n+\t\tsp.Sync(tgroup)\n \n-\t\t} else {\n-\t\t\texisting.Sync(tgroup)\n+\t\tsp.mtx.RLock()","path":"scrape/manager.go","position":163,"original_position":163,"commit_id":"d2f71777c97ccc55b4cd8d5d0767d91d2a88454a","original_commit_id":"d2f71777c97ccc55b4cd8d5d0767d91d2a88454a","user":{"login":"brian-brazil","id":7115638,"avatar_url":"https://avatars0.githubusercontent.com/u/7115638?v=4","gravatar_id":"","url":"https://api.github.com/users/brian-brazil","html_url":"https://github.com/brian-brazil","followers_url":"https://api.github.com/users/brian-brazil/followers","following_url":"https://api.github.com/users/brian-brazil/following{/other_user}","gists_url":"https://api.github.com/users/brian-brazil/gists{/gist_id}","starred_url":"https://api.github.com/users/brian-brazil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brian-brazil/subscriptions","organizations_url":"https://api.github.com/users/brian-brazil/orgs","repos_url":"https://api.github.com/users/brian-brazil/repos","events_url":"https://api.github.com/users/brian-brazil/events{/privacy}","received_events_url":"https://api.github.com/users/brian-brazil/received_events","type":"User","site_admin":false},"body":"This is a layering violation, it would be safer to have Sync return what you need and reduce the chance of a race being introduced in future.","created_at":"2018-04-03T07:37:08Z","updated_at":"2018-04-03T07:52:31Z","html_url":"https://github.com/prometheus/prometheus/pull/4005#discussion_r178736248","pull_request_url":"https://api.github.com/repos/prometheus/prometheus/pulls/4005","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/comments/178736248"},"html":{"href":"https://github.com/prometheus/prometheus/pull/4005#discussion_r178736248"},"pull_request":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/4005"}}},"pull_request":{"url":"https://api.github.com/repos/prometheus/prometheus/pulls/4005","id":177260105,"html_url":"https://github.com/prometheus/prometheus/pull/4005","diff_url":"https://github.com/prometheus/prometheus/pull/4005.diff","patch_url":"https://github.com/prometheus/prometheus/pull/4005.patch","issue_url":"https://api.github.com/repos/prometheus/prometheus/issues/4005","number":4005,"state":"open","locked":false,"title":"Races/3994","user":{"login":"krasi-georgiev","id":8903888,"avatar_url":"https://avatars0.githubusercontent.com/u/8903888?v=4","gravatar_id":"","url":"https://api.github.com/users/krasi-georgiev","html_url":"https://github.com/krasi-georgiev","followers_url":"https://api.github.com/users/krasi-georgiev/followers","following_url":"https://api.github.com/users/krasi-georgiev/following{/other_user}","gists_url":"https://api.github.com/users/krasi-georgiev/gists{/gist_id}","starred_url":"https://api.github.com/users/krasi-georgiev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krasi-georgiev/subscriptions","organizations_url":"https://api.github.com/users/krasi-georgiev/orgs","repos_url":"https://api.github.com/users/krasi-georgiev/repos","events_url":"https://api.github.com/users/krasi-georgiev/events{/privacy}","received_events_url":"https://api.github.com/users/krasi-georgiev/received_events","type":"User","site_admin":false},"body":"fixes #3994","created_at":"2018-03-24T21:36:45Z","updated_at":"2018-04-03T07:52:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8509336ba37d7dda04844ca5e9248c6ce0eb37f5","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/prometheus/prometheus/pulls/4005/commits","review_comments_url":"https://api.github.com/repos/prometheus/prometheus/pulls/4005/comments","review_comment_url":"https://api.github.com/repos/prometheus/prometheus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/prometheus/prometheus/issues/4005/comments","statuses_url":"https://api.github.com/repos/prometheus/prometheus/statuses/d2f71777c97ccc55b4cd8d5d0767d91d2a88454a","head":{"label":"krasi-georgiev:races/3994","ref":"races/3994","sha":"d2f71777c97ccc55b4cd8d5d0767d91d2a88454a","user":{"login":"krasi-georgiev","id":8903888,"avatar_url":"https://avatars0.githubusercontent.com/u/8903888?v=4","gravatar_id":"","url":"https://api.github.com/users/krasi-georgiev","html_url":"https://github.com/krasi-georgiev","followers_url":"https://api.github.com/users/krasi-georgiev/followers","following_url":"https://api.github.com/users/krasi-georgiev/following{/other_user}","gists_url":"https://api.github.com/users/krasi-georgiev/gists{/gist_id}","starred_url":"https://api.github.com/users/krasi-georgiev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krasi-georgiev/subscriptions","organizations_url":"https://api.github.com/users/krasi-georgiev/orgs","repos_url":"https://api.github.com/users/krasi-georgiev/repos","events_url":"https://api.github.com/users/krasi-georgiev/events{/privacy}","received_events_url":"https://api.github.com/users/krasi-georgiev/received_events","type":"User","site_admin":false},"repo":{"id":102344946,"name":"prometheus","full_name":"krasi-georgiev/prometheus","owner":{"login":"krasi-georgiev","id":8903888,"avatar_url":"https://avatars0.githubusercontent.com/u/8903888?v=4","gravatar_id":"","url":"https://api.github.com/users/krasi-georgiev","html_url":"https://github.com/krasi-georgiev","followers_url":"https://api.github.com/users/krasi-georgiev/followers","following_url":"https://api.github.com/users/krasi-georgiev/following{/other_user}","gists_url":"https://api.github.com/users/krasi-georgiev/gists{/gist_id}","starred_url":"https://api.github.com/users/krasi-georgiev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krasi-georgiev/subscriptions","organizations_url":"https://api.github.com/users/krasi-georgiev/orgs","repos_url":"https://api.github.com/users/krasi-georgiev/repos","events_url":"https://api.github.com/users/krasi-georgiev/events{/privacy}","received_events_url":"https://api.github.com/users/krasi-georgiev/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/krasi-georgiev/prometheus","description":"The Prometheus monitoring system and time series database.","fork":true,"url":"https://api.github.com/repos/krasi-georgiev/prometheus","forks_url":"https://api.github.com/repos/krasi-georgiev/prometheus/forks","keys_url":"https://api.github.com/repos/krasi-georgiev/prometheus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/krasi-georgiev/prometheus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/krasi-georgiev/prometheus/teams","hooks_url":"https://api.github.com/repos/krasi-georgiev/prometheus/hooks","issue_events_url":"https://api.github.com/repos/krasi-georgiev/prometheus/issues/events{/number}","events_url":"https://api.github.com/repos/krasi-georgiev/prometheus/events","assignees_url":"https://api.github.com/repos/krasi-georgiev/prometheus/assignees{/user}","branches_url":"https://api.github.com/repos/krasi-georgiev/prometheus/branches{/branch}","tags_url":"https://api.github.com/repos/krasi-georgiev/prometheus/tags","blobs_url":"https://api.github.com/repos/krasi-georgiev/prometheus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/krasi-georgiev/prometheus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/krasi-georgiev/prometheus/git/refs{/sha}","trees_url":"https://api.github.com/repos/krasi-georgiev/prometheus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/krasi-georgiev/prometheus/statuses/{sha}","languages_url":"https://api.github.com/repos/krasi-georgiev/prometheus/languages","stargazers_url":"https://api.github.com/repos/krasi-georgiev/prometheus/stargazers","contributors_url":"https://api.github.com/repos/krasi-georgiev/prometheus/contributors","subscribers_url":"https://api.github.com/repos/krasi-georgiev/prometheus/subscribers","subscription_url":"https://api.github.com/repos/krasi-georgiev/prometheus/subscription","commits_url":"https://api.github.com/repos/krasi-georgiev/prometheus/commits{/sha}","git_commits_url":"https://api.github.com/repos/krasi-georgiev/prometheus/git/commits{/sha}","comments_url":"https://api.github.com/repos/krasi-georgiev/prometheus/comments{/number}","issue_comment_url":"https://api.github.com/repos/krasi-georgiev/prometheus/issues/comments{/number}","contents_url":"https://api.github.com/repos/krasi-georgiev/prometheus/contents/{+path}","compare_url":"https://api.github.com/repos/krasi-georgiev/prometheus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/krasi-georgiev/prometheus/merges","archive_url":"https://api.github.com/repos/krasi-georgiev/prometheus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/krasi-georgiev/prometheus/downloads","issues_url":"https://api.github.com/repos/krasi-georgiev/prometheus/issues{/number}","pulls_url":"https://api.github.com/repos/krasi-georgiev/prometheus/pulls{/number}","milestones_url":"https://api.github.com/repos/krasi-georgiev/prometheus/milestones{/number}","notifications_url":"https://api.github.com/repos/krasi-georgiev/prometheus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/krasi-georgiev/prometheus/labels{/name}","releases_url":"https://api.github.com/repos/krasi-georgiev/prometheus/releases{/id}","deployments_url":"https://api.github.com/repos/krasi-georgiev/prometheus/deployments","created_at":"2017-09-04T09:40:04Z","updated_at":"2018-03-27T11:44:24Z","pushed_at":"2018-04-02T21:11:49Z","git_url":"git://github.com/krasi-georgiev/prometheus.git","ssh_url":"git@github.com:krasi-georgiev/prometheus.git","clone_url":"https://github.com/krasi-georgiev/prometheus.git","svn_url":"https://github.com/krasi-georgiev/prometheus","homepage":"https://prometheus.io/","size":37721,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"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":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"prometheus:release-2.2","ref":"release-2.2","sha":"6cf725c56d03871ead872f15f4521d481c35103e","user":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars3.githubusercontent.com/u/3380462?v=4","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"repo":{"id":6838921,"name":"prometheus","full_name":"prometheus/prometheus","owner":{"login":"prometheus","id":3380462,"avatar_url":"https://avatars3.githubusercontent.com/u/3380462?v=4","gravatar_id":"","url":"https://api.github.com/users/prometheus","html_url":"https://github.com/prometheus","followers_url":"https://api.github.com/users/prometheus/followers","following_url":"https://api.github.com/users/prometheus/following{/other_user}","gists_url":"https://api.github.com/users/prometheus/gists{/gist_id}","starred_url":"https://api.github.com/users/prometheus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/prometheus/subscriptions","organizations_url":"https://api.github.com/users/prometheus/orgs","repos_url":"https://api.github.com/users/prometheus/repos","events_url":"https://api.github.com/users/prometheus/events{/privacy}","received_events_url":"https://api.github.com/users/prometheus/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/prometheus/prometheus","description":"The Prometheus monitoring system and time series database.","fork":false,"url":"https://api.github.com/repos/prometheus/prometheus","forks_url":"https://api.github.com/repos/prometheus/prometheus/forks","keys_url":"https://api.github.com/repos/prometheus/prometheus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/prometheus/prometheus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/prometheus/prometheus/teams","hooks_url":"https://api.github.com/repos/prometheus/prometheus/hooks","issue_events_url":"https://api.github.com/repos/prometheus/prometheus/issues/events{/number}","events_url":"https://api.github.com/repos/prometheus/prometheus/events","assignees_url":"https://api.github.com/repos/prometheus/prometheus/assignees{/user}","branches_url":"https://api.github.com/repos/prometheus/prometheus/branches{/branch}","tags_url":"https://api.github.com/repos/prometheus/prometheus/tags","blobs_url":"https://api.github.com/repos/prometheus/prometheus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/prometheus/prometheus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/prometheus/prometheus/git/refs{/sha}","trees_url":"https://api.github.com/repos/prometheus/prometheus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/prometheus/prometheus/statuses/{sha}","languages_url":"https://api.github.com/repos/prometheus/prometheus/languages","stargazers_url":"https://api.github.com/repos/prometheus/prometheus/stargazers","contributors_url":"https://api.github.com/repos/prometheus/prometheus/contributors","subscribers_url":"https://api.github.com/repos/prometheus/prometheus/subscribers","subscription_url":"https://api.github.com/repos/prometheus/prometheus/subscription","commits_url":"https://api.github.com/repos/prometheus/prometheus/commits{/sha}","git_commits_url":"https://api.github.com/repos/prometheus/prometheus/git/commits{/sha}","comments_url":"https://api.github.com/repos/prometheus/prometheus/comments{/number}","issue_comment_url":"https://api.github.com/repos/prometheus/prometheus/issues/comments{/number}","contents_url":"https://api.github.com/repos/prometheus/prometheus/contents/{+path}","compare_url":"https://api.github.com/repos/prometheus/prometheus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/prometheus/prometheus/merges","archive_url":"https://api.github.com/repos/prometheus/prometheus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/prometheus/prometheus/downloads","issues_url":"https://api.github.com/repos/prometheus/prometheus/issues{/number}","pulls_url":"https://api.github.com/repos/prometheus/prometheus/pulls{/number}","milestones_url":"https://api.github.com/repos/prometheus/prometheus/milestones{/number}","notifications_url":"https://api.github.com/repos/prometheus/prometheus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/prometheus/prometheus/labels{/name}","releases_url":"https://api.github.com/repos/prometheus/prometheus/releases{/id}","deployments_url":"https://api.github.com/repos/prometheus/prometheus/deployments","created_at":"2012-11-24T11:14:12Z","updated_at":"2018-04-03T07:03:21Z","pushed_at":"2018-04-02T21:36:27Z","git_url":"git://github.com/prometheus/prometheus.git","ssh_url":"git@github.com:prometheus/prometheus.git","clone_url":"https://github.com/prometheus/prometheus.git","svn_url":"https://github.com/prometheus/prometheus","homepage":"https://prometheus.io/","size":35711,"stargazers_count":15607,"watchers_count":15607,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1957,"mirror_url":null,"archived":false,"open_issues_count":249,"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":1957,"open_issues":249,"watchers":15607,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/4005"},"html":{"href":"https://github.com/prometheus/prometheus/pull/4005"},"issue":{"href":"https://api.github.com/repos/prometheus/prometheus/issues/4005"},"comments":{"href":"https://api.github.com/repos/prometheus/prometheus/issues/4005/comments"},"review_comments":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/4005/comments"},"review_comment":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/prometheus/prometheus/pulls/4005/commits"},"statuses":{"href":"https://api.github.com/repos/prometheus/prometheus/statuses/d2f71777c97ccc55b4cd8d5d0767d91d2a88454a"}},"author_association":"OWNER"}}
{"actor":{"display_login":"brian-brazil"}}