From 83394f01b8531eff14a04bec075c9a280457e40c Mon Sep 17 00:00:00 2001 From: Andrea Leopardi Date: Sat, 1 Jul 2023 18:51:11 +0200 Subject: [PATCH] Fix some issues with Telemetry --- lib/xandra/telemetry.ex | 16 ++++++++++++++-- test/xandra/cluster/control_connection_test.exs | 4 ++-- test/xandra/connection_error_test.exs | 8 ++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/lib/xandra/telemetry.ex b/lib/xandra/telemetry.ex index 27677840..c6979c57 100644 --- a/lib/xandra/telemetry.ex +++ b/lib/xandra/telemetry.ex @@ -270,8 +270,20 @@ defmodule Xandra.Telemetry do def handle_event(event, measurements, metadata, config) def handle_event([:xandra, :cluster | event], measurements, metadata, :no_config) do - %Host{address: address, port: port} = metadata.host - logger_meta = [xandra_address: address, xandra_port: port] + logger_meta = + case Map.fetch(metadata, :host) do + {:ok, %Host{address: address, port: port}} -> + address = + case address do + ip when is_tuple(ip) -> ip |> :inet.ntoa() |> to_string() + str when is_list(str) -> to_string(str) + end + + [xandra_address: address, xandra_port: port] + + :error -> + [] + end case event do [:change_event] -> diff --git a/test/xandra/cluster/control_connection_test.exs b/test/xandra/cluster/control_connection_test.exs index 8edab466..ee12db28 100644 --- a/test/xandra/cluster/control_connection_test.exs +++ b/test/xandra/cluster/control_connection_test.exs @@ -54,7 +54,7 @@ defmodule Xandra.Cluster.ControlConnectionTest do assert %Host{address: {127, 0, 0, 1}} = local_peer end) - assert log =~ "Error connecting: non-existing domain" + assert log =~ "Control connection failed to connect" assert log =~ "xandra_address=bad-domain" assert log =~ "xandra_port=9042" end @@ -72,7 +72,7 @@ defmodule Xandra.Cluster.ControlConnectionTest do assert {:disconnected, _data} = :sys.get_state(ctrl_conn) end) - assert log =~ "Error connecting: non-existing domain" + assert log =~ "Control connection failed to connect" assert log =~ "xandra_address=bad-domain" assert log =~ "xandra_address=other-bad-domain" end diff --git a/test/xandra/connection_error_test.exs b/test/xandra/connection_error_test.exs index ef96419e..c52e8cc8 100644 --- a/test/xandra/connection_error_test.exs +++ b/test/xandra/connection_error_test.exs @@ -36,8 +36,12 @@ defmodule Xandra.ConnectionErrorTest do end test "with any other reason" do - assert message("connect", :banana) == - ~s(action "connect" failed with reason: :banana) + message = message("connect", :banana) + + assert message in [ + ~s(action "connect" failed with reason: :banana), + ~s(action "connect" failed with reason: unknown POSIX error: banana) + ] end end