{"action":"created","comment":{"url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/comments/56237344","id":56237344,"diff_hunk":"@@ -127,6 +116,32 @@ def udp_listener(output_queue)\n     end\n   end # def udp_listener\n \n+  # generate a new LogStash::Event from json input and assign host to source_host event field.\n+  # @param json_gelf [String] GELF json data\n+  # @param host [String] source host of GELF data\n+  # @return [LogStash::Event] new event with parsed json gelf, assigned source host and coerced timestamp\n+  def self.new_event(json_gelf, host)\n+    event = LogStash::Event.new(LogStash::Json.load(json_gelf))\n+\n+    event[SOURCE_HOST_FIELD] = host\n+\n+    if (gelf_timestamp = event[TIMESTAMP_GELF_FIELD]).is_a?(Numeric)\n+      event.timestamp = self.coerce_timestamp(gelf_timestamp)\n+      event.remove(TIMESTAMP_GELF_FIELD)\n+    end\n+\n+    event\n+  end\n+\n+  # transform a given timestamp value into a proper LogStash::Timestamp, preserving microsecond precision\n+  # and work around a JRuby issue with Time.at loosing fractional part with BigDecimal.\n+  # @param timestamp [String|Numeric] a String, Numeric (integer, float or bigdecimal) representation\n+  # @return [LogStash::Timestamp] the proper LogStash::Timestamp representation\n+  def self.coerce_timestamp(timestamp)\n+    # bug in JRuby prevents correcly parsing a BigDecimal fractional part, see https://github.com/elastic/logstash/issues/4565\n+    LogStash::Timestamp.at(timestamp.to_i, BigDecimal.new(timestamp.to_s).frac * 1000000)","path":"lib/logstash/inputs/gelf.rb","position":58,"original_position":58,"commit_id":"803f9e42dfe26e409b7da610d2445b1c754e46e4","original_commit_id":"803f9e42dfe26e409b7da610d2445b1c754e46e4","user":{"login":"alex88","id":436888,"avatar_url":"https://avatars.githubusercontent.com/u/436888?v=3","gravatar_id":"","url":"https://api.github.com/users/alex88","html_url":"https://github.com/alex88","followers_url":"https://api.github.com/users/alex88/followers","following_url":"https://api.github.com/users/alex88/following{/other_user}","gists_url":"https://api.github.com/users/alex88/gists{/gist_id}","starred_url":"https://api.github.com/users/alex88/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alex88/subscriptions","organizations_url":"https://api.github.com/users/alex88/orgs","repos_url":"https://api.github.com/users/alex88/repos","events_url":"https://api.github.com/users/alex88/events{/privacy}","received_events_url":"https://api.github.com/users/alex88/received_events","type":"User","site_admin":false},"body":"Maybe I've forgot something in the meantime, but why not just use:\r\n\r\n```\r\nLogStash::Timestamp.at(BigDecimal.new(timestamp.to_s).to_f)\r\n```\r\n\r\ninstead of\r\n\r\n```\r\nLogStash::Timestamp.at(timestamp.to_i, BigDecimal.new(timestamp.to_s).frac * 1000000)\r\n```\r\n\r\nfrom my tests [here](https://github.com/jruby/jruby/issues/3616) seems to fix the issue too and it's shorter an maybe even faster","created_at":"2016-03-15T20:45:12Z","updated_at":"2016-03-15T20:45:12Z","html_url":"https://github.com/logstash-plugins/logstash-input-gelf/pull/35#discussion_r56237344","pull_request_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/35","_links":{"self":{"href":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/comments/56237344"},"html":{"href":"https://github.com/logstash-plugins/logstash-input-gelf/pull/35#discussion_r56237344"},"pull_request":{"href":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/35"}}},"pull_request":{"url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/35","id":62968574,"html_url":"https://github.com/logstash-plugins/logstash-input-gelf/pull/35","diff_url":"https://github.com/logstash-plugins/logstash-input-gelf/pull/35.diff","patch_url":"https://github.com/logstash-plugins/logstash-input-gelf/pull/35.patch","issue_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues/35","number":35,"state":"open","locked":false,"title":"proper timestamp coercion to preserve microsecond precision","user":{"login":"colinsurprenant","id":2010,"avatar_url":"https://avatars.githubusercontent.com/u/2010?v=3","gravatar_id":"","url":"https://api.github.com/users/colinsurprenant","html_url":"https://github.com/colinsurprenant","followers_url":"https://api.github.com/users/colinsurprenant/followers","following_url":"https://api.github.com/users/colinsurprenant/following{/other_user}","gists_url":"https://api.github.com/users/colinsurprenant/gists{/gist_id}","starred_url":"https://api.github.com/users/colinsurprenant/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/colinsurprenant/subscriptions","organizations_url":"https://api.github.com/users/colinsurprenant/orgs","repos_url":"https://api.github.com/users/colinsurprenant/repos","events_url":"https://api.github.com/users/colinsurprenant/events{/privacy}","received_events_url":"https://api.github.com/users/colinsurprenant/received_events","type":"User","site_admin":false},"body":"this refactors, extends and replaces #32\r\nthis will fix elastic/logstash#4565","created_at":"2016-03-15T20:07:43Z","updated_at":"2016-03-15T20:45:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"989acb654bc07a16550464c2d8250d6e2b1b5e5f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/35/commits","review_comments_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/35/comments","review_comment_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/comments{/number}","comments_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues/35/comments","statuses_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/statuses/803f9e42dfe26e409b7da610d2445b1c754e46e4","head":{"label":"logstash-plugins:pr/32","ref":"pr/32","sha":"803f9e42dfe26e409b7da610d2445b1c754e46e4","user":{"login":"logstash-plugins","id":8961934,"avatar_url":"https://avatars.githubusercontent.com/u/8961934?v=3","gravatar_id":"","url":"https://api.github.com/users/logstash-plugins","html_url":"https://github.com/logstash-plugins","followers_url":"https://api.github.com/users/logstash-plugins/followers","following_url":"https://api.github.com/users/logstash-plugins/following{/other_user}","gists_url":"https://api.github.com/users/logstash-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/logstash-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logstash-plugins/subscriptions","organizations_url":"https://api.github.com/users/logstash-plugins/orgs","repos_url":"https://api.github.com/users/logstash-plugins/repos","events_url":"https://api.github.com/users/logstash-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/logstash-plugins/received_events","type":"Organization","site_admin":false},"repo":{"id":25312463,"name":"logstash-input-gelf","full_name":"logstash-plugins/logstash-input-gelf","owner":{"login":"logstash-plugins","id":8961934,"avatar_url":"https://avatars.githubusercontent.com/u/8961934?v=3","gravatar_id":"","url":"https://api.github.com/users/logstash-plugins","html_url":"https://github.com/logstash-plugins","followers_url":"https://api.github.com/users/logstash-plugins/followers","following_url":"https://api.github.com/users/logstash-plugins/following{/other_user}","gists_url":"https://api.github.com/users/logstash-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/logstash-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logstash-plugins/subscriptions","organizations_url":"https://api.github.com/users/logstash-plugins/orgs","repos_url":"https://api.github.com/users/logstash-plugins/repos","events_url":"https://api.github.com/users/logstash-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/logstash-plugins/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/logstash-plugins/logstash-input-gelf","description":null,"fork":false,"url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf","forks_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/forks","keys_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/teams","hooks_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/hooks","issue_events_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues/events{/number}","events_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/events","assignees_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/assignees{/user}","branches_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/branches{/branch}","tags_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/tags","blobs_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/refs{/sha}","trees_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/statuses/{sha}","languages_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/languages","stargazers_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/stargazers","contributors_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/contributors","subscribers_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/subscribers","subscription_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/subscription","commits_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/commits{/sha}","git_commits_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/commits{/sha}","comments_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/comments{/number}","issue_comment_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues/comments{/number}","contents_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/contents/{+path}","compare_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/merges","archive_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/downloads","issues_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues{/number}","pulls_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls{/number}","milestones_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/milestones{/number}","notifications_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/labels{/name}","releases_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/releases{/id}","deployments_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/deployments","created_at":"2014-10-16T17:03:07Z","updated_at":"2016-02-23T20:46:35Z","pushed_at":"2016-03-15T20:07:44Z","git_url":"git://github.com/logstash-plugins/logstash-input-gelf.git","ssh_url":"git@github.com:logstash-plugins/logstash-input-gelf.git","clone_url":"https://github.com/logstash-plugins/logstash-input-gelf.git","svn_url":"https://github.com/logstash-plugins/logstash-input-gelf","homepage":null,"size":42,"stargazers_count":2,"watchers_count":2,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":25,"forks":15,"open_issues":25,"watchers":2,"default_branch":"master"}},"base":{"label":"logstash-plugins:master","ref":"master","sha":"03794c8c6a82e5b440485a9711a471c40278415e","user":{"login":"logstash-plugins","id":8961934,"avatar_url":"https://avatars.githubusercontent.com/u/8961934?v=3","gravatar_id":"","url":"https://api.github.com/users/logstash-plugins","html_url":"https://github.com/logstash-plugins","followers_url":"https://api.github.com/users/logstash-plugins/followers","following_url":"https://api.github.com/users/logstash-plugins/following{/other_user}","gists_url":"https://api.github.com/users/logstash-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/logstash-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logstash-plugins/subscriptions","organizations_url":"https://api.github.com/users/logstash-plugins/orgs","repos_url":"https://api.github.com/users/logstash-plugins/repos","events_url":"https://api.github.com/users/logstash-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/logstash-plugins/received_events","type":"Organization","site_admin":false},"repo":{"id":25312463,"name":"logstash-input-gelf","full_name":"logstash-plugins/logstash-input-gelf","owner":{"login":"logstash-plugins","id":8961934,"avatar_url":"https://avatars.githubusercontent.com/u/8961934?v=3","gravatar_id":"","url":"https://api.github.com/users/logstash-plugins","html_url":"https://github.com/logstash-plugins","followers_url":"https://api.github.com/users/logstash-plugins/followers","following_url":"https://api.github.com/users/logstash-plugins/following{/other_user}","gists_url":"https://api.github.com/users/logstash-plugins/gists{/gist_id}","starred_url":"https://api.github.com/users/logstash-plugins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/logstash-plugins/subscriptions","organizations_url":"https://api.github.com/users/logstash-plugins/orgs","repos_url":"https://api.github.com/users/logstash-plugins/repos","events_url":"https://api.github.com/users/logstash-plugins/events{/privacy}","received_events_url":"https://api.github.com/users/logstash-plugins/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/logstash-plugins/logstash-input-gelf","description":null,"fork":false,"url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf","forks_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/forks","keys_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/keys{/key_id}","collaborators_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/teams","hooks_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/hooks","issue_events_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues/events{/number}","events_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/events","assignees_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/assignees{/user}","branches_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/branches{/branch}","tags_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/tags","blobs_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/refs{/sha}","trees_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/trees{/sha}","statuses_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/statuses/{sha}","languages_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/languages","stargazers_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/stargazers","contributors_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/contributors","subscribers_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/subscribers","subscription_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/subscription","commits_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/commits{/sha}","git_commits_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/git/commits{/sha}","comments_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/comments{/number}","issue_comment_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues/comments{/number}","contents_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/contents/{+path}","compare_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/compare/{base}...{head}","merges_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/merges","archive_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/downloads","issues_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues{/number}","pulls_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls{/number}","milestones_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/milestones{/number}","notifications_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/labels{/name}","releases_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/releases{/id}","deployments_url":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/deployments","created_at":"2014-10-16T17:03:07Z","updated_at":"2016-02-23T20:46:35Z","pushed_at":"2016-03-15T20:07:44Z","git_url":"git://github.com/logstash-plugins/logstash-input-gelf.git","ssh_url":"git@github.com:logstash-plugins/logstash-input-gelf.git","clone_url":"https://github.com/logstash-plugins/logstash-input-gelf.git","svn_url":"https://github.com/logstash-plugins/logstash-input-gelf","homepage":null,"size":42,"stargazers_count":2,"watchers_count":2,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":15,"mirror_url":null,"open_issues_count":25,"forks":15,"open_issues":25,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/35"},"html":{"href":"https://github.com/logstash-plugins/logstash-input-gelf/pull/35"},"issue":{"href":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues/35"},"comments":{"href":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/issues/35/comments"},"review_comments":{"href":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/35/comments"},"review_comment":{"href":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/pulls/35/commits"},"statuses":{"href":"https://api.github.com/repos/logstash-plugins/logstash-input-gelf/statuses/803f9e42dfe26e409b7da610d2445b1c754e46e4"}}}}