Skip to content

Commit

Permalink
Fix some issues with Telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Jul 1, 2023
1 parent 1bfaad6 commit 83394f0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
16 changes: 14 additions & 2 deletions lib/xandra/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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] ->
Expand Down
4 changes: 2 additions & 2 deletions test/xandra/cluster/control_connection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions test/xandra/connection_error_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 83394f0

Please sign in to comment.