Skip to content

Commit

Permalink
Provide better output on broken probes (#27)
Browse files Browse the repository at this point in the history
* Provide better output on broken probes

Right now the probe will just crash and exit if the probe module returns
an invalid value.  With many probes this can make it difficult to find
and correct misbehaving probes.

Instead of crashing, log a warning with the probe name and the invalid
value so the probe can be corrected

* Use a function that exists on all supported versions

* Increase assert_receive tolerance
  • Loading branch information
ihumanable authored Mar 31, 2022
1 parent 6162bd3 commit 5bad8ee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 3 additions & 0 deletions lib/probe/runner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ defmodule Instruments.Probe.Runner do

nil ->
Logger.info("Not Sending #{state.name} due to nil return")

invalid ->
Logger.warn("Probe #{state.name} has returned an invalid value: #{inspect(invalid)}")
end
end

Expand Down
10 changes: 5 additions & 5 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ defmodule MetricsAssertions do
use ExUnit.Case

def assert_metric_reported(metric_type, metric_name) do
assert_receive {:metric_reported, {^metric_type, ^metric_name, _, _}}
assert_receive {:metric_reported, {^metric_type, ^metric_name, _, _}}, 5000
end

def assert_metric_reported(metric_type, metric_name, metric_value)
when is_number(metric_value) do
assert_receive {:metric_reported, {^metric_type, ^metric_name, ^metric_value, _}}
assert_receive {:metric_reported, {^metric_type, ^metric_name, ^metric_value, _}}, 5000
end

def assert_metric_reported(metric_type, metric_name, expected_metric_value) do
assert_receive {:metric_reported, {^metric_type, ^metric_name, actual_value, _}}
assert_receive {:metric_reported, {^metric_type, ^metric_name, actual_value, _}}, 5000

cond do
range?(expected_metric_value) ->
Expand All @@ -27,14 +27,14 @@ defmodule MetricsAssertions do

def assert_metric_reported(metric_type, metric_name, metric_value, options)
when is_number(metric_value) do
assert_receive {:metric_reported, {^metric_type, ^metric_name, ^metric_value, actual_options}}
assert_receive {:metric_reported, {^metric_type, ^metric_name, ^metric_value, actual_options}}, 5000

do_assert_options(metric_type, options, actual_options)
end

def assert_metric_reported(metric_type, metric_name, expected_metric_value, options) do
assert_receive {:metric_reported,
{^metric_type, ^metric_name, actual_metric_value, actual_options}}
{^metric_type, ^metric_name, actual_metric_value, actual_options}}, 5000

do_assert_options(metric_type, options, actual_options)

Expand Down

0 comments on commit 5bad8ee

Please sign in to comment.