Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use libp2p raw tracer functionality #457

Merged
merged 25 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
df03795
feat: boilerplate
Godspower-Eze Nov 27, 2023
ae91f96
Merge branch 'main' into raw_tracer
Godspower-Eze Nov 27, 2023
bda08a1
Merge branch 'main' into raw_tracer
Godspower-Eze Nov 27, 2023
2b84bcb
feat: added proto defs and helpers
Godspower-Eze Nov 28, 2023
c6fa8a6
feat: added notification sender
Godspower-Eze Nov 28, 2023
11222be
feat: added handler
Godspower-Eze Nov 28, 2023
a610929
Merge branch 'raw_tracer' of github.com:Godspower-Eze/lambda_ethereum…
Godspower-Eze Nov 28, 2023
7f289dc
Merge branch 'main' into raw_tracer
Godspower-Eze Nov 28, 2023
f7bd8d0
fix: lint
Godspower-Eze Nov 28, 2023
19bd92c
update
Godspower-Eze Nov 28, 2023
f2e267e
fix lint
Godspower-Eze Nov 28, 2023
185b472
Merge branch 'main' into raw_tracer
Godspower-Eze Nov 28, 2023
0721dc4
feat: added new graphs
Godspower-Eze Nov 29, 2023
040bfe7
Merge branch 'raw_tracer' of github.com:Godspower-Eze/lambda_ethereum…
Godspower-Eze Nov 29, 2023
8e76503
Merge branch 'main' into raw_tracer
Godspower-Eze Nov 29, 2023
f58a269
feat: added topics activity
Godspower-Eze Nov 29, 2023
ebbb8b9
Merge branch 'raw_tracer' of github.com:Godspower-Eze/lambda_ethereum…
Godspower-Eze Nov 29, 2023
62f7f00
fix: lint
Godspower-Eze Nov 29, 2023
62dc3dd
Merge branch 'main' into raw_tracer
Godspower-Eze Nov 29, 2023
e3dc54c
feat: added add/remove peer
Godspower-Eze Nov 29, 2023
fbac9f3
fix
Godspower-Eze Nov 29, 2023
4c8e994
fic
Godspower-Eze Dec 1, 2023
929285f
Merge branch 'main' into raw_tracer
Godspower-Eze Dec 1, 2023
1f6c614
Merge branch 'main' into raw_tracer
Godspower-Eze Dec 2, 2023
4cb1d20
fix
Godspower-Eze Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions lib/lambda_ethereum_consensus/telemetry.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,15 @@ defmodule LambdaEthereumConsensus.Telemetry do
counter("peers.connection.count", tags: [:result]),
counter("peers.challenge.count", tags: [:result]),
counter("network.request.count", tags: [:result, :type, :reason]),
counter("network.pubsub_peers.count", tags: [:result]),
sum("network.pubsub_topic_active.active", tags: [:topic]),
counter("network.pubsub_topics_graft.count", tags: [:topic]),
counter("network.pubsub_topics_prune.count", tags: [:topic]),
counter("network.pubsub_topics_deliver_message.count", tags: [:topic]),
counter("network.pubsub_topics_duplicate_message.count", tags: [:topic]),
counter("network.pubsub_topics_reject_message.count", tags: [:topic]),
counter("network.pubsub_topics_un_deliverable_message.count", tags: [:topic]),
counter("network.pubsub_topics_validate_message.count", tags: [:topic]),
counter("port.message.count", tags: [:function, :direction]),
sum("network.request.blocks", tags: [:result, :type, :reason]),

Expand Down
73 changes: 71 additions & 2 deletions lib/libp2p_port.ex
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
defmodule LambdaEthereumConsensus.Libp2pPort do
@moduledoc """
A GenServer that allows other elixir processes to send and receive commands to/from
the LibP2P server in Go. For now, it only supports subscribing and unsubscribing from
topics.
the LibP2P server in Go.

Requests are generated with an ID, which is returned when calling. Those IDs appear
in the responses that might be listened to by other processes.
Expand All @@ -26,6 +25,7 @@ defmodule LambdaEthereumConsensus.Libp2pPort do
SendResponse,
SetHandler,
SubscribeToTopic,
Tracer,
UnsubscribeFromTopic,
ValidateMessage
}
Expand Down Expand Up @@ -310,6 +310,68 @@ defmodule LambdaEthereumConsensus.Libp2pPort do
send(pid, {:response, result})
end

defp handle_notification(%Tracer{t: {:add_peer, %{}}}, _state) do
:telemetry.execute([:network, :pubsub_peers], %{}, %{
result: "add"
})
end

defp handle_notification(%Tracer{t: {:remove_peer, %{}}}, _state) do
:telemetry.execute([:network, :pubsub_peers], %{}, %{
result: "remove"
})
end

defp handle_notification(%Tracer{t: {:joined, %{topic: topic}}}, _state) do
:telemetry.execute([:network, :pubsub_topic_active], %{active: 1}, %{
topic: get_topic_name(topic)
})
end

defp handle_notification(%Tracer{t: {:left, %{topic: topic}}}, _state) do
:telemetry.execute([:network, :pubsub_topic_active], %{active: -1}, %{
topic: get_topic_name(topic)
})
end

defp handle_notification(%Tracer{t: {:grafted, %{topic: topic}}}, _state) do
:telemetry.execute([:network, :pubsub_topics_graft], %{}, %{topic: get_topic_name(topic)})
end

defp handle_notification(%Tracer{t: {:pruned, %{topic: topic}}}, _state) do
:telemetry.execute([:network, :pubsub_topics_prune], %{}, %{topic: get_topic_name(topic)})
end

defp handle_notification(%Tracer{t: {:deliver_message, %{topic: topic}}}, _state) do
:telemetry.execute([:network, :pubsub_topics_deliver_message], %{}, %{
topic: get_topic_name(topic)
})
end

defp handle_notification(%Tracer{t: {:duplicate_message, %{topic: topic}}}, _state) do
:telemetry.execute([:network, :pubsub_topics_duplicate_message], %{}, %{
topic: get_topic_name(topic)
})
end

defp handle_notification(%Tracer{t: {:reject_message, %{topic: topic}}}, _state) do
:telemetry.execute([:network, :pubsub_topics_reject_message], %{}, %{
topic: get_topic_name(topic)
})
end

defp handle_notification(%Tracer{t: {:un_deliverable_message, %{topic: topic}}}, _state) do
:telemetry.execute([:network, :pubsub_topics_un_deliverable_message], %{}, %{
topic: get_topic_name(topic)
})
end

defp handle_notification(%Tracer{t: {:validate_message, %{topic: topic}}}, _state) do
:telemetry.execute([:network, :pubsub_topics_validate_message], %{}, %{
topic: get_topic_name(topic)
})
end

defp parse_args(args) do
args
|> Keyword.validate!(@default_args)
Expand Down Expand Up @@ -339,4 +401,11 @@ defmodule LambdaEthereumConsensus.Libp2pPort do
{:response, {res, %ResultMessage{message: message}}} -> [res | message] |> List.to_tuple()
end
end

defp get_topic_name(topic) do
case topic |> String.split("/") |> Enum.fetch(3) do
{:ok, name} -> name
:error -> topic
end
end
end
Loading
Loading