{"action":"created","comment":{"url":"https://api.github.com/repos/thought-machine/please/pulls/comments/76528937","id":76528937,"diff_hunk":"@@ -0,0 +1,207 @@\n+// +build prometheus\n+\n+// Package metrics contains support for reporting metrics to an external server,\n+// currently a Prometheus pushgateway. Because plz runs as a transient process\n+// we can't wait around for Prometheus to call us, we've got to push to them.\n+package metrics\n+\n+import (\n+\t\"os/user\"\n+\t\"runtime\"\n+\t\"time\"\n+\n+\t\"github.com/prometheus/client_golang/prometheus\"\n+\t\"github.com/prometheus/client_golang/prometheus/push\"\n+\t\"gopkg.in/op/go-logging.v1\"\n+\n+\t\"core\"\n+)\n+\n+var log = logging.MustGetLogger(\"metrics\")\n+\n+// This is the maximum number of errors after which plz will stop attempting to send metrics.\n+const maxErrors = 3\n+\n+type metrics struct {\n+\turl                                           string\n+\tnewMetrics                                    bool\n+\tstopChan                                      chan bool\n+\tcancelled                                     bool\n+\terrors                                        int\n+\tpushes                                        int\n+\tbuildCounter, cacheCounter, testCounter       *prometheus.CounterVec\n+\tbuildHistogram, cacheHistogram, testHistogram *prometheus.HistogramVec\n+}\n+\n+// m is the singleton metrics instance.\n+var m *metrics\n+\n+// InitFromConfig sets up the initial metrics from the configuration.\n+func InitFromConfig(config *core.Configuration) {\n+\tif config.Metrics.PushGatewayURL != \"\" {\n+\t\tm = initMetrics(config.Metrics.PushGatewayURL, config.Metrics.PushFrequency)\n+\t\tprometheus.MustRegister(m.buildCounter)\n+\t\tprometheus.MustRegister(m.cacheCounter)\n+\t\tprometheus.MustRegister(m.testCounter)\n+\t\tprometheus.MustRegister(m.buildHistogram)\n+\t\tprometheus.MustRegister(m.cacheHistogram)\n+\t\tprometheus.MustRegister(m.testHistogram)\n+\t}\n+}\n+\n+// initMetrics initialises a new metrics instance.\n+// This is deliberately not exposed but is useful for testing.\n+func initMetrics(url string, frequency int) *metrics {\n+\tu, err := user.Current()\n+\tif err != nil {\n+\t\tlog.Warning(\"Can't determine current user name for metrics\")\n+\t\tu = &user.User{Username: \"unknown\"}\n+\t}\n+\tconstLabels := prometheus.Labels{","path":"src/metrics/prometheus.go","position":60,"original_position":60,"commit_id":"51506d299483062d5ee5b80069124d1dc7ef4cce","original_commit_id":"51506d299483062d5ee5b80069124d1dc7ef4cce","user":{"login":"dimpavloff","id":1078697,"avatar_url":"https://avatars.githubusercontent.com/u/1078697?v=3","gravatar_id":"","url":"https://api.github.com/users/dimpavloff","html_url":"https://github.com/dimpavloff","followers_url":"https://api.github.com/users/dimpavloff/followers","following_url":"https://api.github.com/users/dimpavloff/following{/other_user}","gists_url":"https://api.github.com/users/dimpavloff/gists{/gist_id}","starred_url":"https://api.github.com/users/dimpavloff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimpavloff/subscriptions","organizations_url":"https://api.github.com/users/dimpavloff/orgs","repos_url":"https://api.github.com/users/dimpavloff/repos","events_url":"https://api.github.com/users/dimpavloff/events{/privacy}","received_events_url":"https://api.github.com/users/dimpavloff/received_events","type":"User","site_admin":false},"body":"> plz is agnostic to the version control system so at the moment we never know the branch. I suppose we could quickly run a cheeky git command to find it.\r\nHm, I thought this might be the case :/ I think a better solution is to have a section in the plzconfig about the additional dimensions/labels to apply to each metric, although that feels like a more substantial piece of work.\r\n\r\nRe master/non-master -- definitely agree, that was my thinking, too.","created_at":"2016-08-28T09:32:17Z","updated_at":"2016-08-28T09:32:17Z","html_url":"https://github.com/thought-machine/please/pull/133#discussion_r76528937","pull_request_url":"https://api.github.com/repos/thought-machine/please/pulls/133","_links":{"self":{"href":"https://api.github.com/repos/thought-machine/please/pulls/comments/76528937"},"html":{"href":"https://github.com/thought-machine/please/pull/133#discussion_r76528937"},"pull_request":{"href":"https://api.github.com/repos/thought-machine/please/pulls/133"}}},"pull_request":{"url":"https://api.github.com/repos/thought-machine/please/pulls/133","id":82076881,"html_url":"https://github.com/thought-machine/please/pull/133","diff_url":"https://github.com/thought-machine/please/pull/133.diff","patch_url":"https://github.com/thought-machine/please/pull/133.patch","issue_url":"https://api.github.com/repos/thought-machine/please/issues/133","number":133,"state":"closed","locked":false,"title":"Support for pushing metrics to Prometheus","user":{"login":"peterebden","id":1479315,"avatar_url":"https://avatars.githubusercontent.com/u/1479315?v=3","gravatar_id":"","url":"https://api.github.com/users/peterebden","html_url":"https://github.com/peterebden","followers_url":"https://api.github.com/users/peterebden/followers","following_url":"https://api.github.com/users/peterebden/following{/other_user}","gists_url":"https://api.github.com/users/peterebden/gists{/gist_id}","starred_url":"https://api.github.com/users/peterebden/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/peterebden/subscriptions","organizations_url":"https://api.github.com/users/peterebden/orgs","repos_url":"https://api.github.com/users/peterebden/repos","events_url":"https://api.github.com/users/peterebden/events{/privacy}","received_events_url":"https://api.github.com/users/peterebden/received_events","type":"User","site_admin":false},"body":"I imagine we might want other metrics later, but this should be enough to get started with.","created_at":"2016-08-20T11:53:38Z","updated_at":"2016-08-28T09:32:17Z","closed_at":"2016-08-25T15:52:00Z","merged_at":"2016-08-25T15:52:00Z","merge_commit_sha":"27dfeab69aa7df8838708f49a594138b381c6902","assignee":{"login":"csdigi","id":43999,"avatar_url":"https://avatars.githubusercontent.com/u/43999?v=3","gravatar_id":"","url":"https://api.github.com/users/csdigi","html_url":"https://github.com/csdigi","followers_url":"https://api.github.com/users/csdigi/followers","following_url":"https://api.github.com/users/csdigi/following{/other_user}","gists_url":"https://api.github.com/users/csdigi/gists{/gist_id}","starred_url":"https://api.github.com/users/csdigi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csdigi/subscriptions","organizations_url":"https://api.github.com/users/csdigi/orgs","repos_url":"https://api.github.com/users/csdigi/repos","events_url":"https://api.github.com/users/csdigi/events{/privacy}","received_events_url":"https://api.github.com/users/csdigi/received_events","type":"User","site_admin":false},"assignees":[{"login":"csdigi","id":43999,"avatar_url":"https://avatars.githubusercontent.com/u/43999?v=3","gravatar_id":"","url":"https://api.github.com/users/csdigi","html_url":"https://github.com/csdigi","followers_url":"https://api.github.com/users/csdigi/followers","following_url":"https://api.github.com/users/csdigi/following{/other_user}","gists_url":"https://api.github.com/users/csdigi/gists{/gist_id}","starred_url":"https://api.github.com/users/csdigi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/csdigi/subscriptions","organizations_url":"https://api.github.com/users/csdigi/orgs","repos_url":"https://api.github.com/users/csdigi/repos","events_url":"https://api.github.com/users/csdigi/events{/privacy}","received_events_url":"https://api.github.com/users/csdigi/received_events","type":"User","site_admin":false},{"login":"fs75","id":1045708,"avatar_url":"https://avatars.githubusercontent.com/u/1045708?v=3","gravatar_id":"","url":"https://api.github.com/users/fs75","html_url":"https://github.com/fs75","followers_url":"https://api.github.com/users/fs75/followers","following_url":"https://api.github.com/users/fs75/following{/other_user}","gists_url":"https://api.github.com/users/fs75/gists{/gist_id}","starred_url":"https://api.github.com/users/fs75/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fs75/subscriptions","organizations_url":"https://api.github.com/users/fs75/orgs","repos_url":"https://api.github.com/users/fs75/repos","events_url":"https://api.github.com/users/fs75/events{/privacy}","received_events_url":"https://api.github.com/users/fs75/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/thought-machine/please/pulls/133/commits","review_comments_url":"https://api.github.com/repos/thought-machine/please/pulls/133/comments","review_comment_url":"https://api.github.com/repos/thought-machine/please/pulls/comments{/number}","comments_url":"https://api.github.com/repos/thought-machine/please/issues/133/comments","statuses_url":"https://api.github.com/repos/thought-machine/please/statuses/51506d299483062d5ee5b80069124d1dc7ef4cce","head":{"label":"thought-machine:prometheus","ref":"prometheus","sha":"51506d299483062d5ee5b80069124d1dc7ef4cce","user":{"login":"thought-machine","id":16104327,"avatar_url":"https://avatars.githubusercontent.com/u/16104327?v=3","gravatar_id":"","url":"https://api.github.com/users/thought-machine","html_url":"https://github.com/thought-machine","followers_url":"https://api.github.com/users/thought-machine/followers","following_url":"https://api.github.com/users/thought-machine/following{/other_user}","gists_url":"https://api.github.com/users/thought-machine/gists{/gist_id}","starred_url":"https://api.github.com/users/thought-machine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thought-machine/subscriptions","organizations_url":"https://api.github.com/users/thought-machine/orgs","repos_url":"https://api.github.com/users/thought-machine/repos","events_url":"https://api.github.com/users/thought-machine/events{/privacy}","received_events_url":"https://api.github.com/users/thought-machine/received_events","type":"Organization","site_admin":false},"repo":{"id":50915867,"name":"please","full_name":"thought-machine/please","owner":{"login":"thought-machine","id":16104327,"avatar_url":"https://avatars.githubusercontent.com/u/16104327?v=3","gravatar_id":"","url":"https://api.github.com/users/thought-machine","html_url":"https://github.com/thought-machine","followers_url":"https://api.github.com/users/thought-machine/followers","following_url":"https://api.github.com/users/thought-machine/following{/other_user}","gists_url":"https://api.github.com/users/thought-machine/gists{/gist_id}","starred_url":"https://api.github.com/users/thought-machine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thought-machine/subscriptions","organizations_url":"https://api.github.com/users/thought-machine/orgs","repos_url":"https://api.github.com/users/thought-machine/repos","events_url":"https://api.github.com/users/thought-machine/events{/privacy}","received_events_url":"https://api.github.com/users/thought-machine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thought-machine/please","description":"High-performance extensible build system for reproducible builds.","fork":false,"url":"https://api.github.com/repos/thought-machine/please","forks_url":"https://api.github.com/repos/thought-machine/please/forks","keys_url":"https://api.github.com/repos/thought-machine/please/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thought-machine/please/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thought-machine/please/teams","hooks_url":"https://api.github.com/repos/thought-machine/please/hooks","issue_events_url":"https://api.github.com/repos/thought-machine/please/issues/events{/number}","events_url":"https://api.github.com/repos/thought-machine/please/events","assignees_url":"https://api.github.com/repos/thought-machine/please/assignees{/user}","branches_url":"https://api.github.com/repos/thought-machine/please/branches{/branch}","tags_url":"https://api.github.com/repos/thought-machine/please/tags","blobs_url":"https://api.github.com/repos/thought-machine/please/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thought-machine/please/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thought-machine/please/git/refs{/sha}","trees_url":"https://api.github.com/repos/thought-machine/please/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thought-machine/please/statuses/{sha}","languages_url":"https://api.github.com/repos/thought-machine/please/languages","stargazers_url":"https://api.github.com/repos/thought-machine/please/stargazers","contributors_url":"https://api.github.com/repos/thought-machine/please/contributors","subscribers_url":"https://api.github.com/repos/thought-machine/please/subscribers","subscription_url":"https://api.github.com/repos/thought-machine/please/subscription","commits_url":"https://api.github.com/repos/thought-machine/please/commits{/sha}","git_commits_url":"https://api.github.com/repos/thought-machine/please/git/commits{/sha}","comments_url":"https://api.github.com/repos/thought-machine/please/comments{/number}","issue_comment_url":"https://api.github.com/repos/thought-machine/please/issues/comments{/number}","contents_url":"https://api.github.com/repos/thought-machine/please/contents/{+path}","compare_url":"https://api.github.com/repos/thought-machine/please/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thought-machine/please/merges","archive_url":"https://api.github.com/repos/thought-machine/please/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thought-machine/please/downloads","issues_url":"https://api.github.com/repos/thought-machine/please/issues{/number}","pulls_url":"https://api.github.com/repos/thought-machine/please/pulls{/number}","milestones_url":"https://api.github.com/repos/thought-machine/please/milestones{/number}","notifications_url":"https://api.github.com/repos/thought-machine/please/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thought-machine/please/labels{/name}","releases_url":"https://api.github.com/repos/thought-machine/please/releases{/id}","deployments_url":"https://api.github.com/repos/thought-machine/please/deployments","created_at":"2016-02-02T11:27:05Z","updated_at":"2016-08-16T20:34:36Z","pushed_at":"2016-08-26T09:56:34Z","git_url":"git://github.com/thought-machine/please.git","ssh_url":"git@github.com:thought-machine/please.git","clone_url":"https://github.com/thought-machine/please.git","svn_url":"https://github.com/thought-machine/please","homepage":"http://please.build","size":1725,"stargazers_count":6,"watchers_count":6,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":6,"default_branch":"master"}},"base":{"label":"thought-machine:master","ref":"master","sha":"dcc2b60c6cc4a956ce457212fab1a60a0330d3f9","user":{"login":"thought-machine","id":16104327,"avatar_url":"https://avatars.githubusercontent.com/u/16104327?v=3","gravatar_id":"","url":"https://api.github.com/users/thought-machine","html_url":"https://github.com/thought-machine","followers_url":"https://api.github.com/users/thought-machine/followers","following_url":"https://api.github.com/users/thought-machine/following{/other_user}","gists_url":"https://api.github.com/users/thought-machine/gists{/gist_id}","starred_url":"https://api.github.com/users/thought-machine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thought-machine/subscriptions","organizations_url":"https://api.github.com/users/thought-machine/orgs","repos_url":"https://api.github.com/users/thought-machine/repos","events_url":"https://api.github.com/users/thought-machine/events{/privacy}","received_events_url":"https://api.github.com/users/thought-machine/received_events","type":"Organization","site_admin":false},"repo":{"id":50915867,"name":"please","full_name":"thought-machine/please","owner":{"login":"thought-machine","id":16104327,"avatar_url":"https://avatars.githubusercontent.com/u/16104327?v=3","gravatar_id":"","url":"https://api.github.com/users/thought-machine","html_url":"https://github.com/thought-machine","followers_url":"https://api.github.com/users/thought-machine/followers","following_url":"https://api.github.com/users/thought-machine/following{/other_user}","gists_url":"https://api.github.com/users/thought-machine/gists{/gist_id}","starred_url":"https://api.github.com/users/thought-machine/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thought-machine/subscriptions","organizations_url":"https://api.github.com/users/thought-machine/orgs","repos_url":"https://api.github.com/users/thought-machine/repos","events_url":"https://api.github.com/users/thought-machine/events{/privacy}","received_events_url":"https://api.github.com/users/thought-machine/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/thought-machine/please","description":"High-performance extensible build system for reproducible builds.","fork":false,"url":"https://api.github.com/repos/thought-machine/please","forks_url":"https://api.github.com/repos/thought-machine/please/forks","keys_url":"https://api.github.com/repos/thought-machine/please/keys{/key_id}","collaborators_url":"https://api.github.com/repos/thought-machine/please/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/thought-machine/please/teams","hooks_url":"https://api.github.com/repos/thought-machine/please/hooks","issue_events_url":"https://api.github.com/repos/thought-machine/please/issues/events{/number}","events_url":"https://api.github.com/repos/thought-machine/please/events","assignees_url":"https://api.github.com/repos/thought-machine/please/assignees{/user}","branches_url":"https://api.github.com/repos/thought-machine/please/branches{/branch}","tags_url":"https://api.github.com/repos/thought-machine/please/tags","blobs_url":"https://api.github.com/repos/thought-machine/please/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/thought-machine/please/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/thought-machine/please/git/refs{/sha}","trees_url":"https://api.github.com/repos/thought-machine/please/git/trees{/sha}","statuses_url":"https://api.github.com/repos/thought-machine/please/statuses/{sha}","languages_url":"https://api.github.com/repos/thought-machine/please/languages","stargazers_url":"https://api.github.com/repos/thought-machine/please/stargazers","contributors_url":"https://api.github.com/repos/thought-machine/please/contributors","subscribers_url":"https://api.github.com/repos/thought-machine/please/subscribers","subscription_url":"https://api.github.com/repos/thought-machine/please/subscription","commits_url":"https://api.github.com/repos/thought-machine/please/commits{/sha}","git_commits_url":"https://api.github.com/repos/thought-machine/please/git/commits{/sha}","comments_url":"https://api.github.com/repos/thought-machine/please/comments{/number}","issue_comment_url":"https://api.github.com/repos/thought-machine/please/issues/comments{/number}","contents_url":"https://api.github.com/repos/thought-machine/please/contents/{+path}","compare_url":"https://api.github.com/repos/thought-machine/please/compare/{base}...{head}","merges_url":"https://api.github.com/repos/thought-machine/please/merges","archive_url":"https://api.github.com/repos/thought-machine/please/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/thought-machine/please/downloads","issues_url":"https://api.github.com/repos/thought-machine/please/issues{/number}","pulls_url":"https://api.github.com/repos/thought-machine/please/pulls{/number}","milestones_url":"https://api.github.com/repos/thought-machine/please/milestones{/number}","notifications_url":"https://api.github.com/repos/thought-machine/please/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/thought-machine/please/labels{/name}","releases_url":"https://api.github.com/repos/thought-machine/please/releases{/id}","deployments_url":"https://api.github.com/repos/thought-machine/please/deployments","created_at":"2016-02-02T11:27:05Z","updated_at":"2016-08-16T20:34:36Z","pushed_at":"2016-08-26T09:56:34Z","git_url":"git://github.com/thought-machine/please.git","ssh_url":"git@github.com:thought-machine/please.git","clone_url":"https://github.com/thought-machine/please.git","svn_url":"https://github.com/thought-machine/please","homepage":"http://please.build","size":1725,"stargazers_count":6,"watchers_count":6,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":9,"forks":0,"open_issues":9,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/thought-machine/please/pulls/133"},"html":{"href":"https://github.com/thought-machine/please/pull/133"},"issue":{"href":"https://api.github.com/repos/thought-machine/please/issues/133"},"comments":{"href":"https://api.github.com/repos/thought-machine/please/issues/133/comments"},"review_comments":{"href":"https://api.github.com/repos/thought-machine/please/pulls/133/comments"},"review_comment":{"href":"https://api.github.com/repos/thought-machine/please/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/thought-machine/please/pulls/133/commits"},"statuses":{"href":"https://api.github.com/repos/thought-machine/please/statuses/51506d299483062d5ee5b80069124d1dc7ef4cce"}}}}
{"actor":{"display_login":"dimpavloff"}}