{"action":"created","comment":{"url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/comments/78748559","id":78748559,"diff_hunk":"@@ -60,39 +66,74 @@ func (h *ScalingHandler) HandleScale(w http.ResponseWriter, r *http.Request, var\n func (h *ScalingHandler) Scale(appId string, trigger *models.Trigger) (int, error) {\n \tlogger := h.logger.WithData(lager.Data{\"appId\": appId})\n \n-\tpolicy, err := h.database.GetAppPolicy(appId)\n+\thistory := &models.AppScalingHistory{\n+\t\tAppId:        appId,\n+\t\tTimestamp:    h.hClock.Now().UnixNano(),\n+\t\tScalingType:  models.ScalingTypeDynamic,\n+\t\tOldInstances: -1,\n+\t\tNewInstances: -1,\n+\t\tReason:       getScalingReason(trigger),\n+\t}\n+\n+\tpolicy, err := h.policyDB.GetAppPolicy(appId)\n \tif err != nil {\n \t\tlogger.Error(\"scale-get-app-policy\", err)\n+\t\thistory.Status = models.ScalingStatusFailed\n+\t\thistory.Error = \"failed to get scaling policy\"\n+\t\th.historyDB.SaveScalingHistory(history)\n \t\treturn -1, err\n \t}\n \n \tinstances, err := h.cfClient.GetAppInstances(appId)\n \tif err != nil {\n \t\tlogger.Error(\"scale-get-app-instances\", err)\n+\t\thistory.Status = models.ScalingStatusFailed\n+\t\thistory.Error = \"failed to get app instances\"\n+\t\th.historyDB.SaveScalingHistory(history)\n \t\treturn -1, err\n \t}\n+\thistory.OldInstances = instances\n \n \tvar newInstances int\n-\tnewInstances, err = h.ComputeNewInstances(instances, trigger.Adjustment, policy.InstanceMin, policy.InstanceMax)\n+\tnewInstances, err = h.ComputeNewInstances(instances, trigger.Adjustment)\n \tif err != nil {\n-\t\tlogger.Error(\"scale-compute-new-instance\", err, lager.Data{\"instances\": instances, \"adjustment\": trigger.Adjustment, \"instanceMin\": policy.InstanceMin, \"InstanceMax\": policy.InstanceMax})\n+\t\tlogger.Error(\"scale-compute-new-instance\", err, lager.Data{\"instances\": instances, \"adjustment\": trigger.Adjustment})\n+\t\thistory.Status = models.ScalingStatusFailed\n+\t\thistory.Error = \"failed to compute new app instances\"\n+\t\th.historyDB.SaveScalingHistory(history)\n \t\treturn -1, err\n \t}\n \n-\tlogger.Info(\"Scale\", lager.Data{\"trigger\": trigger, \"instanceMin\": policy.InstanceMin, \"InstanceMax\": policy.InstanceMax, \"currentInstances\": instances, \"newInstances\": newInstances})\n+\tif newInstances > policy.InstanceMax {\n+\t\tnewInstances = policy.InstanceMax\n+\t\thistory.Message = fmt.Sprintf(\"limit to max instances %d\", policy.InstanceMax)","path":"src/scalingengine/server/scaling_handler.go","position":88,"original_position":88,"commit_id":"79884569a8b1591293677ed083f03b8ef617244e","original_commit_id":"79884569a8b1591293677ed083f03b8ef617244e","user":{"login":"fraenkel","id":929377,"avatar_url":"https://avatars.githubusercontent.com/u/929377?v=3","gravatar_id":"","url":"https://api.github.com/users/fraenkel","html_url":"https://github.com/fraenkel","followers_url":"https://api.github.com/users/fraenkel/followers","following_url":"https://api.github.com/users/fraenkel/following{/other_user}","gists_url":"https://api.github.com/users/fraenkel/gists{/gist_id}","starred_url":"https://api.github.com/users/fraenkel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fraenkel/subscriptions","organizations_url":"https://api.github.com/users/fraenkel/orgs","repos_url":"https://api.github.com/users/fraenkel/repos","events_url":"https://api.github.com/users/fraenkel/events{/privacy}","received_events_url":"https://api.github.com/users/fraenkel/received_events","type":"User","site_admin":false},"body":"exceeded max instances? limited by max instances?","created_at":"2016-09-14T13:35:03Z","updated_at":"2016-09-14T13:35:03Z","html_url":"https://github.com/cloudfoundry-incubator/app-autoscaler/pull/92#discussion_r78748559","pull_request_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/92","_links":{"self":{"href":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/comments/78748559"},"html":{"href":"https://github.com/cloudfoundry-incubator/app-autoscaler/pull/92#discussion_r78748559"},"pull_request":{"href":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/92"}}},"pull_request":{"url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/92","id":85134282,"html_url":"https://github.com/cloudfoundry-incubator/app-autoscaler/pull/92","diff_url":"https://github.com/cloudfoundry-incubator/app-autoscaler/pull/92.diff","patch_url":"https://github.com/cloudfoundry-incubator/app-autoscaler/pull/92.patch","issue_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/issues/92","number":92,"state":"open","locked":false,"title":"record scaling history","user":{"login":"boyang9527","id":5013402,"avatar_url":"https://avatars.githubusercontent.com/u/5013402?v=3","gravatar_id":"","url":"https://api.github.com/users/boyang9527","html_url":"https://github.com/boyang9527","followers_url":"https://api.github.com/users/boyang9527/followers","following_url":"https://api.github.com/users/boyang9527/following{/other_user}","gists_url":"https://api.github.com/users/boyang9527/gists{/gist_id}","starred_url":"https://api.github.com/users/boyang9527/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boyang9527/subscriptions","organizations_url":"https://api.github.com/users/boyang9527/orgs","repos_url":"https://api.github.com/users/boyang9527/repos","events_url":"https://api.github.com/users/boyang9527/events{/privacy}","received_events_url":"https://api.github.com/users/boyang9527/received_events","type":"User","site_admin":false},"body":"[#119505611]\r\n\r\n- add histroyDB interface to save and retrieve scaling history\r\n- REST API to get scaling history\r\n- Store scaling history when there is scaling action\r\n- other refactoring","created_at":"2016-09-13T22:06:27Z","updated_at":"2016-09-14T13:35:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ea70d8bc7c82829916de3355c6374282992b1856","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/92/commits","review_comments_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/92/comments","review_comment_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/issues/92/comments","statuses_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/statuses/79884569a8b1591293677ed083f03b8ef617244e","head":{"label":"boyang9527:history","ref":"history","sha":"79884569a8b1591293677ed083f03b8ef617244e","user":{"login":"boyang9527","id":5013402,"avatar_url":"https://avatars.githubusercontent.com/u/5013402?v=3","gravatar_id":"","url":"https://api.github.com/users/boyang9527","html_url":"https://github.com/boyang9527","followers_url":"https://api.github.com/users/boyang9527/followers","following_url":"https://api.github.com/users/boyang9527/following{/other_user}","gists_url":"https://api.github.com/users/boyang9527/gists{/gist_id}","starred_url":"https://api.github.com/users/boyang9527/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boyang9527/subscriptions","organizations_url":"https://api.github.com/users/boyang9527/orgs","repos_url":"https://api.github.com/users/boyang9527/repos","events_url":"https://api.github.com/users/boyang9527/events{/privacy}","received_events_url":"https://api.github.com/users/boyang9527/received_events","type":"User","site_admin":false},"repo":{"id":56274020,"name":"app-autoscaler","full_name":"boyang9527/app-autoscaler","owner":{"login":"boyang9527","id":5013402,"avatar_url":"https://avatars.githubusercontent.com/u/5013402?v=3","gravatar_id":"","url":"https://api.github.com/users/boyang9527","html_url":"https://github.com/boyang9527","followers_url":"https://api.github.com/users/boyang9527/followers","following_url":"https://api.github.com/users/boyang9527/following{/other_user}","gists_url":"https://api.github.com/users/boyang9527/gists{/gist_id}","starred_url":"https://api.github.com/users/boyang9527/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/boyang9527/subscriptions","organizations_url":"https://api.github.com/users/boyang9527/orgs","repos_url":"https://api.github.com/users/boyang9527/repos","events_url":"https://api.github.com/users/boyang9527/events{/privacy}","received_events_url":"https://api.github.com/users/boyang9527/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/boyang9527/app-autoscaler","description":"Auto Scaling for CF Applications","fork":true,"url":"https://api.github.com/repos/boyang9527/app-autoscaler","forks_url":"https://api.github.com/repos/boyang9527/app-autoscaler/forks","keys_url":"https://api.github.com/repos/boyang9527/app-autoscaler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/boyang9527/app-autoscaler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/boyang9527/app-autoscaler/teams","hooks_url":"https://api.github.com/repos/boyang9527/app-autoscaler/hooks","issue_events_url":"https://api.github.com/repos/boyang9527/app-autoscaler/issues/events{/number}","events_url":"https://api.github.com/repos/boyang9527/app-autoscaler/events","assignees_url":"https://api.github.com/repos/boyang9527/app-autoscaler/assignees{/user}","branches_url":"https://api.github.com/repos/boyang9527/app-autoscaler/branches{/branch}","tags_url":"https://api.github.com/repos/boyang9527/app-autoscaler/tags","blobs_url":"https://api.github.com/repos/boyang9527/app-autoscaler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/boyang9527/app-autoscaler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/boyang9527/app-autoscaler/git/refs{/sha}","trees_url":"https://api.github.com/repos/boyang9527/app-autoscaler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/boyang9527/app-autoscaler/statuses/{sha}","languages_url":"https://api.github.com/repos/boyang9527/app-autoscaler/languages","stargazers_url":"https://api.github.com/repos/boyang9527/app-autoscaler/stargazers","contributors_url":"https://api.github.com/repos/boyang9527/app-autoscaler/contributors","subscribers_url":"https://api.github.com/repos/boyang9527/app-autoscaler/subscribers","subscription_url":"https://api.github.com/repos/boyang9527/app-autoscaler/subscription","commits_url":"https://api.github.com/repos/boyang9527/app-autoscaler/commits{/sha}","git_commits_url":"https://api.github.com/repos/boyang9527/app-autoscaler/git/commits{/sha}","comments_url":"https://api.github.com/repos/boyang9527/app-autoscaler/comments{/number}","issue_comment_url":"https://api.github.com/repos/boyang9527/app-autoscaler/issues/comments{/number}","contents_url":"https://api.github.com/repos/boyang9527/app-autoscaler/contents/{+path}","compare_url":"https://api.github.com/repos/boyang9527/app-autoscaler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/boyang9527/app-autoscaler/merges","archive_url":"https://api.github.com/repos/boyang9527/app-autoscaler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/boyang9527/app-autoscaler/downloads","issues_url":"https://api.github.com/repos/boyang9527/app-autoscaler/issues{/number}","pulls_url":"https://api.github.com/repos/boyang9527/app-autoscaler/pulls{/number}","milestones_url":"https://api.github.com/repos/boyang9527/app-autoscaler/milestones{/number}","notifications_url":"https://api.github.com/repos/boyang9527/app-autoscaler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/boyang9527/app-autoscaler/labels{/name}","releases_url":"https://api.github.com/repos/boyang9527/app-autoscaler/releases{/id}","deployments_url":"https://api.github.com/repos/boyang9527/app-autoscaler/deployments","created_at":"2016-04-14T22:31:10Z","updated_at":"2016-04-14T22:31:12Z","pushed_at":"2016-09-13T22:02:40Z","git_url":"git://github.com/boyang9527/app-autoscaler.git","ssh_url":"git@github.com:boyang9527/app-autoscaler.git","clone_url":"https://github.com/boyang9527/app-autoscaler.git","svn_url":"https://github.com/boyang9527/app-autoscaler","homepage":"","size":1669,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"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":"develop"}},"base":{"label":"cloudfoundry-incubator:develop","ref":"develop","sha":"3d5523a8f862be2ee29f8582cd245e9db52e6389","user":{"login":"cloudfoundry-incubator","id":5680605,"avatar_url":"https://avatars.githubusercontent.com/u/5680605?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudfoundry-incubator","html_url":"https://github.com/cloudfoundry-incubator","followers_url":"https://api.github.com/users/cloudfoundry-incubator/followers","following_url":"https://api.github.com/users/cloudfoundry-incubator/following{/other_user}","gists_url":"https://api.github.com/users/cloudfoundry-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudfoundry-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudfoundry-incubator/subscriptions","organizations_url":"https://api.github.com/users/cloudfoundry-incubator/orgs","repos_url":"https://api.github.com/users/cloudfoundry-incubator/repos","events_url":"https://api.github.com/users/cloudfoundry-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/cloudfoundry-incubator/received_events","type":"Organization","site_admin":false},"repo":{"id":55270767,"name":"app-autoscaler","full_name":"cloudfoundry-incubator/app-autoscaler","owner":{"login":"cloudfoundry-incubator","id":5680605,"avatar_url":"https://avatars.githubusercontent.com/u/5680605?v=3","gravatar_id":"","url":"https://api.github.com/users/cloudfoundry-incubator","html_url":"https://github.com/cloudfoundry-incubator","followers_url":"https://api.github.com/users/cloudfoundry-incubator/followers","following_url":"https://api.github.com/users/cloudfoundry-incubator/following{/other_user}","gists_url":"https://api.github.com/users/cloudfoundry-incubator/gists{/gist_id}","starred_url":"https://api.github.com/users/cloudfoundry-incubator/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloudfoundry-incubator/subscriptions","organizations_url":"https://api.github.com/users/cloudfoundry-incubator/orgs","repos_url":"https://api.github.com/users/cloudfoundry-incubator/repos","events_url":"https://api.github.com/users/cloudfoundry-incubator/events{/privacy}","received_events_url":"https://api.github.com/users/cloudfoundry-incubator/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloudfoundry-incubator/app-autoscaler","description":"Auto Scaling for CF Applications","fork":false,"url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler","forks_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/forks","keys_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/teams","hooks_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/hooks","issue_events_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/issues/events{/number}","events_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/events","assignees_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/assignees{/user}","branches_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/branches{/branch}","tags_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/tags","blobs_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/statuses/{sha}","languages_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/languages","stargazers_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/stargazers","contributors_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/contributors","subscribers_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/subscribers","subscription_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/subscription","commits_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/contents/{+path}","compare_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/merges","archive_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/downloads","issues_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/issues{/number}","pulls_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls{/number}","milestones_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/milestones{/number}","notifications_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/labels{/name}","releases_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/releases{/id}","deployments_url":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/deployments","created_at":"2016-04-02T00:47:11Z","updated_at":"2016-09-07T08:33:02Z","pushed_at":"2016-09-14T09:04:32Z","git_url":"git://github.com/cloudfoundry-incubator/app-autoscaler.git","ssh_url":"git@github.com:cloudfoundry-incubator/app-autoscaler.git","clone_url":"https://github.com/cloudfoundry-incubator/app-autoscaler.git","svn_url":"https://github.com/cloudfoundry-incubator/app-autoscaler","homepage":"","size":1815,"stargazers_count":10,"watchers_count":10,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":9,"mirror_url":null,"open_issues_count":4,"forks":9,"open_issues":4,"watchers":10,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/92"},"html":{"href":"https://github.com/cloudfoundry-incubator/app-autoscaler/pull/92"},"issue":{"href":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/issues/92"},"comments":{"href":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/issues/92/comments"},"review_comments":{"href":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/92/comments"},"review_comment":{"href":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/pulls/92/commits"},"statuses":{"href":"https://api.github.com/repos/cloudfoundry-incubator/app-autoscaler/statuses/79884569a8b1591293677ed083f03b8ef617244e"}}}}
{"actor":{"display_login":"fraenkel"}}