{"action":"created","comment":{"url":"https://api.github.com/repos/rbkmoney/machinegun/pulls/comments/236302488","pull_request_review_id":178332624,"id":236302488,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNjMwMjQ4OA==","diff_hunk":"@@ -0,0 +1,129 @@\n+%%%\n+%%% Copyright 2018 RBKmoney\n+%%%\n+%%% Licensed under the Apache License, Version 2.0 (the \"License\");\n+%%% you may not use this file except in compliance with the License.\n+%%% You may obtain a copy of the License at\n+%%%\n+%%%     http://www.apache.org/licenses/LICENSE-2.0\n+%%%\n+%%% Unless required by applicable law or agreed to in writing, software\n+%%% distributed under the License is distributed on an \"AS IS\" BASIS,\n+%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+%%% See the License for the specific language governing permissions and\n+%%% limitations under the License.\n+%%%\n+\n+-module(mg_woody_api_pulse_log).\n+\n+-include_lib(\"mg/include/pulse.hrl\").\n+-include_lib(\"mg_woody_api/include/pulse.hrl\").\n+\n+%% mg_pulse handler\n+-behaviour(mg_pulse).\n+-export([handle_beat/2]).\n+\n+%% internal types\n+-type log_msg() :: mg_woody_api_log:log_msg().\n+-type meta() :: mg_woody_api_log:meta().\n+-type beat() :: mg_woody_api_pulse:beat().\n+\n+%%\n+%% mg_pulse handler\n+%%\n+\n+-spec handle_beat(undefined, beat()) ->\n+    ok.\n+handle_beat(undefined, Beat) ->\n+    ok = mg_woody_api_log:log(format_beat(Beat)).\n+\n+%% Internals\n+\n+-define(beat_to_meta(RecordName, Record),\n+    lists:flatten([\n+        extract_meta(FiledName, Value) ||\n+        {FiledName, Value} <- lists:zip(\n+            record_info(fields, RecordName),\n+            erlang:tl(erlang:tuple_to_list(Record))\n+        )\n+    ])\n+).\n+\n+-spec format_beat(beat()) ->\n+    log_msg() | undefined.\n+format_beat(#woody_request_handle_error{exception = {_, {logic, _} = Reason, _}} = Beat) ->\n+    % бизнес ошибки это не warning\n+    Context = ?beat_to_meta(woody_request_handle_error, Beat),\n+    {info, {\"request handling failed ~p\", [Reason]}, Context};\n+format_beat(#woody_request_handle_error{exception = {_, Reason, _}} = Beat) ->\n+    Context = ?beat_to_meta(woody_request_handle_error, Beat),\n+    {warning, {\"request handling failed ~p\", [Reason]}, Context};\n+format_beat(#woody_internal_event{event = Event, rpc_id = RPCID, event_meta = EventMeta}) ->\n+    WoodyMetaFields = [event, service, function, type, metadata, url, deadline],\n+    {Level, Msg, Meta} = woody_event_handler:format_event_and_meta(Event, EventMeta, RPCID, WoodyMetaFields),\n+    {Level, Msg, maps:to_list(Meta)};\n+format_beat(#mg_scheduler_error{tag = Tag, exception = {_, Reason, _}} = Beat) ->\n+    Context = ?beat_to_meta(mg_scheduler_error, Beat),\n+    {warning, {\"sheduler task ~p failed ~p\", [Tag, Reason]}, Context};\n+format_beat(#mg_machine_process_transient_error{exception = {_, Reason, _}} = Beat) ->\n+    Context = ?beat_to_meta(mg_machine_process_transient_error, Beat),\n+    case Beat#mg_machine_process_transient_error.retry_action of\n+        {wait, Timeout, _} ->\n+            {warning, {\"transient error ~p, retrying in ~p msec\", [Reason, Timeout]}, Context};\n+        finish ->\n+            {warning, {\"transient error ~p, retires exhausted\", [Reason]}, Context}\n+    end;\n+format_beat(#mg_machine_lifecycle_failed{exception = {_, Reason, _}} = Beat) ->\n+    Context = ?beat_to_meta(mg_machine_lifecycle_failed, Beat),\n+    {error, {\"machine failed ~p\", [Reason]}, Context};\n+format_beat(#mg_machine_lifecycle_loading_error{exception = {_, Reason, _}} = Beat) ->\n+    Context = ?beat_to_meta(mg_machine_lifecycle_loading_error, Beat),\n+    {error, {\"loading failed ~p\", [Reason]}, Context};\n+format_beat(#mg_machine_lifecycle_committed_suicide{} = Beat) ->\n+    Context = ?beat_to_meta(mg_machine_lifecycle_committed_suicide, Beat),\n+    {info, {\"machine has committed suicide\", []}, Context};\n+format_beat(#mg_timer_lifecycle_rescheduled{target_timestamp = TS, attempt = Attempt} = Beat) ->\n+    Context = ?beat_to_meta(mg_timer_lifecycle_rescheduled, Beat),\n+    {info, {\"machine rescheduled to ~s, attempt ~p\", [format_timestamp(TS), Attempt]}, Context};\n+format_beat(#mg_timer_lifecycle_rescheduling_error{exception = {_, Reason, _}} = Beat) ->\n+    Context = ?beat_to_meta(mg_timer_lifecycle_rescheduling_error, Beat),\n+    {info, {\"machine rescheduling failed ~p\", [Reason]}, Context};\n+format_beat(_Beat) ->\n+    undefined.\n+\n+-spec extract_meta(atom(), any()) ->\n+    [meta()] | meta().\n+extract_meta(_Name, undefined) ->\n+    [];\n+extract_meta(request_context, null) ->\n+    [];\n+extract_meta(request_context, ReqCtx) ->\n+    #{rpc_id := RPCID} = mg_woody_api_utils:opaque_to_woody_context(ReqCtx),\n+    maps:to_list(RPCID);\n+extract_meta(deadline, Deadline) when is_integer(Deadline) ->\n+    {deadline, format_timestamp(Deadline div 1000)};  % Deadline measured in millisecond\n+extract_meta(target_timestamp, Timestamp) ->\n+    {target_timestamp, format_timestamp(Timestamp)};\n+extract_meta(exception, {Class, Reason, StackStrace}) ->\n+    [","path":"apps/mg_woody_api/src/mg_woody_api_pulse_log.erl","position":108,"original_position":108,"commit_id":"c3d7a6e732a3d3507cceb2854bf038db4d0af8d0","original_commit_id":"c3d7a6e732a3d3507cceb2854bf038db4d0af8d0","user":{"login":"keynslug","id":1148366,"node_id":"MDQ6VXNlcjExNDgzNjY=","avatar_url":"https://avatars0.githubusercontent.com/u/1148366?v=4","gravatar_id":"","url":"https://api.github.com/users/keynslug","html_url":"https://github.com/keynslug","followers_url":"https://api.github.com/users/keynslug/followers","following_url":"https://api.github.com/users/keynslug/following{/other_user}","gists_url":"https://api.github.com/users/keynslug/gists{/gist_id}","starred_url":"https://api.github.com/users/keynslug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keynslug/subscriptions","organizations_url":"https://api.github.com/users/keynslug/orgs","repos_url":"https://api.github.com/users/keynslug/repos","events_url":"https://api.github.com/users/keynslug/events{/privacy}","received_events_url":"https://api.github.com/users/keynslug/received_events","type":"User","site_admin":false},"body":"Не разумнее было бы сделать `{error, [{class, ...}, ...]}`?","created_at":"2018-11-26T15:34:54Z","updated_at":"2018-11-26T15:37:28Z","html_url":"https://github.com/rbkmoney/machinegun/pull/110#discussion_r236302488","pull_request_url":"https://api.github.com/repos/rbkmoney/machinegun/pulls/110","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/rbkmoney/machinegun/pulls/comments/236302488"},"html":{"href":"https://github.com/rbkmoney/machinegun/pull/110#discussion_r236302488"},"pull_request":{"href":"https://api.github.com/repos/rbkmoney/machinegun/pulls/110"}}},"pull_request":{"url":"https://api.github.com/repos/rbkmoney/machinegun/pulls/110","id":230908791,"node_id":"MDExOlB1bGxSZXF1ZXN0MjMwOTA4Nzkx","html_url":"https://github.com/rbkmoney/machinegun/pull/110","diff_url":"https://github.com/rbkmoney/machinegun/pull/110.diff","patch_url":"https://github.com/rbkmoney/machinegun/pull/110.patch","issue_url":"https://api.github.com/repos/rbkmoney/machinegun/issues/110","number":110,"state":"open","locked":false,"title":"MG-137 Add metrics collecting","user":{"login":"ciiol","id":425290,"node_id":"MDQ6VXNlcjQyNTI5MA==","avatar_url":"https://avatars2.githubusercontent.com/u/425290?v=4","gravatar_id":"","url":"https://api.github.com/users/ciiol","html_url":"https://github.com/ciiol","followers_url":"https://api.github.com/users/ciiol/followers","following_url":"https://api.github.com/users/ciiol/following{/other_user}","gists_url":"https://api.github.com/users/ciiol/gists{/gist_id}","starred_url":"https://api.github.com/users/ciiol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciiol/subscriptions","organizations_url":"https://api.github.com/users/ciiol/orgs","repos_url":"https://api.github.com/users/ciiol/repos","events_url":"https://api.github.com/users/ciiol/events{/privacy}","received_events_url":"https://api.github.com/users/ciiol/received_events","type":"User","site_admin":false},"body":"Добавляется более общая система внутренних событий вместо использовавшейся для логирования.\r\nНа основе этих событий реализуется сбор различных метрик о внутреннем состоянии.\r\n","created_at":"2018-11-14T16:55:11Z","updated_at":"2018-11-26T15:37:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d17d56be03fff1bd8d4331228985b194d62189b7","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rbkmoney/machinegun/pulls/110/commits","review_comments_url":"https://api.github.com/repos/rbkmoney/machinegun/pulls/110/comments","review_comment_url":"https://api.github.com/repos/rbkmoney/machinegun/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rbkmoney/machinegun/issues/110/comments","statuses_url":"https://api.github.com/repos/rbkmoney/machinegun/statuses/c3d7a6e732a3d3507cceb2854bf038db4d0af8d0","head":{"label":"ciiol:MG-137/ft/metrics","ref":"MG-137/ft/metrics","sha":"c3d7a6e732a3d3507cceb2854bf038db4d0af8d0","user":{"login":"ciiol","id":425290,"node_id":"MDQ6VXNlcjQyNTI5MA==","avatar_url":"https://avatars2.githubusercontent.com/u/425290?v=4","gravatar_id":"","url":"https://api.github.com/users/ciiol","html_url":"https://github.com/ciiol","followers_url":"https://api.github.com/users/ciiol/followers","following_url":"https://api.github.com/users/ciiol/following{/other_user}","gists_url":"https://api.github.com/users/ciiol/gists{/gist_id}","starred_url":"https://api.github.com/users/ciiol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciiol/subscriptions","organizations_url":"https://api.github.com/users/ciiol/orgs","repos_url":"https://api.github.com/users/ciiol/repos","events_url":"https://api.github.com/users/ciiol/events{/privacy}","received_events_url":"https://api.github.com/users/ciiol/received_events","type":"User","site_admin":false},"repo":{"id":136504151,"node_id":"MDEwOlJlcG9zaXRvcnkxMzY1MDQxNTE=","name":"machinegun","full_name":"ciiol/machinegun","private":false,"owner":{"login":"ciiol","id":425290,"node_id":"MDQ6VXNlcjQyNTI5MA==","avatar_url":"https://avatars2.githubusercontent.com/u/425290?v=4","gravatar_id":"","url":"https://api.github.com/users/ciiol","html_url":"https://github.com/ciiol","followers_url":"https://api.github.com/users/ciiol/followers","following_url":"https://api.github.com/users/ciiol/following{/other_user}","gists_url":"https://api.github.com/users/ciiol/gists{/gist_id}","starred_url":"https://api.github.com/users/ciiol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ciiol/subscriptions","organizations_url":"https://api.github.com/users/ciiol/orgs","repos_url":"https://api.github.com/users/ciiol/repos","events_url":"https://api.github.com/users/ciiol/events{/privacy}","received_events_url":"https://api.github.com/users/ciiol/received_events","type":"User","site_admin":false},"html_url":"https://github.com/ciiol/machinegun","description":"Machinegun FSM processor","fork":true,"url":"https://api.github.com/repos/ciiol/machinegun","forks_url":"https://api.github.com/repos/ciiol/machinegun/forks","keys_url":"https://api.github.com/repos/ciiol/machinegun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ciiol/machinegun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ciiol/machinegun/teams","hooks_url":"https://api.github.com/repos/ciiol/machinegun/hooks","issue_events_url":"https://api.github.com/repos/ciiol/machinegun/issues/events{/number}","events_url":"https://api.github.com/repos/ciiol/machinegun/events","assignees_url":"https://api.github.com/repos/ciiol/machinegun/assignees{/user}","branches_url":"https://api.github.com/repos/ciiol/machinegun/branches{/branch}","tags_url":"https://api.github.com/repos/ciiol/machinegun/tags","blobs_url":"https://api.github.com/repos/ciiol/machinegun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ciiol/machinegun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ciiol/machinegun/git/refs{/sha}","trees_url":"https://api.github.com/repos/ciiol/machinegun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ciiol/machinegun/statuses/{sha}","languages_url":"https://api.github.com/repos/ciiol/machinegun/languages","stargazers_url":"https://api.github.com/repos/ciiol/machinegun/stargazers","contributors_url":"https://api.github.com/repos/ciiol/machinegun/contributors","subscribers_url":"https://api.github.com/repos/ciiol/machinegun/subscribers","subscription_url":"https://api.github.com/repos/ciiol/machinegun/subscription","commits_url":"https://api.github.com/repos/ciiol/machinegun/commits{/sha}","git_commits_url":"https://api.github.com/repos/ciiol/machinegun/git/commits{/sha}","comments_url":"https://api.github.com/repos/ciiol/machinegun/comments{/number}","issue_comment_url":"https://api.github.com/repos/ciiol/machinegun/issues/comments{/number}","contents_url":"https://api.github.com/repos/ciiol/machinegun/contents/{+path}","compare_url":"https://api.github.com/repos/ciiol/machinegun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ciiol/machinegun/merges","archive_url":"https://api.github.com/repos/ciiol/machinegun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ciiol/machinegun/downloads","issues_url":"https://api.github.com/repos/ciiol/machinegun/issues{/number}","pulls_url":"https://api.github.com/repos/ciiol/machinegun/pulls{/number}","milestones_url":"https://api.github.com/repos/ciiol/machinegun/milestones{/number}","notifications_url":"https://api.github.com/repos/ciiol/machinegun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ciiol/machinegun/labels{/name}","releases_url":"https://api.github.com/repos/ciiol/machinegun/releases{/id}","deployments_url":"https://api.github.com/repos/ciiol/machinegun/deployments","created_at":"2018-06-07T16:29:54Z","updated_at":"2018-11-06T16:43:02Z","pushed_at":"2018-11-22T19:45:17Z","git_url":"git://github.com/ciiol/machinegun.git","ssh_url":"git@github.com:ciiol/machinegun.git","clone_url":"https://github.com/ciiol/machinegun.git","svn_url":"https://github.com/ciiol/machinegun","homepage":"","size":435,"stargazers_count":0,"watchers_count":0,"language":"Erlang","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rbkmoney:master","ref":"master","sha":"05100794c4432601d22e50754d17312e70597696","user":{"login":"rbkmoney","id":17027024,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE3MDI3MDI0","avatar_url":"https://avatars0.githubusercontent.com/u/17027024?v=4","gravatar_id":"","url":"https://api.github.com/users/rbkmoney","html_url":"https://github.com/rbkmoney","followers_url":"https://api.github.com/users/rbkmoney/followers","following_url":"https://api.github.com/users/rbkmoney/following{/other_user}","gists_url":"https://api.github.com/users/rbkmoney/gists{/gist_id}","starred_url":"https://api.github.com/users/rbkmoney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbkmoney/subscriptions","organizations_url":"https://api.github.com/users/rbkmoney/orgs","repos_url":"https://api.github.com/users/rbkmoney/repos","events_url":"https://api.github.com/users/rbkmoney/events{/privacy}","received_events_url":"https://api.github.com/users/rbkmoney/received_events","type":"Organization","site_admin":false},"repo":{"id":57044163,"node_id":"MDEwOlJlcG9zaXRvcnk1NzA0NDE2Mw==","name":"machinegun","full_name":"rbkmoney/machinegun","private":false,"owner":{"login":"rbkmoney","id":17027024,"node_id":"MDEyOk9yZ2FuaXphdGlvbjE3MDI3MDI0","avatar_url":"https://avatars0.githubusercontent.com/u/17027024?v=4","gravatar_id":"","url":"https://api.github.com/users/rbkmoney","html_url":"https://github.com/rbkmoney","followers_url":"https://api.github.com/users/rbkmoney/followers","following_url":"https://api.github.com/users/rbkmoney/following{/other_user}","gists_url":"https://api.github.com/users/rbkmoney/gists{/gist_id}","starred_url":"https://api.github.com/users/rbkmoney/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rbkmoney/subscriptions","organizations_url":"https://api.github.com/users/rbkmoney/orgs","repos_url":"https://api.github.com/users/rbkmoney/repos","events_url":"https://api.github.com/users/rbkmoney/events{/privacy}","received_events_url":"https://api.github.com/users/rbkmoney/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/rbkmoney/machinegun","description":"Machinegun FSM processor","fork":false,"url":"https://api.github.com/repos/rbkmoney/machinegun","forks_url":"https://api.github.com/repos/rbkmoney/machinegun/forks","keys_url":"https://api.github.com/repos/rbkmoney/machinegun/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rbkmoney/machinegun/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rbkmoney/machinegun/teams","hooks_url":"https://api.github.com/repos/rbkmoney/machinegun/hooks","issue_events_url":"https://api.github.com/repos/rbkmoney/machinegun/issues/events{/number}","events_url":"https://api.github.com/repos/rbkmoney/machinegun/events","assignees_url":"https://api.github.com/repos/rbkmoney/machinegun/assignees{/user}","branches_url":"https://api.github.com/repos/rbkmoney/machinegun/branches{/branch}","tags_url":"https://api.github.com/repos/rbkmoney/machinegun/tags","blobs_url":"https://api.github.com/repos/rbkmoney/machinegun/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rbkmoney/machinegun/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rbkmoney/machinegun/git/refs{/sha}","trees_url":"https://api.github.com/repos/rbkmoney/machinegun/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rbkmoney/machinegun/statuses/{sha}","languages_url":"https://api.github.com/repos/rbkmoney/machinegun/languages","stargazers_url":"https://api.github.com/repos/rbkmoney/machinegun/stargazers","contributors_url":"https://api.github.com/repos/rbkmoney/machinegun/contributors","subscribers_url":"https://api.github.com/repos/rbkmoney/machinegun/subscribers","subscription_url":"https://api.github.com/repos/rbkmoney/machinegun/subscription","commits_url":"https://api.github.com/repos/rbkmoney/machinegun/commits{/sha}","git_commits_url":"https://api.github.com/repos/rbkmoney/machinegun/git/commits{/sha}","comments_url":"https://api.github.com/repos/rbkmoney/machinegun/comments{/number}","issue_comment_url":"https://api.github.com/repos/rbkmoney/machinegun/issues/comments{/number}","contents_url":"https://api.github.com/repos/rbkmoney/machinegun/contents/{+path}","compare_url":"https://api.github.com/repos/rbkmoney/machinegun/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rbkmoney/machinegun/merges","archive_url":"https://api.github.com/repos/rbkmoney/machinegun/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rbkmoney/machinegun/downloads","issues_url":"https://api.github.com/repos/rbkmoney/machinegun/issues{/number}","pulls_url":"https://api.github.com/repos/rbkmoney/machinegun/pulls{/number}","milestones_url":"https://api.github.com/repos/rbkmoney/machinegun/milestones{/number}","notifications_url":"https://api.github.com/repos/rbkmoney/machinegun/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rbkmoney/machinegun/labels{/name}","releases_url":"https://api.github.com/repos/rbkmoney/machinegun/releases{/id}","deployments_url":"https://api.github.com/repos/rbkmoney/machinegun/deployments","created_at":"2016-04-25T13:32:38Z","updated_at":"2018-11-26T14:49:22Z","pushed_at":"2018-11-26T14:49:19Z","git_url":"git://github.com/rbkmoney/machinegun.git","ssh_url":"git@github.com:rbkmoney/machinegun.git","clone_url":"https://github.com/rbkmoney/machinegun.git","svn_url":"https://github.com/rbkmoney/machinegun","homepage":"","size":392,"stargazers_count":1,"watchers_count":1,"language":"Erlang","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":5,"open_issues":3,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rbkmoney/machinegun/pulls/110"},"html":{"href":"https://github.com/rbkmoney/machinegun/pull/110"},"issue":{"href":"https://api.github.com/repos/rbkmoney/machinegun/issues/110"},"comments":{"href":"https://api.github.com/repos/rbkmoney/machinegun/issues/110/comments"},"review_comments":{"href":"https://api.github.com/repos/rbkmoney/machinegun/pulls/110/comments"},"review_comment":{"href":"https://api.github.com/repos/rbkmoney/machinegun/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rbkmoney/machinegun/pulls/110/commits"},"statuses":{"href":"https://api.github.com/repos/rbkmoney/machinegun/statuses/c3d7a6e732a3d3507cceb2854bf038db4d0af8d0"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"keynslug"}}