{"action":"created","comment":{"url":"https://api.github.com/repos/lenshq/lens_server/pulls/comments/43537334","id":43537334,"diff_hunk":"@@ -0,0 +1,134 @@\n+class ProcessRawEvent\n+  def self.call(*args)\n+    new(*args).call\n+  end\n+\n+  def initialize(raw_event_id)\n+    @raw_event_id = raw_event_id\n+  end\n+\n+  def call\n+    raw_event = RawEvent.find_by(id: @raw_event_id)\n+    process_raw_event(raw_event) if raw_event.present?\n+  end\n+\n+  def process_raw_event(raw_event)\n+    application = raw_event.application\n+\n+    parsed_data = parse_raw_data(raw_event)\n+\n+    meta = parsed_data[:meta]\n+    details = parsed_data[:details]\n+    details = add_transactions_to_details(details)\n+    scenario_hash = generate_scenario_hash(details)\n+\n+    event_source = find_or_create_event_source(application: application, meta: meta)\n+    scenario = find_or_create_scnario(event_source: event_source, hash: scenario_hash)\n+    create_request(scenario: scenario, raw_event: raw_event, meta: meta)\n+\n+    events = details.each_with_index.map do |row, index|\n+      event_hash(scenario: scenario, details: row, meta: meta, index: index)\n+    end\n+\n+    store_events(events)\n+  end\n+\n+  def store_events(events)\n+    messages = events.map do |hash|\n+      Poseidon::MessageToSend.new(LensServer.config.kafka.topic, hash.to_json)\n+    end\n+\n+    kafka_producer.send_messages(messages)\n+  end\n+\n+  def parse_raw_data(raw_event)\n+    data = JSON.parse(raw_event.data)\n+    Parser.new(data).parse\n+  end\n+\n+  def find_or_create_event_source(application:, meta:)\n+    application.event_sources.find_or_create_by(source: meta[:controller], endpoint: meta[:action])\n+  end\n+\n+  def find_or_create_scnario(event_source:, hash:)\n+    event_source.scenarios.find_or_create_by(events_hash: hash)\n+  end\n+\n+  def create_request(scenario:, raw_event:, meta:)\n+    event_source = scenario.event_source\n+\n+    scenario.requests.create(\n+      event_source_id: event_source.id,\n+      application_id: event_source.application.id,\n+      controller: meta[:controller],\n+      action: meta[:action],\n+      duration: meta[:duration],\n+      started_at: meta[:start],\n+      finished_at: meta[:finish],\n+      raw_event_id: raw_event.id\n+    )\n+  end\n+\n+  def generate_scenario_hash(details)\n+    Scenario.hash_from_string(details.inject('') { |a, d| a << d[:type] })\n+  end\n+\n+  def kafka_producer\n+    @producer ||= begin\n+                    klass = LensServer.config.service_locator.kafka_producer\n+                    klass.new(\n+                      [\"#{LensServer.config.kafka.host}:#{LensServer.config.kafka.port}\"],\n+                      'lens_bg_producer'\n+                    )\n+                  end\n+  end\n+\n+  def base_hash(scenario:, meta:)\n+    @base_hash ||=\n+      {\n+        application: scenario.event_source.application.id,\n+        scenario: scenario.events_hash,\n+        conroller: meta[:controller],\n+        action: meta[:action]\n+      }\n+  end\n+\n+  def event_hash(scenario:, details:, meta:, index:)\n+    base_hash(scenario: scenario, meta: meta).merge({","path":"app/commands/process_raw_event.rb","position":97,"original_position":97,"commit_id":"d6ef7297326383a5c1b9e1c4662a0578b2df783d","original_commit_id":"d6ef7297326383a5c1b9e1c4662a0578b2df783d","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Redundant curly braces around a hash parameter.","created_at":"2015-10-30T18:35:12Z","updated_at":"2015-10-30T18:35:12Z","html_url":"https://github.com/lenshq/lens_server/pull/43#discussion_r43537334","pull_request_url":"https://api.github.com/repos/lenshq/lens_server/pulls/43","_links":{"self":{"href":"https://api.github.com/repos/lenshq/lens_server/pulls/comments/43537334"},"html":{"href":"https://github.com/lenshq/lens_server/pull/43#discussion_r43537334"},"pull_request":{"href":"https://api.github.com/repos/lenshq/lens_server/pulls/43"}}},"pull_request":{"url":"https://api.github.com/repos/lenshq/lens_server/pulls/43","id":49220089,"html_url":"https://github.com/lenshq/lens_server/pull/43","diff_url":"https://github.com/lenshq/lens_server/pull/43.diff","patch_url":"https://github.com/lenshq/lens_server/pull/43.patch","issue_url":"https://api.github.com/repos/lenshq/lens_server/issues/43","number":43,"state":"open","locked":false,"title":"[WIP] [NO MERGE] Feature/druid","user":{"login":"zzet","id":510788,"avatar_url":"https://avatars.githubusercontent.com/u/510788?v=3","gravatar_id":"","url":"https://api.github.com/users/zzet","html_url":"https://github.com/zzet","followers_url":"https://api.github.com/users/zzet/followers","following_url":"https://api.github.com/users/zzet/following{/other_user}","gists_url":"https://api.github.com/users/zzet/gists{/gist_id}","starred_url":"https://api.github.com/users/zzet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zzet/subscriptions","organizations_url":"https://api.github.com/users/zzet/orgs","repos_url":"https://api.github.com/users/zzet/repos","events_url":"https://api.github.com/users/zzet/events{/privacy}","received_events_url":"https://api.github.com/users/zzet/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-10-30T00:55:48Z","updated_at":"2015-10-30T18:35:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1bfc5929ad295cbd0212a3cd00a8c0151d00fd00","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/lenshq/lens_server/pulls/43/commits","review_comments_url":"https://api.github.com/repos/lenshq/lens_server/pulls/43/comments","review_comment_url":"https://api.github.com/repos/lenshq/lens_server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/lenshq/lens_server/issues/43/comments","statuses_url":"https://api.github.com/repos/lenshq/lens_server/statuses/d6ef7297326383a5c1b9e1c4662a0578b2df783d","head":{"label":"lenshq:feature/druid","ref":"feature/druid","sha":"d6ef7297326383a5c1b9e1c4662a0578b2df783d","user":{"login":"lenshq","id":13371271,"avatar_url":"https://avatars.githubusercontent.com/u/13371271?v=3","gravatar_id":"","url":"https://api.github.com/users/lenshq","html_url":"https://github.com/lenshq","followers_url":"https://api.github.com/users/lenshq/followers","following_url":"https://api.github.com/users/lenshq/following{/other_user}","gists_url":"https://api.github.com/users/lenshq/gists{/gist_id}","starred_url":"https://api.github.com/users/lenshq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lenshq/subscriptions","organizations_url":"https://api.github.com/users/lenshq/orgs","repos_url":"https://api.github.com/users/lenshq/repos","events_url":"https://api.github.com/users/lenshq/events{/privacy}","received_events_url":"https://api.github.com/users/lenshq/received_events","type":"Organization","site_admin":false},"repo":{"id":39218913,"name":"lens_server","full_name":"lenshq/lens_server","owner":{"login":"lenshq","id":13371271,"avatar_url":"https://avatars.githubusercontent.com/u/13371271?v=3","gravatar_id":"","url":"https://api.github.com/users/lenshq","html_url":"https://github.com/lenshq","followers_url":"https://api.github.com/users/lenshq/followers","following_url":"https://api.github.com/users/lenshq/following{/other_user}","gists_url":"https://api.github.com/users/lenshq/gists{/gist_id}","starred_url":"https://api.github.com/users/lenshq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lenshq/subscriptions","organizations_url":"https://api.github.com/users/lenshq/orgs","repos_url":"https://api.github.com/users/lenshq/repos","events_url":"https://api.github.com/users/lenshq/events{/privacy}","received_events_url":"https://api.github.com/users/lenshq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lenshq/lens_server","description":"Back-end part of Lens – profiling tool for Rails apps","fork":false,"url":"https://api.github.com/repos/lenshq/lens_server","forks_url":"https://api.github.com/repos/lenshq/lens_server/forks","keys_url":"https://api.github.com/repos/lenshq/lens_server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lenshq/lens_server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lenshq/lens_server/teams","hooks_url":"https://api.github.com/repos/lenshq/lens_server/hooks","issue_events_url":"https://api.github.com/repos/lenshq/lens_server/issues/events{/number}","events_url":"https://api.github.com/repos/lenshq/lens_server/events","assignees_url":"https://api.github.com/repos/lenshq/lens_server/assignees{/user}","branches_url":"https://api.github.com/repos/lenshq/lens_server/branches{/branch}","tags_url":"https://api.github.com/repos/lenshq/lens_server/tags","blobs_url":"https://api.github.com/repos/lenshq/lens_server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lenshq/lens_server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lenshq/lens_server/git/refs{/sha}","trees_url":"https://api.github.com/repos/lenshq/lens_server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lenshq/lens_server/statuses/{sha}","languages_url":"https://api.github.com/repos/lenshq/lens_server/languages","stargazers_url":"https://api.github.com/repos/lenshq/lens_server/stargazers","contributors_url":"https://api.github.com/repos/lenshq/lens_server/contributors","subscribers_url":"https://api.github.com/repos/lenshq/lens_server/subscribers","subscription_url":"https://api.github.com/repos/lenshq/lens_server/subscription","commits_url":"https://api.github.com/repos/lenshq/lens_server/commits{/sha}","git_commits_url":"https://api.github.com/repos/lenshq/lens_server/git/commits{/sha}","comments_url":"https://api.github.com/repos/lenshq/lens_server/comments{/number}","issue_comment_url":"https://api.github.com/repos/lenshq/lens_server/issues/comments{/number}","contents_url":"https://api.github.com/repos/lenshq/lens_server/contents/{+path}","compare_url":"https://api.github.com/repos/lenshq/lens_server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lenshq/lens_server/merges","archive_url":"https://api.github.com/repos/lenshq/lens_server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lenshq/lens_server/downloads","issues_url":"https://api.github.com/repos/lenshq/lens_server/issues{/number}","pulls_url":"https://api.github.com/repos/lenshq/lens_server/pulls{/number}","milestones_url":"https://api.github.com/repos/lenshq/lens_server/milestones{/number}","notifications_url":"https://api.github.com/repos/lenshq/lens_server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lenshq/lens_server/labels{/name}","releases_url":"https://api.github.com/repos/lenshq/lens_server/releases{/id}","created_at":"2015-07-16T20:27:58Z","updated_at":"2015-10-24T13:40:19Z","pushed_at":"2015-10-30T18:35:06Z","git_url":"git://github.com/lenshq/lens_server.git","ssh_url":"git@github.com:lenshq/lens_server.git","clone_url":"https://github.com/lenshq/lens_server.git","svn_url":"https://github.com/lenshq/lens_server","homepage":"http://lenshq.io","size":1164,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":14,"forks":0,"open_issues":14,"watchers":0,"default_branch":"master"}},"base":{"label":"lenshq:master","ref":"master","sha":"13d694ed6a919e07053681f76b78cb932a6510ff","user":{"login":"lenshq","id":13371271,"avatar_url":"https://avatars.githubusercontent.com/u/13371271?v=3","gravatar_id":"","url":"https://api.github.com/users/lenshq","html_url":"https://github.com/lenshq","followers_url":"https://api.github.com/users/lenshq/followers","following_url":"https://api.github.com/users/lenshq/following{/other_user}","gists_url":"https://api.github.com/users/lenshq/gists{/gist_id}","starred_url":"https://api.github.com/users/lenshq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lenshq/subscriptions","organizations_url":"https://api.github.com/users/lenshq/orgs","repos_url":"https://api.github.com/users/lenshq/repos","events_url":"https://api.github.com/users/lenshq/events{/privacy}","received_events_url":"https://api.github.com/users/lenshq/received_events","type":"Organization","site_admin":false},"repo":{"id":39218913,"name":"lens_server","full_name":"lenshq/lens_server","owner":{"login":"lenshq","id":13371271,"avatar_url":"https://avatars.githubusercontent.com/u/13371271?v=3","gravatar_id":"","url":"https://api.github.com/users/lenshq","html_url":"https://github.com/lenshq","followers_url":"https://api.github.com/users/lenshq/followers","following_url":"https://api.github.com/users/lenshq/following{/other_user}","gists_url":"https://api.github.com/users/lenshq/gists{/gist_id}","starred_url":"https://api.github.com/users/lenshq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lenshq/subscriptions","organizations_url":"https://api.github.com/users/lenshq/orgs","repos_url":"https://api.github.com/users/lenshq/repos","events_url":"https://api.github.com/users/lenshq/events{/privacy}","received_events_url":"https://api.github.com/users/lenshq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/lenshq/lens_server","description":"Back-end part of Lens – profiling tool for Rails apps","fork":false,"url":"https://api.github.com/repos/lenshq/lens_server","forks_url":"https://api.github.com/repos/lenshq/lens_server/forks","keys_url":"https://api.github.com/repos/lenshq/lens_server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lenshq/lens_server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lenshq/lens_server/teams","hooks_url":"https://api.github.com/repos/lenshq/lens_server/hooks","issue_events_url":"https://api.github.com/repos/lenshq/lens_server/issues/events{/number}","events_url":"https://api.github.com/repos/lenshq/lens_server/events","assignees_url":"https://api.github.com/repos/lenshq/lens_server/assignees{/user}","branches_url":"https://api.github.com/repos/lenshq/lens_server/branches{/branch}","tags_url":"https://api.github.com/repos/lenshq/lens_server/tags","blobs_url":"https://api.github.com/repos/lenshq/lens_server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lenshq/lens_server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lenshq/lens_server/git/refs{/sha}","trees_url":"https://api.github.com/repos/lenshq/lens_server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lenshq/lens_server/statuses/{sha}","languages_url":"https://api.github.com/repos/lenshq/lens_server/languages","stargazers_url":"https://api.github.com/repos/lenshq/lens_server/stargazers","contributors_url":"https://api.github.com/repos/lenshq/lens_server/contributors","subscribers_url":"https://api.github.com/repos/lenshq/lens_server/subscribers","subscription_url":"https://api.github.com/repos/lenshq/lens_server/subscription","commits_url":"https://api.github.com/repos/lenshq/lens_server/commits{/sha}","git_commits_url":"https://api.github.com/repos/lenshq/lens_server/git/commits{/sha}","comments_url":"https://api.github.com/repos/lenshq/lens_server/comments{/number}","issue_comment_url":"https://api.github.com/repos/lenshq/lens_server/issues/comments{/number}","contents_url":"https://api.github.com/repos/lenshq/lens_server/contents/{+path}","compare_url":"https://api.github.com/repos/lenshq/lens_server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lenshq/lens_server/merges","archive_url":"https://api.github.com/repos/lenshq/lens_server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lenshq/lens_server/downloads","issues_url":"https://api.github.com/repos/lenshq/lens_server/issues{/number}","pulls_url":"https://api.github.com/repos/lenshq/lens_server/pulls{/number}","milestones_url":"https://api.github.com/repos/lenshq/lens_server/milestones{/number}","notifications_url":"https://api.github.com/repos/lenshq/lens_server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lenshq/lens_server/labels{/name}","releases_url":"https://api.github.com/repos/lenshq/lens_server/releases{/id}","created_at":"2015-07-16T20:27:58Z","updated_at":"2015-10-24T13:40:19Z","pushed_at":"2015-10-30T18:35:06Z","git_url":"git://github.com/lenshq/lens_server.git","ssh_url":"git@github.com:lenshq/lens_server.git","clone_url":"https://github.com/lenshq/lens_server.git","svn_url":"https://github.com/lenshq/lens_server","homepage":"http://lenshq.io","size":1164,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":14,"forks":0,"open_issues":14,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/lenshq/lens_server/pulls/43"},"html":{"href":"https://github.com/lenshq/lens_server/pull/43"},"issue":{"href":"https://api.github.com/repos/lenshq/lens_server/issues/43"},"comments":{"href":"https://api.github.com/repos/lenshq/lens_server/issues/43/comments"},"review_comments":{"href":"https://api.github.com/repos/lenshq/lens_server/pulls/43/comments"},"review_comment":{"href":"https://api.github.com/repos/lenshq/lens_server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/lenshq/lens_server/pulls/43/commits"},"statuses":{"href":"https://api.github.com/repos/lenshq/lens_server/statuses/d6ef7297326383a5c1b9e1c4662a0578b2df783d"}}}}