{"action":"created","comment":{"url":"https://api.github.com/repos/id/kastlex/pulls/comments/89346780","pull_request_review_id":9892391,"id":89346780,"diff_hunk":"@@ -0,0 +1,69 @@\n+defmodule Kastlex.CgStatusCollector do\n+  require Logger\n+  require Record\n+  import Record, only: [defrecord: 2, extract: 2]\n+  defrecord :kafka_message,\n+             extract(:kafka_message, from_lib: \"brod/include/brod.hrl\")\n+\n+  @behaviour :brod_topic_subscriber\n+\n+  @table :consumer_offsets\n+  @topic \"__consumer_offsets\"\n+  @server __MODULE__\n+\n+  def get_groups() do\n+    Enum.filter(\n+      :ets.tab2list(@table),\n+      fn({key, _value}) -> get_type(key) === :group end)\n+  end\n+\n+  def get_offsets() do\n+    Enum.filter(\n+      :ets.tab2list(@table),\n+      fn({key, _value}) -> get_type(key) === :offset end)\n+  end\n+\n+  def start_link(options) do\n+    client = options.brod_client_id\n+    consumer_config = [{:begin_offset, :earliest}]\n+    ## start a topic subscriber which will spawn one consumer process\n+    ## for each partition, and subscribe to all partition consumers\n+    :brod_topic_subscriber.start_link(client, @topic, _partitions = :all,\n+                                      consumer_config, __MODULE__, @table)\n+  end\n+\n+  def init(@topic, @table) do\n+    :ets.new(@table, [:set, :protected, :named_table])\n+    {:ok, [], %{}}\n+  end\n+\n+  def handle_message(_partition, msg, state) do\n+    key_bin = kafka_message(msg, :key)\n+    value_bin = kafka_message(msg, :value)\n+    {tag, key, value} = :kpro_consumer_group.decode(key_bin, value_bin)\n+    kf = fn(k) ->\n+      {:ok, v} = Keyword.fetch(key, k)\n+      v\n+    end\n+    case tag do\n+      :offset -> update_ets({kf.(:group_id), kf.(:topic), kf.(:partition)}, value)\n+      :group  -> update_ets(kf.(:group_id), value)\n+    end\n+    {:ok, :ack, state}\n+  end\n+\n+  defp get_type(group_id) when is_binary(group_id) do\n+    :group\n+  end\n+  defp get_type({group_id, _topic, _partition}) when is_binary(group_id) do\n+    :offset\n+  end\n+\n+  defp update_ets(key, _value = []) do\n+    :ets.delete(@table, key)","path":"lib/kastlex/cg_status_collector.ex","position":63,"original_position":63,"commit_id":"2a30a3c589cac19694bb70f4d2fcb903780d5a47","original_commit_id":"2a30a3c589cac19694bb70f4d2fcb903780d5a47","user":{"login":"zmstone","id":164324,"avatar_url":"https://avatars.githubusercontent.com/u/164324?v=3","gravatar_id":"","url":"https://api.github.com/users/zmstone","html_url":"https://github.com/zmstone","followers_url":"https://api.github.com/users/zmstone/followers","following_url":"https://api.github.com/users/zmstone/following{/other_user}","gists_url":"https://api.github.com/users/zmstone/gists{/gist_id}","starred_url":"https://api.github.com/users/zmstone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zmstone/subscriptions","organizations_url":"https://api.github.com/users/zmstone/orgs","repos_url":"https://api.github.com/users/zmstone/repos","events_url":"https://api.github.com/users/zmstone/events{/privacy}","received_events_url":"https://api.github.com/users/zmstone/received_events","type":"User","site_admin":false},"body":"maybe mark it as deleted.","created_at":"2016-11-23T16:05:05Z","updated_at":"2016-11-23T16:05:05Z","html_url":"https://github.com/id/kastlex/pull/4#discussion_r89346780","pull_request_url":"https://api.github.com/repos/id/kastlex/pulls/4","_links":{"self":{"href":"https://api.github.com/repos/id/kastlex/pulls/comments/89346780"},"html":{"href":"https://github.com/id/kastlex/pull/4#discussion_r89346780"},"pull_request":{"href":"https://api.github.com/repos/id/kastlex/pulls/4"}}},"pull_request":{"url":"https://api.github.com/repos/id/kastlex/pulls/4","id":75211738,"html_url":"https://github.com/id/kastlex/pull/4","diff_url":"https://github.com/id/kastlex/pull/4.diff","patch_url":"https://github.com/id/kastlex/pull/4.patch","issue_url":"https://api.github.com/repos/id/kastlex/issues/4","number":4,"state":"open","locked":false,"title":"add consumer group data collector","user":{"login":"zmstone","id":164324,"avatar_url":"https://avatars.githubusercontent.com/u/164324?v=3","gravatar_id":"","url":"https://api.github.com/users/zmstone","html_url":"https://github.com/zmstone","followers_url":"https://api.github.com/users/zmstone/followers","following_url":"https://api.github.com/users/zmstone/following{/other_user}","gists_url":"https://api.github.com/users/zmstone/gists{/gist_id}","starred_url":"https://api.github.com/users/zmstone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zmstone/subscriptions","organizations_url":"https://api.github.com/users/zmstone/orgs","repos_url":"https://api.github.com/users/zmstone/repos","events_url":"https://api.github.com/users/zmstone/events{/privacy}","received_events_url":"https://api.github.com/users/zmstone/received_events","type":"User","site_admin":false},"body":"require brod 2.1.8 (which is not published to hex yet).\n","created_at":"2016-06-25T18:55:52Z","updated_at":"2016-11-23T16:05:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"75a9dab302838a1aba4ecf0300445c5328ba1e8d","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/id/kastlex/pulls/4/commits","review_comments_url":"https://api.github.com/repos/id/kastlex/pulls/4/comments","review_comment_url":"https://api.github.com/repos/id/kastlex/pulls/comments{/number}","comments_url":"https://api.github.com/repos/id/kastlex/issues/4/comments","statuses_url":"https://api.github.com/repos/id/kastlex/statuses/2a30a3c589cac19694bb70f4d2fcb903780d5a47","head":{"label":"zmstone:add-cg-collector","ref":"add-cg-collector","sha":"2a30a3c589cac19694bb70f4d2fcb903780d5a47","user":{"login":"zmstone","id":164324,"avatar_url":"https://avatars.githubusercontent.com/u/164324?v=3","gravatar_id":"","url":"https://api.github.com/users/zmstone","html_url":"https://github.com/zmstone","followers_url":"https://api.github.com/users/zmstone/followers","following_url":"https://api.github.com/users/zmstone/following{/other_user}","gists_url":"https://api.github.com/users/zmstone/gists{/gist_id}","starred_url":"https://api.github.com/users/zmstone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zmstone/subscriptions","organizations_url":"https://api.github.com/users/zmstone/orgs","repos_url":"https://api.github.com/users/zmstone/repos","events_url":"https://api.github.com/users/zmstone/events{/privacy}","received_events_url":"https://api.github.com/users/zmstone/received_events","type":"User","site_admin":false},"repo":{"id":60831165,"name":"kastlex","full_name":"zmstone/kastlex","owner":{"login":"zmstone","id":164324,"avatar_url":"https://avatars.githubusercontent.com/u/164324?v=3","gravatar_id":"","url":"https://api.github.com/users/zmstone","html_url":"https://github.com/zmstone","followers_url":"https://api.github.com/users/zmstone/followers","following_url":"https://api.github.com/users/zmstone/following{/other_user}","gists_url":"https://api.github.com/users/zmstone/gists{/gist_id}","starred_url":"https://api.github.com/users/zmstone/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zmstone/subscriptions","organizations_url":"https://api.github.com/users/zmstone/orgs","repos_url":"https://api.github.com/users/zmstone/repos","events_url":"https://api.github.com/users/zmstone/events{/privacy}","received_events_url":"https://api.github.com/users/zmstone/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zmstone/kastlex","description":"Kafka REST Proxy in Elixir","fork":true,"url":"https://api.github.com/repos/zmstone/kastlex","forks_url":"https://api.github.com/repos/zmstone/kastlex/forks","keys_url":"https://api.github.com/repos/zmstone/kastlex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zmstone/kastlex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zmstone/kastlex/teams","hooks_url":"https://api.github.com/repos/zmstone/kastlex/hooks","issue_events_url":"https://api.github.com/repos/zmstone/kastlex/issues/events{/number}","events_url":"https://api.github.com/repos/zmstone/kastlex/events","assignees_url":"https://api.github.com/repos/zmstone/kastlex/assignees{/user}","branches_url":"https://api.github.com/repos/zmstone/kastlex/branches{/branch}","tags_url":"https://api.github.com/repos/zmstone/kastlex/tags","blobs_url":"https://api.github.com/repos/zmstone/kastlex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zmstone/kastlex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zmstone/kastlex/git/refs{/sha}","trees_url":"https://api.github.com/repos/zmstone/kastlex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zmstone/kastlex/statuses/{sha}","languages_url":"https://api.github.com/repos/zmstone/kastlex/languages","stargazers_url":"https://api.github.com/repos/zmstone/kastlex/stargazers","contributors_url":"https://api.github.com/repos/zmstone/kastlex/contributors","subscribers_url":"https://api.github.com/repos/zmstone/kastlex/subscribers","subscription_url":"https://api.github.com/repos/zmstone/kastlex/subscription","commits_url":"https://api.github.com/repos/zmstone/kastlex/commits{/sha}","git_commits_url":"https://api.github.com/repos/zmstone/kastlex/git/commits{/sha}","comments_url":"https://api.github.com/repos/zmstone/kastlex/comments{/number}","issue_comment_url":"https://api.github.com/repos/zmstone/kastlex/issues/comments{/number}","contents_url":"https://api.github.com/repos/zmstone/kastlex/contents/{+path}","compare_url":"https://api.github.com/repos/zmstone/kastlex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zmstone/kastlex/merges","archive_url":"https://api.github.com/repos/zmstone/kastlex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zmstone/kastlex/downloads","issues_url":"https://api.github.com/repos/zmstone/kastlex/issues{/number}","pulls_url":"https://api.github.com/repos/zmstone/kastlex/pulls{/number}","milestones_url":"https://api.github.com/repos/zmstone/kastlex/milestones{/number}","notifications_url":"https://api.github.com/repos/zmstone/kastlex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zmstone/kastlex/labels{/name}","releases_url":"https://api.github.com/repos/zmstone/kastlex/releases{/id}","deployments_url":"https://api.github.com/repos/zmstone/kastlex/deployments","created_at":"2016-06-10T07:31:47Z","updated_at":"2016-06-10T07:31:48Z","pushed_at":"2016-10-10T15:46:22Z","git_url":"git://github.com/zmstone/kastlex.git","ssh_url":"git@github.com:zmstone/kastlex.git","clone_url":"https://github.com/zmstone/kastlex.git","svn_url":"https://github.com/zmstone/kastlex","homepage":null,"size":91,"stargazers_count":0,"watchers_count":0,"language":"Elixir","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":"master"}},"base":{"label":"id:master","ref":"master","sha":"be5228bf4559f3139cec1d9b6e05ee1388742e04","user":{"login":"id","id":138221,"avatar_url":"https://avatars.githubusercontent.com/u/138221?v=3","gravatar_id":"","url":"https://api.github.com/users/id","html_url":"https://github.com/id","followers_url":"https://api.github.com/users/id/followers","following_url":"https://api.github.com/users/id/following{/other_user}","gists_url":"https://api.github.com/users/id/gists{/gist_id}","starred_url":"https://api.github.com/users/id/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/id/subscriptions","organizations_url":"https://api.github.com/users/id/orgs","repos_url":"https://api.github.com/users/id/repos","events_url":"https://api.github.com/users/id/events{/privacy}","received_events_url":"https://api.github.com/users/id/received_events","type":"User","site_admin":false},"repo":{"id":57920862,"name":"kastlex","full_name":"id/kastlex","owner":{"login":"id","id":138221,"avatar_url":"https://avatars.githubusercontent.com/u/138221?v=3","gravatar_id":"","url":"https://api.github.com/users/id","html_url":"https://github.com/id","followers_url":"https://api.github.com/users/id/followers","following_url":"https://api.github.com/users/id/following{/other_user}","gists_url":"https://api.github.com/users/id/gists{/gist_id}","starred_url":"https://api.github.com/users/id/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/id/subscriptions","organizations_url":"https://api.github.com/users/id/orgs","repos_url":"https://api.github.com/users/id/repos","events_url":"https://api.github.com/users/id/events{/privacy}","received_events_url":"https://api.github.com/users/id/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/id/kastlex","description":"Kafka REST Proxy in Elixir","fork":false,"url":"https://api.github.com/repos/id/kastlex","forks_url":"https://api.github.com/repos/id/kastlex/forks","keys_url":"https://api.github.com/repos/id/kastlex/keys{/key_id}","collaborators_url":"https://api.github.com/repos/id/kastlex/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/id/kastlex/teams","hooks_url":"https://api.github.com/repos/id/kastlex/hooks","issue_events_url":"https://api.github.com/repos/id/kastlex/issues/events{/number}","events_url":"https://api.github.com/repos/id/kastlex/events","assignees_url":"https://api.github.com/repos/id/kastlex/assignees{/user}","branches_url":"https://api.github.com/repos/id/kastlex/branches{/branch}","tags_url":"https://api.github.com/repos/id/kastlex/tags","blobs_url":"https://api.github.com/repos/id/kastlex/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/id/kastlex/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/id/kastlex/git/refs{/sha}","trees_url":"https://api.github.com/repos/id/kastlex/git/trees{/sha}","statuses_url":"https://api.github.com/repos/id/kastlex/statuses/{sha}","languages_url":"https://api.github.com/repos/id/kastlex/languages","stargazers_url":"https://api.github.com/repos/id/kastlex/stargazers","contributors_url":"https://api.github.com/repos/id/kastlex/contributors","subscribers_url":"https://api.github.com/repos/id/kastlex/subscribers","subscription_url":"https://api.github.com/repos/id/kastlex/subscription","commits_url":"https://api.github.com/repos/id/kastlex/commits{/sha}","git_commits_url":"https://api.github.com/repos/id/kastlex/git/commits{/sha}","comments_url":"https://api.github.com/repos/id/kastlex/comments{/number}","issue_comment_url":"https://api.github.com/repos/id/kastlex/issues/comments{/number}","contents_url":"https://api.github.com/repos/id/kastlex/contents/{+path}","compare_url":"https://api.github.com/repos/id/kastlex/compare/{base}...{head}","merges_url":"https://api.github.com/repos/id/kastlex/merges","archive_url":"https://api.github.com/repos/id/kastlex/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/id/kastlex/downloads","issues_url":"https://api.github.com/repos/id/kastlex/issues{/number}","pulls_url":"https://api.github.com/repos/id/kastlex/pulls{/number}","milestones_url":"https://api.github.com/repos/id/kastlex/milestones{/number}","notifications_url":"https://api.github.com/repos/id/kastlex/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/id/kastlex/labels{/name}","releases_url":"https://api.github.com/repos/id/kastlex/releases{/id}","deployments_url":"https://api.github.com/repos/id/kastlex/deployments","created_at":"2016-05-02T20:53:01Z","updated_at":"2016-10-12T15:47:16Z","pushed_at":"2016-11-23T16:01:56Z","git_url":"git://github.com/id/kastlex.git","ssh_url":"git@github.com:id/kastlex.git","clone_url":"https://github.com/id/kastlex.git","svn_url":"https://github.com/id/kastlex","homepage":null,"size":91,"stargazers_count":6,"watchers_count":6,"language":"Elixir","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":2,"forks":4,"open_issues":2,"watchers":6,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/id/kastlex/pulls/4"},"html":{"href":"https://github.com/id/kastlex/pull/4"},"issue":{"href":"https://api.github.com/repos/id/kastlex/issues/4"},"comments":{"href":"https://api.github.com/repos/id/kastlex/issues/4/comments"},"review_comments":{"href":"https://api.github.com/repos/id/kastlex/pulls/4/comments"},"review_comment":{"href":"https://api.github.com/repos/id/kastlex/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/id/kastlex/pulls/4/commits"},"statuses":{"href":"https://api.github.com/repos/id/kastlex/statuses/2a30a3c589cac19694bb70f4d2fcb903780d5a47"}}}}
{"actor":{"display_login":"zmstone"}}