Improve custom hook error logging
Previously if a custom hook failed, it would be difficult to determine which hook in question were actually failing without using strace. The failing hook could be global or a project hook. We now log the filename along with the error message.
Relates to #2923 (closed)
Previous error
{
"correlation_id": "01FMXEDMS5RNX4K2MGYYFC2RQY",
"error": "executing custom hooks: exit status 1",
"grpc.meta.deadline_type": "none",
"grpc.meta.method_type": "bidi_stream",
"grpc.method": "PreReceiveHook",
"grpc.request.fullMethod": "/gitaly.HookService/PreReceiveHook",
"grpc.request.glProjectPath": "root/another-import",
"grpc.request.glRepository": "project-64",
"grpc.request.repoPath": "@hashed/a6/8b/a68b412c4282555f15546cf6e1fc42893b7e07f271557ceb021821098dd66c1b.git",
"grpc.request.repoStorage": "default",
"grpc.service": "gitaly.HookService",
"grpc.start_time": "2021-11-20T01:12:25.790",
"level": "warning",
"msg": "stopping transaction because pre-receive hook failed",
"peer.address": "@",
"pid": 224209,
"span.kind": "server",
"system": "grpc",
"time": "2021-11-20T01:12:25.867Z"
}
New error
{
"correlation_id": "01FMXEQPQKSS8B108XKQDYFD0B",
"error": "executing custom hooks: error executing \"/var/opt/gitlab/gitaly/custom_hooks/pre-receive.d/pre-receive\": exit status 1",
"grpc.meta.deadline_type": "none",
"grpc.meta.method_type": "bidi_stream",
"grpc.method": "PreReceiveHook",
"grpc.request.fullMethod": "/gitaly.HookService/PreReceiveHook",
"grpc.request.glProjectPath": "root/another-import",
"grpc.request.glRepository": "project-64",
"grpc.request.repoPath": "@hashed/a6/8b/a68b412c4282555f15546cf6e1fc42893b7e07f271557ceb021821098dd66c1b.git",
"grpc.request.repoStorage": "default",
"grpc.service": "gitaly.HookService",
"grpc.start_time": "2021-11-20T01:17:55.748",
"level": "warning",
"msg": "stopping transaction because pre-receive hook failed",
"peer.address": "@",
"pid": 1421048,
"span.kind": "server",
"system": "grpc",
"time": "2021-11-20T01:17:55.831Z"
}
Edited by Stan Hu