From 5bad8ee017290718fb37319bb4330f8d6b971995 Mon Sep 17 00:00:00 2001 From: Matt Nowack Date: Thu, 31 Mar 2022 11:03:59 -0700 Subject: [PATCH] Provide better output on broken probes (#27) * 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 --- lib/probe/runner.ex | 3 +++ test/test_helper.exs | 10 +++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/probe/runner.ex b/lib/probe/runner.ex index e9bc91e..747c2fa 100644 --- a/lib/probe/runner.ex +++ b/lib/probe/runner.ex @@ -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 diff --git a/test/test_helper.exs b/test/test_helper.exs index e48d7a8..4d759c6 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -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) -> @@ -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)