Skip to content

Commit 6b7ec74

Browse files
fix(hooks_processor): Lower the log message level (#407)
## πŸ“ Description Use json logging formatter when running in production env Lower the priority of some hot path logs and introduce metrics in their place ## βœ… Checklist - [x] I have tested this change - [ ] This change requires documentation update
1 parent 2fd18b1 commit 6b7ec74

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

β€Žhooks_processor/config/config.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import Config
22

33
config :hooks_processor, environment: config_env()
44

5+
config :logger, :console, format: "$time $metadata[$level] $message\n"
6+
57
config :hooks_processor,
68
ecto_repos: [HooksProcessor.EctoRepo]
79

β€Žhooks_processor/config/runtime.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ config :hooks_processor, HooksProcessor.EctoRepo,
2424

2525
config :logger, level: (System.get_env("LOG_LEVEL") || "info") |> String.to_atom()
2626

27+
if config_env() == :prod do
28+
config :logger, :default_handler, formatter: LoggerJSON.Formatters.Basic.new()
29+
end
30+
2731
# We need valid dsn or nil
2832
sentry_dsn = System.get_env("SENTRY_DSN", "") |> String.trim() |> (&if(&1 != "", do: &1, else: nil)).()
2933

β€Žhooks_processor/lib/hooks_processor/hooks/processing/bitbucket_worker.ex

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule HooksProcessor.Hooks.Processing.BitbucketWorker do
4040
requester_id <- get_requester_id(webhook, actor_id, "bitbucket"),
4141
{:ok, _webhook} <-
4242
process_webhook(hook_type, webhook, project.repository, requester_id) do
43-
"Processing finished successfully." |> graceful_exit(state)
43+
:ok |> graceful_exit(state)
4444
else
4545
error -> graceful_exit(error, state)
4646
end
@@ -94,6 +94,9 @@ defmodule HooksProcessor.Hooks.Processing.BitbucketWorker do
9494
end
9595

9696
defp process_webhook(hook_type, _webhook, _project, _requester_id) do
97+
# Increment unsupported hook type metric
98+
Watchman.increment({"hooks.processing.bitbucket", ["unsupported_hook"]})
99+
97100
"Unsuported type of the hook: '#{hook_type}'"
98101
end
99102

@@ -109,9 +112,15 @@ defmodule HooksProcessor.Hooks.Processing.BitbucketWorker do
109112
defp should_build?(repository, hook_data, hook_type) do
110113
cond do
111114
hook_type not in repository.run_on ->
115+
# Increment skip configuration metric
116+
Watchman.increment({"hooks.processing.bitbucket", ["skip", "configuration"]})
117+
112118
{:build, {false, hook_state(hook_type, :skip)}, hook_data}
113119

114120
not whitelisted?(repository.whitelist, hook_data, hook_type) ->
121+
# Increment skip configuration metric
122+
Watchman.increment({"hooks.processing.bitbucket", ["skip", "whitelist"]})
123+
115124
{:build, {false, hook_state(hook_type, :whitelist)}, hook_data}
116125

117126
true ->
@@ -124,14 +133,28 @@ defmodule HooksProcessor.Hooks.Processing.BitbucketWorker do
124133
defp hook_state(:TAGS, :skip), do: "skip_tag"
125134
defp hook_state(:TAGS, :whitelist), do: "whitelist_tag"
126135

127-
defp graceful_exit(message, state) do
128-
message
129-
|> LT.info("Hook #{state.id} - bitbucket worker process exits: ")
136+
defp graceful_exit(result, state) do
137+
case result do
138+
:ok ->
139+
Watchman.increment({"hooks.processing.bitbucket", ["success"]})
140+
141+
"Processing finished successfully."
142+
|> LT.debug("Hook #{state.id} - bitbucket worker process exits: ")
143+
144+
error ->
145+
Watchman.increment({"hooks.processing.bitbucket", ["error"]})
146+
147+
error
148+
|> LT.error("Hook #{state.id} - bitbucket worker process exits: ")
149+
end
130150

131151
{:stop, :normal, state}
132152
end
133153

134154
defp restart(error, state) do
155+
# Increment failure metric
156+
Watchman.increment({"hooks.processing.bitbucket", ["restart"]})
157+
135158
error
136159
|> LT.warn("Hook #{state.id} - bitbucket worker process failiure: ")
137160

β€Žhooks_processor/mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ defmodule HooksProcessor.MixProject do
3838
{:ecto_sql, "~> 3.0"},
3939
{:postgrex, ">= 0.0.0"},
4040
{:uuid, "~> 1.1"},
41+
{:logger_json, "~> 7.0"},
4142
{:junit_formatter, "~> 3.1", only: [:test]},
4243
# head because support for JSON is not yet released
4344
{:sentry, github: "getsentry/sentry-elixir", ref: "f375551f32f35674f9baab470d0e571466b07055"},

β€Žhooks_processor/mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
2424
"junit_formatter": {:hex, :junit_formatter, "3.4.0", "d0e8db6c34dab6d3c4154c3b46b21540db1109ae709d6cf99ba7e7a2ce4b1ac2", [:mix], [], "hexpm", "bb36e2ae83f1ced6ab931c4ce51dd3dbef1ef61bb4932412e173b0cfa259dacd"},
2525
"log_tee": {:git, "https://github.com/renderedtext/log-tee.git", "30c69704d583bda8cffb324b8936ffd3680e6ae4", []},
26+
"logger_json": {:hex, :logger_json, "7.0.3", "0f202788d743154796bd208e1078d878bb4fccf0adc4ed9c83cba821732d326c", [:mix], [{:decimal, ">= 0.0.0", [hex: :decimal, repo: "hexpm", optional: true]}, {:ecto, "~> 3.11", [hex: :ecto, repo: "hexpm", optional: true]}, {:jason, "~> 1.4", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.15", [hex: :plug, repo: "hexpm", optional: true]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "9d1ca7dfe77eb7eac4664edfd6f874168d4707aedbedea09fba8eaa6ed2e2f97"},
2627
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm", "69b09adddc4f74a40716ae54d140f93beb0fb8978d8636eaded0c31b6f099f16"},
2728
"mime": {:hex, :mime, "2.0.6", "8f18486773d9b15f95f4f4f1e39b710045fa1de891fada4516559967276e4dc2", [:mix], [], "hexpm", "c9945363a6b26d747389aac3643f8e0e09d30499a138ad64fe8fd1d13d9b153e"},
2829
"mimerl": {:hex, :mimerl, "1.3.0", "d0cd9fc04b9061f82490f6581e0128379830e78535e017f7780f37fea7545726", [:rebar3], [], "hexpm", "a1e15a50d1887217de95f0b9b0793e32853f7c258a5cd227650889b38839fe9d"},

0 commit comments

Comments
Β (0)