Skip to content

Commit 2a545e3

Browse files
authored
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
1 parent 010f29e commit 2a545e3

File tree

4 files changed

+43
-32
lines changed

4 files changed

+43
-32
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## 1.1.1
4+
* 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)
5+
36
## 1.1.0
47
* 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)
58
* Deprecate `handle_spec_started/3` callback in Bins and Pipelines. [#708](https://github.com/membraneframework/membrane_core/pull/708)

lib/membrane/core/parent/child_life_controller/startup_utils.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ defmodule Membrane.Core.Parent.ChildLifeController.StartupUtils do
3434
sinks =
3535
children
3636
|> Enum.filter(
37-
&(Membrane.Element.element?(&1.module) and &1.module.membrane_element_type == :sink)
37+
&(Membrane.Element.element?(&1.module) and &1.module.membrane_element_type() == :sink)
3838
)
3939
|> Enum.map(& &1.name)
4040

lib/membrane/core/stalker.ex

+36-27
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ defmodule Membrane.Core.Stalker do
6666
@spec new(component_config(), pid()) :: t()
6767
def new(config, supervisor) do
6868
{:ok, pid} =
69-
Membrane.Core.SubprocessSupervisor.start_link_utility(
69+
Membrane.Core.SubprocessSupervisor.start_utility(
7070
supervisor,
7171
{__MODULE__, %{pipeline: self()}}
7272
)
@@ -280,35 +280,23 @@ defmodule Membrane.Core.Stalker do
280280

281281
if @metrics_enabled do
282282
defmacro report_metric(metric, value, opts \\ []) do
283-
quote do
284-
ets = Process.get(:__membrane_stalker_ets__)
285-
286-
if ets do
287-
:ets.insert(
288-
ets,
289-
{{unquote(metric), unquote(opts)[:component_path] || ComponentPath.get(),
290-
unquote(opts)[:pad]}, unquote(value)}
291-
)
292-
end
293-
294-
:ok
295-
end
283+
try_insert(
284+
quote do
285+
{unquote(metric), unquote(opts)[:component_path] || ComponentPath.get(),
286+
unquote(opts)[:pad]}
287+
end,
288+
value
289+
)
296290
end
297291

298292
defmacro register_metric_function(metric, function, opts \\ []) do
299-
quote do
300-
ets = Process.get(:__membrane_stalker_ets__)
301-
302-
if ets do
303-
:ets.insert(
304-
ets,
305-
{{unquote(metric), unquote(opts)[:component_path] || ComponentPath.get(),
306-
unquote(opts)[:pad]}, unquote({@function_metric, function})}
307-
)
308-
end
309-
310-
:ok
311-
end
293+
try_insert(
294+
quote do
295+
{unquote(metric), unquote(opts)[:component_path] || ComponentPath.get(),
296+
unquote(opts)[:pad]}
297+
end,
298+
{@function_metric, function}
299+
)
312300
end
313301
else
314302
defmacro report_metric(metric, value, opts \\ []) do
@@ -336,6 +324,27 @@ defmodule Membrane.Core.Stalker do
336324
end
337325
end
338326

327+
defp try_insert(key, value) do
328+
quote do
329+
ets = Process.get(:__membrane_stalker_ets__)
330+
331+
if ets do
332+
try do
333+
:ets.insert(ets, {unquote(key), unquote(value)})
334+
rescue
335+
error ->
336+
require Logger
337+
pretty_error = Exception.format(:error, error, __STACKTRACE__)
338+
339+
Logger.warning("""
340+
Failed to insert a metric into the observability ETS.
341+
Error: #{pretty_error}
342+
""")
343+
end
344+
end
345+
end
346+
end
347+
339348
@impl true
340349
def init(options) do
341350
Utils.log_on_error do

lib/membrane/core/utils.ex

+3-4
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,15 @@ defmodule Membrane.Core.Utils do
1616
try do
1717
unquote(code)
1818
rescue
19-
e ->
19+
error ->
2020
require Membrane.Logger
2121

2222
Membrane.Logger.error("""
2323
Error occured in #{unquote(error_source)}:
24-
#{inspect(e, pretty: true, limit: :infinity)}
25-
#{Exception.format_stacktrace(__STACKTRACE__)}
24+
#{Exception.format(:error, error, __STACKTRACE__)}
2625
""")
2726

28-
reraise e, __STACKTRACE__
27+
reraise error, __STACKTRACE__
2928
end
3029
end
3130
end

0 commit comments

Comments
 (0)