-
Notifications
You must be signed in to change notification settings - Fork 20
chore: log max run_queue and don't fail health checks based on it #883
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,90 +1,24 @@ | ||
| defmodule Health.Checkers.RunQueue do | ||
| @moduledoc """ | ||
| Health check which makes sure the Erlang [Run | ||
| Queue](http://erlang.org/doc/man/erlang.html#statistics-1) is reasonably | ||
| low. | ||
| Health check for monitoring the Erlang [Run | ||
| Queue](http://erlang.org/doc/man/erlang.html#statistics-1). | ||
| This check always returns healthy as we don't want to kill tasks based on the run queue length. | ||
| Instead it logs the maximum run queue length across all schedulers for monitoring purposes. | ||
| """ | ||
| require Logger | ||
|
|
||
| def current do | ||
| [run_queue: queue_size()] | ||
| [run_queue: max_queue_length()] | ||
| end | ||
|
|
||
| def healthy? do | ||
| h? = queue_size() <= max_run_queue_length() | ||
|
|
||
| _ = log_processes(h?, Logger.level()) | ||
|
|
||
| h? | ||
| end | ||
|
|
||
| defp max_run_queue_length, do: 100 | ||
|
|
||
| defp queue_size do | ||
| :erlang.statistics(:run_queue) | ||
| end | ||
|
|
||
| def log_processes(false, level) when level in [:info, :debug] do | ||
| spawn(fn -> | ||
| for line <- log_lines() do | ||
| _ = Logger.info(line) | ||
| end | ||
| end) | ||
|
|
||
| :logged | ||
| end | ||
|
|
||
| def log_processes(_, _) do | ||
| :ignored | ||
| end | ||
|
|
||
| def log_lines do | ||
| start_time = System.monotonic_time() | ||
|
|
||
| for pid <- Process.list() do | ||
| # lt short for log time | ||
| "process_info pid=#{inspect(pid)} lt=#{start_time} #{log_info(pid)}" | ||
| end | ||
| end | ||
|
|
||
| def log_info(pid) do | ||
| info = | ||
| Process.info( | ||
| pid, | ||
| ~w(current_function initial_call status message_queue_len priority total_heap_size heap_size stack_size reductions dictionary registered_name memory)a | ||
| ) | ||
|
|
||
| log_info_iodata(info) | ||
| end | ||
|
|
||
| defp log_info_iodata(info) when is_list(info) do | ||
| info = | ||
| if initial_call = info[:dictionary][:"$initial_call"] do | ||
| Keyword.put(info, :initial_call, initial_call) | ||
| else | ||
| info | ||
| end | ||
|
|
||
| info = Keyword.delete(info, :dictionary) | ||
|
|
||
| for {k, v} <- info do | ||
| [Atom.to_string(k), "=", pid_log(v), " "] | ||
| end | ||
| end | ||
|
|
||
| defp log_info_iodata(nil) do | ||
| ["status=dead"] | ||
| end | ||
|
|
||
| defp pid_log({m, f, a}) when is_atom(m) and is_atom(f) and a >= 0 do | ||
| [?", Atom.to_string(m), ?., Atom.to_string(f), ?/, Integer.to_string(a), ?"] | ||
| end | ||
|
|
||
| defp pid_log(atom) when is_atom(atom) do | ||
| Atom.to_string(atom) | ||
| max_length = max_queue_length() | ||
| _ = Logger.info("run_queue_check max_run_queue_length=#{max_length}") | ||
| true | ||
| end | ||
|
|
||
| defp pid_log(other) do | ||
| inspect(other) | ||
| defp max_queue_length do | ||
| Enum.max(:erlang.statistics(:run_queue_lengths)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick (non-blocking): this could be a good pipeline operator candidate |
||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (non-blocking): if this isn't going to be used as a "real" health check anymore, does it make sense to maybe split this out and make it its own GenServer living somewhere in the supervision tree? The only issue is that I'm not sure where exactly that "somewhere" would be, especially in the context of the API umbrella app setup.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I both agree, but didn't feel like it was worth the overhead. I can easily be convinced otherwise. The rest of the metrics we collect come from a reporter built into
ehmon. We don't currently have another way of surfacing metrics so it'd mean building a way of scheduling this to run on some interval, which just seemed like more code than it was worth for this one metric.