{"action":"closed","number":42148,"pull_request":{"url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/42148","id":108071964,"html_url":"https://github.com/kubernetes/kubernetes/pull/42148","diff_url":"https://github.com/kubernetes/kubernetes/pull/42148.diff","patch_url":"https://github.com/kubernetes/kubernetes/pull/42148.patch","issue_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/42148","number":42148,"state":"closed","locked":false,"title":"Should wrap the calculation of elapsed time","user":{"login":"mYmNeo","id":1198961,"avatar_url":"https://avatars2.githubusercontent.com/u/1198961?v=3","gravatar_id":"","url":"https://api.github.com/users/mYmNeo","html_url":"https://github.com/mYmNeo","followers_url":"https://api.github.com/users/mYmNeo/followers","following_url":"https://api.github.com/users/mYmNeo/following{/other_user}","gists_url":"https://api.github.com/users/mYmNeo/gists{/gist_id}","starred_url":"https://api.github.com/users/mYmNeo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mYmNeo/subscriptions","organizations_url":"https://api.github.com/users/mYmNeo/orgs","repos_url":"https://api.github.com/users/mYmNeo/repos","events_url":"https://api.github.com/users/mYmNeo/events{/privacy}","received_events_url":"https://api.github.com/users/mYmNeo/received_events","type":"User","site_admin":false},"body":"This PR try to fix the wrong latency of `scheduleOne`. \r\n\r\nAt https://github.com/kubernetes/kubernetes/blob/master/plugin/pkg/scheduler/scheduler.go#L191\r\n```\r\n\tgo func() {\r\n\t\tdefer metrics.E2eSchedulingLatency.Observe(metrics.SinceInMicroseconds(start)) /** I think this code wants to get the total time of invoking `scheduleOne`**/\r\n\r\n\t\tb := &v1.Binding{\r\n\t\t\tObjectMeta: metav1.ObjectMeta{Namespace: pod.Namespace, Name: pod.Name},\r\n\t\t\tTarget: v1.ObjectReference{\r\n\t\t\t\tKind: \"Node\",\r\n\t\t\t\tName: dest,\r\n\t\t\t},\r\n\t\t}\r\n\r\n\t\tbindingStart := time.Now()\r\n\t\t// If binding succeeded then PodScheduled condition will be updated in apiserver so that\r\n\t\t// it's atomic with setting host.\r\n\t\terr := s.config.Binder.Bind(b)\r\n\t\tif err := s.config.SchedulerCache.FinishBinding(&assumed); err != nil {\r\n\t\t\tglog.Errorf(\"scheduler cache FinishBinding failed: %v\", err)\r\n\t\t}\r\n\t\tif err != nil {\r\n\t\t\tglog.V(1).Infof(\"Failed to bind pod: %v/%v\", pod.Namespace, pod.Name)\r\n\t\t\tif err := s.config.SchedulerCache.ForgetPod(&assumed); err != nil {\r\n\t\t\t\tglog.Errorf(\"scheduler cache ForgetPod failed: %v\", err)\r\n\t\t\t}\r\n\t\t\ts.config.Error(pod, err)\r\n\t\t\ts.config.Recorder.Eventf(pod, v1.EventTypeNormal, \"FailedScheduling\", \"Binding rejected: %v\", err)\r\n\t\t\ts.config.PodConditionUpdater.Update(pod, &v1.PodCondition{\r\n\t\t\t\tType:   v1.PodScheduled,\r\n\t\t\t\tStatus: v1.ConditionFalse,\r\n\t\t\t\tReason: \"BindingRejected\",\r\n\t\t\t})\r\n\t\t\treturn\r\n\t\t}\r\n\t\tmetrics.BindingLatency.Observe(metrics.SinceInMicroseconds(bindingStart))\r\n\t\ts.config.Recorder.Eventf(pod, v1.EventTypeNormal, \"Scheduled\", \"Successfully assigned %v to %v\", pod.Name, dest)\r\n\t}()\r\n```\r\nIt seems that the keyword `defer` has tried to pre-calculate the parameters. So the reported latency was wrong.  \r\nHere is an example:\r\n```\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"sync\"\r\n\t\"time\"\r\n)\r\n\r\nvar (\r\n\twg = sync.WaitGroup{}\r\n)\r\n\r\nfunc elapsed(t time.Time) float64 {\r\n\treturn time.Since(t).Seconds()\r\n}\r\n\r\nfunc report(pass float64, msg string) {\r\n\tfmt.Printf(\"%s duration: %e\\n\", msg, pass)\r\n}\r\n\r\nfunc test() {\r\n\tstartWithoutFix := time.Now()\r\n\r\n\twg.Add(2)\r\n\r\n\t// Without fix\r\n\tgo func() {\r\n\t\tdefer report(elapsed(startWithoutFix), \"Without fix\")\r\n\t\ttime.Sleep(time.Second * 5)\r\n\t\twg.Done()\r\n\t}()\r\n\r\n\t// With fix\r\n\tstartWithFix := time.Now()\r\n\tgo func() {\r\n\t\tdefer func() {\r\n\t\t\treport(elapsed(startWithFix), \"With fix\")\r\n\t\t}()\r\n\r\n\t\ttime.Sleep(time.Second * 5)\r\n\t\twg.Done()\r\n\t}()\r\n}\r\n\r\nfunc main() {\r\n\ttest()\r\n\twg.Wait()\r\n}\r\n\r\n# go run test.go\r\nWith fix duration: 5.000262e+00\r\nWithout fix duration: 3.062900e-05\r\n```\r\nSigned-off-by: thomassong <thomassong@tencent.com>\r\n","created_at":"2017-02-27T09:05:34Z","updated_at":"2017-04-14T02:36:36Z","closed_at":"2017-04-14T02:36:36Z","merged_at":null,"merge_commit_sha":"ac036fb745bda38e68bbc28ae275375eb4a88b29","assignee":{"login":"davidopp","id":8264113,"avatar_url":"https://avatars1.githubusercontent.com/u/8264113?v=3","gravatar_id":"","url":"https://api.github.com/users/davidopp","html_url":"https://github.com/davidopp","followers_url":"https://api.github.com/users/davidopp/followers","following_url":"https://api.github.com/users/davidopp/following{/other_user}","gists_url":"https://api.github.com/users/davidopp/gists{/gist_id}","starred_url":"https://api.github.com/users/davidopp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidopp/subscriptions","organizations_url":"https://api.github.com/users/davidopp/orgs","repos_url":"https://api.github.com/users/davidopp/repos","events_url":"https://api.github.com/users/davidopp/events{/privacy}","received_events_url":"https://api.github.com/users/davidopp/received_events","type":"User","site_admin":false},"assignees":[{"login":"davidopp","id":8264113,"avatar_url":"https://avatars1.githubusercontent.com/u/8264113?v=3","gravatar_id":"","url":"https://api.github.com/users/davidopp","html_url":"https://github.com/davidopp","followers_url":"https://api.github.com/users/davidopp/followers","following_url":"https://api.github.com/users/davidopp/following{/other_user}","gists_url":"https://api.github.com/users/davidopp/gists{/gist_id}","starred_url":"https://api.github.com/users/davidopp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davidopp/subscriptions","organizations_url":"https://api.github.com/users/davidopp/orgs","repos_url":"https://api.github.com/users/davidopp/repos","events_url":"https://api.github.com/users/davidopp/events{/privacy}","received_events_url":"https://api.github.com/users/davidopp/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/42148/commits","review_comments_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/42148/comments","review_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/42148/comments","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/a270fb993436892340f4bd89d15fe1062323b049","head":{"label":"mYmNeo:metric","ref":"metric","sha":"a270fb993436892340f4bd89d15fe1062323b049","user":{"login":"mYmNeo","id":1198961,"avatar_url":"https://avatars2.githubusercontent.com/u/1198961?v=3","gravatar_id":"","url":"https://api.github.com/users/mYmNeo","html_url":"https://github.com/mYmNeo","followers_url":"https://api.github.com/users/mYmNeo/followers","following_url":"https://api.github.com/users/mYmNeo/following{/other_user}","gists_url":"https://api.github.com/users/mYmNeo/gists{/gist_id}","starred_url":"https://api.github.com/users/mYmNeo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mYmNeo/subscriptions","organizations_url":"https://api.github.com/users/mYmNeo/orgs","repos_url":"https://api.github.com/users/mYmNeo/repos","events_url":"https://api.github.com/users/mYmNeo/events{/privacy}","received_events_url":"https://api.github.com/users/mYmNeo/received_events","type":"User","site_admin":false},"repo":{"id":54623656,"name":"kubernetes","full_name":"mYmNeo/kubernetes","owner":{"login":"mYmNeo","id":1198961,"avatar_url":"https://avatars2.githubusercontent.com/u/1198961?v=3","gravatar_id":"","url":"https://api.github.com/users/mYmNeo","html_url":"https://github.com/mYmNeo","followers_url":"https://api.github.com/users/mYmNeo/followers","following_url":"https://api.github.com/users/mYmNeo/following{/other_user}","gists_url":"https://api.github.com/users/mYmNeo/gists{/gist_id}","starred_url":"https://api.github.com/users/mYmNeo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mYmNeo/subscriptions","organizations_url":"https://api.github.com/users/mYmNeo/orgs","repos_url":"https://api.github.com/users/mYmNeo/repos","events_url":"https://api.github.com/users/mYmNeo/events{/privacy}","received_events_url":"https://api.github.com/users/mYmNeo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mYmNeo/kubernetes","description":"Container Cluster Manager from Google","fork":true,"url":"https://api.github.com/repos/mYmNeo/kubernetes","forks_url":"https://api.github.com/repos/mYmNeo/kubernetes/forks","keys_url":"https://api.github.com/repos/mYmNeo/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mYmNeo/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mYmNeo/kubernetes/teams","hooks_url":"https://api.github.com/repos/mYmNeo/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/mYmNeo/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/mYmNeo/kubernetes/events","assignees_url":"https://api.github.com/repos/mYmNeo/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/mYmNeo/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/mYmNeo/kubernetes/tags","blobs_url":"https://api.github.com/repos/mYmNeo/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mYmNeo/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mYmNeo/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/mYmNeo/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mYmNeo/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/mYmNeo/kubernetes/languages","stargazers_url":"https://api.github.com/repos/mYmNeo/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/mYmNeo/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/mYmNeo/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/mYmNeo/kubernetes/subscription","commits_url":"https://api.github.com/repos/mYmNeo/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/mYmNeo/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/mYmNeo/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/mYmNeo/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/mYmNeo/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/mYmNeo/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mYmNeo/kubernetes/merges","archive_url":"https://api.github.com/repos/mYmNeo/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mYmNeo/kubernetes/downloads","issues_url":"https://api.github.com/repos/mYmNeo/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/mYmNeo/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/mYmNeo/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/mYmNeo/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mYmNeo/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/mYmNeo/kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/mYmNeo/kubernetes/deployments","created_at":"2016-03-24T07:40:38Z","updated_at":"2016-03-24T07:40:51Z","pushed_at":"2017-04-14T01:30:45Z","git_url":"git://github.com/mYmNeo/kubernetes.git","ssh_url":"git@github.com:mYmNeo/kubernetes.git","clone_url":"https://github.com/mYmNeo/kubernetes.git","svn_url":"https://github.com/mYmNeo/kubernetes","homepage":"http://kubernetes.io","size":422599,"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,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"kubernetes:master","ref":"master","sha":"61a2bd64a212f76402332fcfad2033f57fe88034","user":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars1.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"repo":{"id":20580498,"name":"kubernetes","full_name":"kubernetes/kubernetes","owner":{"login":"kubernetes","id":13629408,"avatar_url":"https://avatars1.githubusercontent.com/u/13629408?v=3","gravatar_id":"","url":"https://api.github.com/users/kubernetes","html_url":"https://github.com/kubernetes","followers_url":"https://api.github.com/users/kubernetes/followers","following_url":"https://api.github.com/users/kubernetes/following{/other_user}","gists_url":"https://api.github.com/users/kubernetes/gists{/gist_id}","starred_url":"https://api.github.com/users/kubernetes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kubernetes/subscriptions","organizations_url":"https://api.github.com/users/kubernetes/orgs","repos_url":"https://api.github.com/users/kubernetes/repos","events_url":"https://api.github.com/users/kubernetes/events{/privacy}","received_events_url":"https://api.github.com/users/kubernetes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/kubernetes/kubernetes","description":"Production-Grade Container Scheduling and Management","fork":false,"url":"https://api.github.com/repos/kubernetes/kubernetes","forks_url":"https://api.github.com/repos/kubernetes/kubernetes/forks","keys_url":"https://api.github.com/repos/kubernetes/kubernetes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kubernetes/kubernetes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kubernetes/kubernetes/teams","hooks_url":"https://api.github.com/repos/kubernetes/kubernetes/hooks","issue_events_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/events{/number}","events_url":"https://api.github.com/repos/kubernetes/kubernetes/events","assignees_url":"https://api.github.com/repos/kubernetes/kubernetes/assignees{/user}","branches_url":"https://api.github.com/repos/kubernetes/kubernetes/branches{/branch}","tags_url":"https://api.github.com/repos/kubernetes/kubernetes/tags","blobs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kubernetes/kubernetes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kubernetes/kubernetes/git/refs{/sha}","trees_url":"https://api.github.com/repos/kubernetes/kubernetes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kubernetes/kubernetes/statuses/{sha}","languages_url":"https://api.github.com/repos/kubernetes/kubernetes/languages","stargazers_url":"https://api.github.com/repos/kubernetes/kubernetes/stargazers","contributors_url":"https://api.github.com/repos/kubernetes/kubernetes/contributors","subscribers_url":"https://api.github.com/repos/kubernetes/kubernetes/subscribers","subscription_url":"https://api.github.com/repos/kubernetes/kubernetes/subscription","commits_url":"https://api.github.com/repos/kubernetes/kubernetes/commits{/sha}","git_commits_url":"https://api.github.com/repos/kubernetes/kubernetes/git/commits{/sha}","comments_url":"https://api.github.com/repos/kubernetes/kubernetes/comments{/number}","issue_comment_url":"https://api.github.com/repos/kubernetes/kubernetes/issues/comments{/number}","contents_url":"https://api.github.com/repos/kubernetes/kubernetes/contents/{+path}","compare_url":"https://api.github.com/repos/kubernetes/kubernetes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kubernetes/kubernetes/merges","archive_url":"https://api.github.com/repos/kubernetes/kubernetes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kubernetes/kubernetes/downloads","issues_url":"https://api.github.com/repos/kubernetes/kubernetes/issues{/number}","pulls_url":"https://api.github.com/repos/kubernetes/kubernetes/pulls{/number}","milestones_url":"https://api.github.com/repos/kubernetes/kubernetes/milestones{/number}","notifications_url":"https://api.github.com/repos/kubernetes/kubernetes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kubernetes/kubernetes/labels{/name}","releases_url":"https://api.github.com/repos/kubernetes/kubernetes/releases{/id}","deployments_url":"https://api.github.com/repos/kubernetes/kubernetes/deployments","created_at":"2014-06-06T22:56:04Z","updated_at":"2017-04-14T02:26:37Z","pushed_at":"2017-04-14T02:28:50Z","git_url":"git://github.com/kubernetes/kubernetes.git","ssh_url":"git@github.com:kubernetes/kubernetes.git","clone_url":"https://github.com/kubernetes/kubernetes.git","svn_url":"https://github.com/kubernetes/kubernetes","homepage":"http://kubernetes.io","size":621596,"stargazers_count":22382,"watchers_count":22382,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":7762,"mirror_url":null,"open_issues_count":5666,"forks":7762,"open_issues":5666,"watchers":22382,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/42148"},"html":{"href":"https://github.com/kubernetes/kubernetes/pull/42148"},"issue":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/42148"},"comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/issues/42148/comments"},"review_comments":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/42148/comments"},"review_comment":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kubernetes/kubernetes/pulls/42148/commits"},"statuses":{"href":"https://api.github.com/repos/kubernetes/kubernetes/statuses/a270fb993436892340f4bd89d15fe1062323b049"}},"merged":false,"mergeable":true,"rebaseable":false,"mergeable_state":"unstable","merged_by":null,"comments":6,"review_comments":2,"maintainer_can_modify":false,"commits":1,"additions":3,"deletions":1,"changed_files":1}}
{"actor":{"display_login":"mYmNeo"}}