From 2a545e3afd7e1c515870ea59400ba5a3c383cf4a Mon Sep 17 00:00:00 2001 From: Mateusz Front Date: Fri, 28 Jun 2024 15:30:32 +0200 Subject: [PATCH] Fix 'table identifier does not refer to an existing ETS table' error when inserting metrics into the observability ETS (#835) * stalker: fix 'non existing ETS' error, wrap ets.insert with try-rescue * improve logging errors from components --- CHANGELOG.md | 3 + .../child_life_controller/startup_utils.ex | 2 +- lib/membrane/core/stalker.ex | 63 +++++++++++-------- lib/membrane/core/utils.ex | 7 +-- 4 files changed, 43 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index becaeca20..e9de8c653 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.1.1 +* Fix 'table identifier does not refer to an existing ETS table' error when inserting metrics into the observability ETS [#835](https://github.com/membraneframework/membrane_core/pull/835) + ## 1.1.0 * Add new callbacks `handle_child_setup_completed/3` and `handle_child_playing/3` in Bins and Pipelines. [#801](https://github.com/membraneframework/membrane_core/pull/801) * Deprecate `handle_spec_started/3` callback in Bins and Pipelines. [#708](https://github.com/membraneframework/membrane_core/pull/708) diff --git a/lib/membrane/core/parent/child_life_controller/startup_utils.ex b/lib/membrane/core/parent/child_life_controller/startup_utils.ex index 622273adc..766ddf610 100644 --- a/lib/membrane/core/parent/child_life_controller/startup_utils.ex +++ b/lib/membrane/core/parent/child_life_controller/startup_utils.ex @@ -34,7 +34,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.StartupUtils do sinks = children |> Enum.filter( - &(Membrane.Element.element?(&1.module) and &1.module.membrane_element_type == :sink) + &(Membrane.Element.element?(&1.module) and &1.module.membrane_element_type() == :sink) ) |> Enum.map(& &1.name) diff --git a/lib/membrane/core/stalker.ex b/lib/membrane/core/stalker.ex index 384459f20..2fe1a0514 100644 --- a/lib/membrane/core/stalker.ex +++ b/lib/membrane/core/stalker.ex @@ -66,7 +66,7 @@ defmodule Membrane.Core.Stalker do @spec new(component_config(), pid()) :: t() def new(config, supervisor) do {:ok, pid} = - Membrane.Core.SubprocessSupervisor.start_link_utility( + Membrane.Core.SubprocessSupervisor.start_utility( supervisor, {__MODULE__, %{pipeline: self()}} ) @@ -280,35 +280,23 @@ defmodule Membrane.Core.Stalker do if @metrics_enabled do defmacro report_metric(metric, value, opts \\ []) do - quote do - ets = Process.get(:__membrane_stalker_ets__) - - if ets do - :ets.insert( - ets, - {{unquote(metric), unquote(opts)[:component_path] || ComponentPath.get(), - unquote(opts)[:pad]}, unquote(value)} - ) - end - - :ok - end + try_insert( + quote do + {unquote(metric), unquote(opts)[:component_path] || ComponentPath.get(), + unquote(opts)[:pad]} + end, + value + ) end defmacro register_metric_function(metric, function, opts \\ []) do - quote do - ets = Process.get(:__membrane_stalker_ets__) - - if ets do - :ets.insert( - ets, - {{unquote(metric), unquote(opts)[:component_path] || ComponentPath.get(), - unquote(opts)[:pad]}, unquote({@function_metric, function})} - ) - end - - :ok - end + try_insert( + quote do + {unquote(metric), unquote(opts)[:component_path] || ComponentPath.get(), + unquote(opts)[:pad]} + end, + {@function_metric, function} + ) end else defmacro report_metric(metric, value, opts \\ []) do @@ -336,6 +324,27 @@ defmodule Membrane.Core.Stalker do end end + defp try_insert(key, value) do + quote do + ets = Process.get(:__membrane_stalker_ets__) + + if ets do + try do + :ets.insert(ets, {unquote(key), unquote(value)}) + rescue + error -> + require Logger + pretty_error = Exception.format(:error, error, __STACKTRACE__) + + Logger.warning(""" + Failed to insert a metric into the observability ETS. + Error: #{pretty_error} + """) + end + end + end + end + @impl true def init(options) do Utils.log_on_error do diff --git a/lib/membrane/core/utils.ex b/lib/membrane/core/utils.ex index 1f21bacb1..54df1b0f4 100644 --- a/lib/membrane/core/utils.ex +++ b/lib/membrane/core/utils.ex @@ -16,16 +16,15 @@ defmodule Membrane.Core.Utils do try do unquote(code) rescue - e -> + error -> require Membrane.Logger Membrane.Logger.error(""" Error occured in #{unquote(error_source)}: - #{inspect(e, pretty: true, limit: :infinity)} - #{Exception.format_stacktrace(__STACKTRACE__)} + #{Exception.format(:error, error, __STACKTRACE__)} """) - reraise e, __STACKTRACE__ + reraise error, __STACKTRACE__ end end end