{"action":"created","issue":{"url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime/issues/132","repository_url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime","labels_url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime/issues/132/labels{/name}","comments_url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime/issues/132/comments","events_url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime/issues/132/events","html_url":"https://github.com/kubernetes-sigs/controller-runtime/pull/132","id":356529499,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEyNzY3MTY4","number":132,"title":"Add prometheus metrics to internal controller","user":{"login":"JoelSpeed","id":9232216,"node_id":"MDQ6VXNlcjkyMzIyMTY=","avatar_url":"https://avatars3.githubusercontent.com/u/9232216?v=4","gravatar_id":"","url":"https://api.github.com/users/JoelSpeed","html_url":"https://github.com/JoelSpeed","followers_url":"https://api.github.com/users/JoelSpeed/followers","following_url":"https://api.github.com/users/JoelSpeed/following{/other_user}","gists_url":"https://api.github.com/users/JoelSpeed/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelSpeed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelSpeed/subscriptions","organizations_url":"https://api.github.com/users/JoelSpeed/orgs","repos_url":"https://api.github.com/users/JoelSpeed/repos","events_url":"https://api.github.com/users/JoelSpeed/events{/privacy}","received_events_url":"https://api.github.com/users/JoelSpeed/received_events","type":"User","site_admin":false},"labels":[{"id":957854387,"node_id":"MDU6TGFiZWw5NTc4NTQzODc=","url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime/labels/cncf-cla:%20yes","name":"cncf-cla: yes","color":"bfe5bf","default":false},{"id":957926583,"node_id":"MDU6TGFiZWw5NTc5MjY1ODM=","url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime/labels/size/XL","name":"size/XL","color":"ee5500","default":false}],"state":"open","locked":false,"assignee":{"login":"DirectXMan12","id":119737,"node_id":"MDQ6VXNlcjExOTczNw==","avatar_url":"https://avatars1.githubusercontent.com/u/119737?v=4","gravatar_id":"","url":"https://api.github.com/users/DirectXMan12","html_url":"https://github.com/DirectXMan12","followers_url":"https://api.github.com/users/DirectXMan12/followers","following_url":"https://api.github.com/users/DirectXMan12/following{/other_user}","gists_url":"https://api.github.com/users/DirectXMan12/gists{/gist_id}","starred_url":"https://api.github.com/users/DirectXMan12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirectXMan12/subscriptions","organizations_url":"https://api.github.com/users/DirectXMan12/orgs","repos_url":"https://api.github.com/users/DirectXMan12/repos","events_url":"https://api.github.com/users/DirectXMan12/events{/privacy}","received_events_url":"https://api.github.com/users/DirectXMan12/received_events","type":"User","site_admin":false},"assignees":[{"login":"DirectXMan12","id":119737,"node_id":"MDQ6VXNlcjExOTczNw==","avatar_url":"https://avatars1.githubusercontent.com/u/119737?v=4","gravatar_id":"","url":"https://api.github.com/users/DirectXMan12","html_url":"https://github.com/DirectXMan12","followers_url":"https://api.github.com/users/DirectXMan12/followers","following_url":"https://api.github.com/users/DirectXMan12/following{/other_user}","gists_url":"https://api.github.com/users/DirectXMan12/gists{/gist_id}","starred_url":"https://api.github.com/users/DirectXMan12/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DirectXMan12/subscriptions","organizations_url":"https://api.github.com/users/DirectXMan12/orgs","repos_url":"https://api.github.com/users/DirectXMan12/repos","events_url":"https://api.github.com/users/DirectXMan12/events{/privacy}","received_events_url":"https://api.github.com/users/DirectXMan12/received_events","type":"User","site_admin":false}],"milestone":null,"comments":4,"created_at":"2018-09-03T14:36:23Z","updated_at":"2018-09-11T13:59:29Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime/pulls/132","html_url":"https://github.com/kubernetes-sigs/controller-runtime/pull/132","diff_url":"https://github.com/kubernetes-sigs/controller-runtime/pull/132.diff","patch_url":"https://github.com/kubernetes-sigs/controller-runtime/pull/132.patch"},"body":"Fixes #119 \r\n\r\nAdds prometheus metric server and some metrics to the controller runtime to allow users to see inside the controllers they are building.\r\n\r\nMetrics Added:\r\n- Reconcile Errors: Counter of how many reconcile errors have occurred (per controller)\r\n- Queue Length: How many items are in the reconcile queue (per controller)\r\n- Reconcile Time: Histogram metric for how long reconcile's are taking (per controller)\r\n\r\nChanges to operation:\r\n- Manager creates a listener in New which binds to the given address (default `:8080`)\r\n- Manager creates a prometheus registry which will be served on the listener\r\n- Manager `.Start()` starts serving the prometheus registry from the manager\r\n- Manager `.Add()` adds metrics from the runnable to the manager's regsitry\r\n- Manager exposes `.AddMetrics()` to add more metrics to the registry\r\n  - This is where kubebuilder consumers will add metrics, in their `.add()` method they can register their metrics with the Manager\r\n- Controller embed `Metrics` struct\r\n  - Metrics struct exposes `GetCollectors()` to allow `Manager.Add()` to register metrics from the controller\r\n  - NewController creates a new set of metrics for use within this particular instance of the controller\r\n  - `processNextWorkItem` updates the metrics within the Controller's Metrics struct"},"comment":{"url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime/issues/comments/420284452","html_url":"https://github.com/kubernetes-sigs/controller-runtime/pull/132#issuecomment-420284452","issue_url":"https://api.github.com/repos/kubernetes-sigs/controller-runtime/issues/132","id":420284452,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDI4NDQ1Mg==","user":{"login":"JoelSpeed","id":9232216,"node_id":"MDQ6VXNlcjkyMzIyMTY=","avatar_url":"https://avatars3.githubusercontent.com/u/9232216?v=4","gravatar_id":"","url":"https://api.github.com/users/JoelSpeed","html_url":"https://github.com/JoelSpeed","followers_url":"https://api.github.com/users/JoelSpeed/followers","following_url":"https://api.github.com/users/JoelSpeed/following{/other_user}","gists_url":"https://api.github.com/users/JoelSpeed/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelSpeed/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelSpeed/subscriptions","organizations_url":"https://api.github.com/users/JoelSpeed/orgs","repos_url":"https://api.github.com/users/JoelSpeed/repos","events_url":"https://api.github.com/users/JoelSpeed/events{/privacy}","received_events_url":"https://api.github.com/users/JoelSpeed/received_events","type":"User","site_admin":false},"created_at":"2018-09-11T13:59:29Z","updated_at":"2018-09-11T13:59:29Z","author_association":"CONTRIBUTOR","body":"@DirectXMan12 Got ya! I added this extra abstraction after discussing with a colleague about globals vs non-globals. We just went for our preference which is to avoid globals as much as possible but I'm happy to modify the PR to make a global `sigs.k8s.io/controller-runtime/pkg/metrics` if you'd prefer.\r\n\r\nThe reason I'm suggesting not to use the default prometheus registry is in case you have multiple packages all setting up metrics handling capabilities within one binary. For instance, we plan to run a webhook alongside one of our controllers which sets up it's own metrics endpoint using the global prometheus registry (part of the framework), I'm not personally a fan as at this point, both the webhook and the controllers would serve the same set of metrics if they both used the global registry.\r\n\r\nI don't know if that's a common problem, but to me, not using the default prometheus registry seems cleaner, happy to meet in the middle with a controller-runtime registry global if that's what you think is the best approach? "}}
{"actor":{"display_login":"JoelSpeed"}}