{"action":"created","comment":{"url":"https://api.github.com/repos/percona/pmm-agent/pulls/comments/236942463","pull_request_review_id":179125132,"id":236942463,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNjk0MjQ2Mw==","diff_hunk":"@@ -0,0 +1,188 @@\n+// pmm-agent\n+// Copyright (C) 2018 Percona LLC\n+//\n+// This program is free software: you can redistribute it and/or modify\n+// it under the terms of the GNU Affero General Public License as published by\n+// the Free Software Foundation, either version 3 of the License, or\n+// (at your option) any later version.\n+//\n+// This program is distributed in the hope that it will be useful,\n+// but WITHOUT ANY WARRANTY; without even the implied warranty of\n+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n+// GNU Affero General Public License for more details.\n+//\n+// You should have received a copy of the GNU Affero General Public License\n+// along with this program. If not, see <https://www.gnu.org/licenses/>.\n+\n+package runner\n+\n+import (\n+\t\"bytes\"\n+\t\"context\"\n+\t\"fmt\"\n+\t\"io\"\n+\t\"math\"\n+\t\"math/rand\"\n+\t\"os\"\n+\t\"os/exec\"\n+\t\"text/template\"\n+\t\"time\"\n+\n+\t\"github.com/sirupsen/logrus\"\n+\n+\t\"github.com/percona/pmm-agent/utils/logger\"\n+\t\"github.com/percona/pmm/api/inventory\"\n+)\n+\n+type State int32\n+\n+const (\n+\tINVALID State = 0\n+\tRUNNING State = 1\n+\tSTOPPED State = 2\n+\tCRASHED State = 3\n+)\n+\n+type AgentParams struct {\n+\tAgentId uint32\n+\tType    inventory.AgentType\n+\tArgs    []string\n+\tEnv     []string\n+\tConfigs map[string]string\n+\tPort    uint32\n+}\n+\n+type SubAgent struct {\n+\tcmd    *exec.Cmd\n+\tlog    *logger.CircularWriter\n+\tl      *logrus.Entry\n+\tstate  State\n+\tparams *AgentParams\n+\n+\trestartChan  chan struct{}\n+\trestartCount int\n+}\n+\n+type templateParams struct {\n+\tListenPort uint32\n+}\n+\n+func NewSubAgent(params *AgentParams) *SubAgent {\n+\tl := logrus.WithField(\"component\", \"runner\").\n+\t\tWithField(\"agentID\", params.AgentId).\n+\t\tWithField(\"type\", params.Type)\n+\n+\treturn &SubAgent{\n+\t\tparams: params,\n+\t\tlog:    logger.New(10),\n+\t\tl:      l,\n+\t\tstate:  INVALID,\n+\t}\n+}\n+\n+func (m *SubAgent) Start(ctx context.Context) error {\n+\tif m.GetState() == RUNNING {\n+\t\treturn fmt.Errorf(\"can't start the process, process is already running\")\n+\t}\n+\tname := m.binary()\n+\targs, err := m.args()\n+\tif err != nil {\n+\t\tm.l.Errorln(err)\n+\t\treturn err\n+\t}\n+\tcmd := exec.CommandContext(ctx, name, args...)\n+\tcmd.Env = m.params.Env\n+\tcmd.Stdout = io.MultiWriter(os.Stdout, m.log)\n+\tcmd.Stderr = io.MultiWriter(os.Stderr, m.log)\n+\n+\terr = cmd.Start()\n+\tif err != nil {\n+\t\tm.state = CRASHED\n+\t\treturn err\n+\t}\n+\tm.cmd = cmd\n+\tm.state = RUNNING\n+\tm.restartChan = make(chan struct{})\n+\tgo func() {\n+\t\t_ = m.cmd.Wait()\n+\t\tif m.state != STOPPED {\n+\t\t\tm.state = CRASHED\n+\t\t\tclose(m.restartChan)\n+\t\t}\n+\t}()\n+\treturn nil\n+}\n+\n+func (m *SubAgent) args() ([]string, error) {\n+\tparams := templateParams{\n+\t\tListenPort: m.params.Port,\n+\t}\n+\tvar args []string\n+\tfor _, arg := range m.params.Args {\n+\t\tbuffer := &bytes.Buffer{}\n+\t\ttmpl, err := template.New(arg).Parse(arg)\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\terr = tmpl.Execute(buffer, params)\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\targs = append(args, buffer.String())\n+\t}\n+\treturn args, nil\n+}\n+\n+func (m *SubAgent) Done() <-chan struct{} {","path":"runner/sub-agents.go","position":136,"original_position":136,"commit_id":"d521779ce02ef2186cc4ace3f68adc4fc7d2d2c3","original_commit_id":"d521779ce02ef2186cc4ace3f68adc4fc7d2d2c3","user":{"login":"golangcibot","id":42910462,"node_id":"MDQ6VXNlcjQyOTEwNDYy","avatar_url":"https://avatars1.githubusercontent.com/u/42910462?v=4","gravatar_id":"","url":"https://api.github.com/users/golangcibot","html_url":"https://github.com/golangcibot","followers_url":"https://api.github.com/users/golangcibot/followers","following_url":"https://api.github.com/users/golangcibot/following{/other_user}","gists_url":"https://api.github.com/users/golangcibot/gists{/gist_id}","starred_url":"https://api.github.com/users/golangcibot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/golangcibot/subscriptions","organizations_url":"https://api.github.com/users/golangcibot/orgs","repos_url":"https://api.github.com/users/golangcibot/repos","events_url":"https://api.github.com/users/golangcibot/events{/privacy}","received_events_url":"https://api.github.com/users/golangcibot/received_events","type":"User","site_admin":false},"body":"exported method SubAgent.Done should have comment or be unexported (from `golint`)","created_at":"2018-11-28T05:13:05Z","updated_at":"2018-11-28T05:13:09Z","html_url":"https://github.com/percona/pmm-agent/pull/4#discussion_r236942463","pull_request_url":"https://api.github.com/repos/percona/pmm-agent/pulls/4","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/percona/pmm-agent/pulls/comments/236942463"},"html":{"href":"https://github.com/percona/pmm-agent/pull/4#discussion_r236942463"},"pull_request":{"href":"https://api.github.com/repos/percona/pmm-agent/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/percona/pmm-agent/pulls/4","id":233444683,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMzNDQ0Njgz","html_url":"https://github.com/percona/pmm-agent/pull/4","diff_url":"https://github.com/percona/pmm-agent/pull/4.diff","patch_url":"https://github.com/percona/pmm-agent/pull/4.patch","issue_url":"https://api.github.com/repos/percona/pmm-agent/issues/4","number":4,"state":"open","locked":false,"title":"[WIP] PMM-3172 Working with subagents","user":{"login":"AlekSi","id":11512,"node_id":"MDQ6VXNlcjExNTEy","avatar_url":"https://avatars1.githubusercontent.com/u/11512?v=4","gravatar_id":"","url":"https://api.github.com/users/AlekSi","html_url":"https://github.com/AlekSi","followers_url":"https://api.github.com/users/AlekSi/followers","following_url":"https://api.github.com/users/AlekSi/following{/other_user}","gists_url":"https://api.github.com/users/AlekSi/gists{/gist_id}","starred_url":"https://api.github.com/users/AlekSi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AlekSi/subscriptions","organizations_url":"https://api.github.com/users/AlekSi/orgs","repos_url":"https://api.github.com/users/AlekSi/repos","events_url":"https://api.github.com/users/AlekSi/events{/privacy}","received_events_url":"https://api.github.com/users/AlekSi/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-11-26T05:46:24Z","updated_at":"2018-11-28T05:13:09Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b58fefc142531d36311fce9855c0fe88183a2804","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/percona/pmm-agent/pulls/4/commits","review_comments_url":"https://api.github.com/repos/percona/pmm-agent/pulls/4/comments","review_comment_url":"https://api.github.com/repos/percona/pmm-agent/pulls/comments{/number}","comments_url":"https://api.github.com/repos/percona/pmm-agent/issues/4/comments","statuses_url":"https://api.github.com/repos/percona/pmm-agent/statuses/d521779ce02ef2186cc4ace3f68adc4fc7d2d2c3","head":{"label":"percona:PMM-3172-working-with-subagents","ref":"PMM-3172-working-with-subagents","sha":"d521779ce02ef2186cc4ace3f68adc4fc7d2d2c3","user":{"login":"percona","id":1683025,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2ODMwMjU=","avatar_url":"https://avatars0.githubusercontent.com/u/1683025?v=4","gravatar_id":"","url":"https://api.github.com/users/percona","html_url":"https://github.com/percona","followers_url":"https://api.github.com/users/percona/followers","following_url":"https://api.github.com/users/percona/following{/other_user}","gists_url":"https://api.github.com/users/percona/gists{/gist_id}","starred_url":"https://api.github.com/users/percona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/percona/subscriptions","organizations_url":"https://api.github.com/users/percona/orgs","repos_url":"https://api.github.com/users/percona/repos","events_url":"https://api.github.com/users/percona/events{/privacy}","received_events_url":"https://api.github.com/users/percona/received_events","type":"Organization","site_admin":false},"repo":{"id":149303640,"node_id":"MDEwOlJlcG9zaXRvcnkxNDkzMDM2NDA=","name":"pmm-agent","full_name":"percona/pmm-agent","private":false,"owner":{"login":"percona","id":1683025,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2ODMwMjU=","avatar_url":"https://avatars0.githubusercontent.com/u/1683025?v=4","gravatar_id":"","url":"https://api.github.com/users/percona","html_url":"https://github.com/percona","followers_url":"https://api.github.com/users/percona/followers","following_url":"https://api.github.com/users/percona/following{/other_user}","gists_url":"https://api.github.com/users/percona/gists{/gist_id}","starred_url":"https://api.github.com/users/percona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/percona/subscriptions","organizations_url":"https://api.github.com/users/percona/orgs","repos_url":"https://api.github.com/users/percona/repos","events_url":"https://api.github.com/users/percona/events{/privacy}","received_events_url":"https://api.github.com/users/percona/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/percona/pmm-agent","description":"pmm-agent for PMM 2.0","fork":false,"url":"https://api.github.com/repos/percona/pmm-agent","forks_url":"https://api.github.com/repos/percona/pmm-agent/forks","keys_url":"https://api.github.com/repos/percona/pmm-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/percona/pmm-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/percona/pmm-agent/teams","hooks_url":"https://api.github.com/repos/percona/pmm-agent/hooks","issue_events_url":"https://api.github.com/repos/percona/pmm-agent/issues/events{/number}","events_url":"https://api.github.com/repos/percona/pmm-agent/events","assignees_url":"https://api.github.com/repos/percona/pmm-agent/assignees{/user}","branches_url":"https://api.github.com/repos/percona/pmm-agent/branches{/branch}","tags_url":"https://api.github.com/repos/percona/pmm-agent/tags","blobs_url":"https://api.github.com/repos/percona/pmm-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/percona/pmm-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/percona/pmm-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/percona/pmm-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/percona/pmm-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/percona/pmm-agent/languages","stargazers_url":"https://api.github.com/repos/percona/pmm-agent/stargazers","contributors_url":"https://api.github.com/repos/percona/pmm-agent/contributors","subscribers_url":"https://api.github.com/repos/percona/pmm-agent/subscribers","subscription_url":"https://api.github.com/repos/percona/pmm-agent/subscription","commits_url":"https://api.github.com/repos/percona/pmm-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/percona/pmm-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/percona/pmm-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/percona/pmm-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/percona/pmm-agent/contents/{+path}","compare_url":"https://api.github.com/repos/percona/pmm-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/percona/pmm-agent/merges","archive_url":"https://api.github.com/repos/percona/pmm-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/percona/pmm-agent/downloads","issues_url":"https://api.github.com/repos/percona/pmm-agent/issues{/number}","pulls_url":"https://api.github.com/repos/percona/pmm-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/percona/pmm-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/percona/pmm-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/percona/pmm-agent/labels{/name}","releases_url":"https://api.github.com/repos/percona/pmm-agent/releases{/id}","deployments_url":"https://api.github.com/repos/percona/pmm-agent/deployments","created_at":"2018-09-18T14:39:05Z","updated_at":"2018-11-28T05:01:26Z","pushed_at":"2018-11-28T05:12:36Z","git_url":"git://github.com/percona/pmm-agent.git","ssh_url":"git@github.com:percona/pmm-agent.git","clone_url":"https://github.com/percona/pmm-agent.git","svn_url":"https://github.com/percona/pmm-agent","homepage":"","size":4167,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"base":{"label":"percona:master","ref":"master","sha":"1f9fa035134742f5efb11154b4829120ec58e492","user":{"login":"percona","id":1683025,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2ODMwMjU=","avatar_url":"https://avatars0.githubusercontent.com/u/1683025?v=4","gravatar_id":"","url":"https://api.github.com/users/percona","html_url":"https://github.com/percona","followers_url":"https://api.github.com/users/percona/followers","following_url":"https://api.github.com/users/percona/following{/other_user}","gists_url":"https://api.github.com/users/percona/gists{/gist_id}","starred_url":"https://api.github.com/users/percona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/percona/subscriptions","organizations_url":"https://api.github.com/users/percona/orgs","repos_url":"https://api.github.com/users/percona/repos","events_url":"https://api.github.com/users/percona/events{/privacy}","received_events_url":"https://api.github.com/users/percona/received_events","type":"Organization","site_admin":false},"repo":{"id":149303640,"node_id":"MDEwOlJlcG9zaXRvcnkxNDkzMDM2NDA=","name":"pmm-agent","full_name":"percona/pmm-agent","private":false,"owner":{"login":"percona","id":1683025,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE2ODMwMjU=","avatar_url":"https://avatars0.githubusercontent.com/u/1683025?v=4","gravatar_id":"","url":"https://api.github.com/users/percona","html_url":"https://github.com/percona","followers_url":"https://api.github.com/users/percona/followers","following_url":"https://api.github.com/users/percona/following{/other_user}","gists_url":"https://api.github.com/users/percona/gists{/gist_id}","starred_url":"https://api.github.com/users/percona/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/percona/subscriptions","organizations_url":"https://api.github.com/users/percona/orgs","repos_url":"https://api.github.com/users/percona/repos","events_url":"https://api.github.com/users/percona/events{/privacy}","received_events_url":"https://api.github.com/users/percona/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/percona/pmm-agent","description":"pmm-agent for PMM 2.0","fork":false,"url":"https://api.github.com/repos/percona/pmm-agent","forks_url":"https://api.github.com/repos/percona/pmm-agent/forks","keys_url":"https://api.github.com/repos/percona/pmm-agent/keys{/key_id}","collaborators_url":"https://api.github.com/repos/percona/pmm-agent/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/percona/pmm-agent/teams","hooks_url":"https://api.github.com/repos/percona/pmm-agent/hooks","issue_events_url":"https://api.github.com/repos/percona/pmm-agent/issues/events{/number}","events_url":"https://api.github.com/repos/percona/pmm-agent/events","assignees_url":"https://api.github.com/repos/percona/pmm-agent/assignees{/user}","branches_url":"https://api.github.com/repos/percona/pmm-agent/branches{/branch}","tags_url":"https://api.github.com/repos/percona/pmm-agent/tags","blobs_url":"https://api.github.com/repos/percona/pmm-agent/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/percona/pmm-agent/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/percona/pmm-agent/git/refs{/sha}","trees_url":"https://api.github.com/repos/percona/pmm-agent/git/trees{/sha}","statuses_url":"https://api.github.com/repos/percona/pmm-agent/statuses/{sha}","languages_url":"https://api.github.com/repos/percona/pmm-agent/languages","stargazers_url":"https://api.github.com/repos/percona/pmm-agent/stargazers","contributors_url":"https://api.github.com/repos/percona/pmm-agent/contributors","subscribers_url":"https://api.github.com/repos/percona/pmm-agent/subscribers","subscription_url":"https://api.github.com/repos/percona/pmm-agent/subscription","commits_url":"https://api.github.com/repos/percona/pmm-agent/commits{/sha}","git_commits_url":"https://api.github.com/repos/percona/pmm-agent/git/commits{/sha}","comments_url":"https://api.github.com/repos/percona/pmm-agent/comments{/number}","issue_comment_url":"https://api.github.com/repos/percona/pmm-agent/issues/comments{/number}","contents_url":"https://api.github.com/repos/percona/pmm-agent/contents/{+path}","compare_url":"https://api.github.com/repos/percona/pmm-agent/compare/{base}...{head}","merges_url":"https://api.github.com/repos/percona/pmm-agent/merges","archive_url":"https://api.github.com/repos/percona/pmm-agent/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/percona/pmm-agent/downloads","issues_url":"https://api.github.com/repos/percona/pmm-agent/issues{/number}","pulls_url":"https://api.github.com/repos/percona/pmm-agent/pulls{/number}","milestones_url":"https://api.github.com/repos/percona/pmm-agent/milestones{/number}","notifications_url":"https://api.github.com/repos/percona/pmm-agent/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/percona/pmm-agent/labels{/name}","releases_url":"https://api.github.com/repos/percona/pmm-agent/releases{/id}","deployments_url":"https://api.github.com/repos/percona/pmm-agent/deployments","created_at":"2018-09-18T14:39:05Z","updated_at":"2018-11-28T05:01:26Z","pushed_at":"2018-11-28T05:12:36Z","git_url":"git://github.com/percona/pmm-agent.git","ssh_url":"git@github.com:percona/pmm-agent.git","clone_url":"https://github.com/percona/pmm-agent.git","svn_url":"https://github.com/percona/pmm-agent","homepage":"","size":4167,"stargazers_count":2,"watchers_count":2,"language":"Go","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"agpl-3.0","name":"GNU Affero General Public License v3.0","spdx_id":"AGPL-3.0","url":"https://api.github.com/licenses/agpl-3.0","node_id":"MDc6TGljZW5zZTE="},"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/percona/pmm-agent/pulls/4"},"html":{"href":"https://github.com/percona/pmm-agent/pull/4"},"issue":{"href":"https://api.github.com/repos/percona/pmm-agent/issues/4"},"comments":{"href":"https://api.github.com/repos/percona/pmm-agent/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/percona/pmm-agent/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/percona/pmm-agent/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/percona/pmm-agent/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/percona/pmm-agent/statuses/d521779ce02ef2186cc4ace3f68adc4fc7d2d2c3"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"golangcibot"}}