-
-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve failure telemetry (#1307)
- Loading branch information
1 parent
b7bfb91
commit 5192428
Showing
10 changed files
with
168 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
defmodule Realtime.PromEx.Plugins.Channels do | ||
@moduledoc """ | ||
Realtime channels monitoring plugin for PromEx | ||
""" | ||
use PromEx.Plugin | ||
require Logger | ||
|
||
@impl true | ||
def event_metrics(_opts) do | ||
Event.build(:realtime, [ | ||
counter( | ||
[:realtime, :channel, :error], | ||
event_name: [:realtime, :channel, :error], | ||
measurement: :code, | ||
tags: [:code], | ||
description: "Count of errors in the Realtime channels initialization" | ||
) | ||
]) | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Realtime.PromExTest do | ||
use ExUnit.Case | ||
doctest Realtime.PromEx | ||
alias Realtime.PromEx | ||
|
||
describe "get_metrics/0" do | ||
test "builds metrics in prometheus format which includes host region and id" do | ||
metrics = PromEx.get_metrics() | ||
|
||
assert String.contains?( | ||
metrics, | ||
"# HELP beam_system_schedulers_online_info The number of scheduler threads that are online." | ||
) | ||
|
||
assert String.contains?(metrics, "# TYPE beam_system_schedulers_online_info gauge") | ||
assert String.contains?(metrics, "beam_system_schedulers_online_info{host=\"nohost\",region=\"\",id=\"nohost\"}") | ||
end | ||
end | ||
end |
This file contains 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,30 +1,73 @@ | ||
defmodule Realtime.RpcTest do | ||
use ExUnit.Case | ||
alias Realtime.Rpc | ||
|
||
import ExUnit.CaptureLog | ||
|
||
alias Realtime.Rpc | ||
|
||
defmodule TestRpc do | ||
def test_raise, do: raise("test") | ||
def test_timeout, do: Process.sleep(1000) | ||
def test_timeout, do: Process.sleep(200) | ||
def test_success, do: {:ok, "success"} | ||
end | ||
|
||
def handle_telemetry(event, metadata, _, pid: pid), do: send(pid, {event, metadata}) | ||
|
||
setup do | ||
:telemetry.attach(__MODULE__, [:realtime, :rpc], &__MODULE__.handle_telemetry/4, pid: self()) | ||
on_exit(fn -> :telemetry.detach(__MODULE__) end) | ||
:ok | ||
end | ||
|
||
describe "call/5" do | ||
test "successful RPC call returns exactly what the original function returns" do | ||
assert {:ok, "success"} = Rpc.call(node(), TestRpc, :test_success, []) | ||
assert_receive {[:realtime, :rpc], %{latency: _}} | ||
end | ||
|
||
test "raised exceptions are properly caught and logged" do | ||
assert {:badrpc, | ||
{:EXIT, | ||
{%RuntimeError{message: "test"}, | ||
[ | ||
{Realtime.RpcTest.TestRpc, :test_raise, 0, | ||
[file: ~c"test/realtime/rpc_test.exs", line: 9, error_info: %{module: Exception}]} | ||
]}}} = | ||
Rpc.call(node(), TestRpc, :test_raise, []) | ||
|
||
assert_receive {[:realtime, :rpc], %{latency: _}} | ||
end | ||
|
||
test "timeouts are properly caught and logged" do | ||
assert {:badrpc, :timeout} = | ||
Rpc.call(node(), TestRpc, :test_timeout, [], timeout: 100) | ||
|
||
assert_receive {[:realtime, :rpc], %{latency: _}} | ||
end | ||
end | ||
|
||
describe "enhanced_call/5" do | ||
test "successful RPC call returns exactly what the original function returns" do | ||
assert {:ok, "success"} = Rpc.enhanced_call(node(), TestRpc, :test_success) | ||
assert_receive {[:realtime, :rpc], %{latency: _, success?: true}} | ||
end | ||
|
||
test "raised exceptions are properly caught and logged" do | ||
assert capture_log(fn -> | ||
assert {:error, "RPC call error"} = Rpc.enhanced_call(node(), TestRpc, :test_raise) | ||
assert {:error, :rpc_error, %RuntimeError{message: "test"}} = | ||
Rpc.enhanced_call(node(), TestRpc, :test_raise) | ||
end) =~ "ErrorOnRpcCall" | ||
|
||
assert_receive {[:realtime, :rpc], %{latency: _, success?: false}} | ||
end | ||
|
||
test "timeouts are properly caught and logged" do | ||
assert capture_log(fn -> | ||
assert {:error, "RPC call error"} = | ||
Rpc.enhanced_call(node(), TestRpc, :test_timeout, 500) | ||
assert {:error, :rpc_error, :timeout} = | ||
Rpc.enhanced_call(node(), TestRpc, :test_timeout, [], timeout: 100) | ||
end) =~ "ErrorOnRpcCall" | ||
|
||
assert_receive {[:realtime, :rpc], %{latency: 0, success?: false}} | ||
end | ||
end | ||
end |
This file contains 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