diff --git a/lib/lambda_ethereum_consensus/telemetry.ex b/lib/lambda_ethereum_consensus/telemetry.ex index 777275913..79920d62e 100644 --- a/lib/lambda_ethereum_consensus/telemetry.ex +++ b/lib/lambda_ethereum_consensus/telemetry.ex @@ -59,8 +59,8 @@ defmodule LambdaEthereumConsensus.Telemetry do counter("peers.connection.count", tags: [:result]), counter("peers.challenge.count", tags: [:result]), counter("network.request.count", tags: [:result, :type, :reason]), - sum("network.pubsub_peers.peers", tags: [:result]), - counter("network.pubsub_topic_active.active", tags: [:topic]), + 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]), diff --git a/lib/libp2p_port.ex b/lib/libp2p_port.ex index e30a25bee..32593996d 100644 --- a/lib/libp2p_port.ex +++ b/lib/libp2p_port.ex @@ -11,22 +11,13 @@ defmodule LambdaEthereumConsensus.Libp2pPort do alias Libp2pProto.{ AddPeer, - AddPeerGossip, Command, - DeliverMessage, - DuplicateMessage, GetId, GossipSub, - Graft, InitArgs, - Join, - Leave, NewPeer, Notification, - Prune, Publish, - RejectMessage, - RemovePeerGossip, Request, Result, ResultMessage, @@ -34,10 +25,9 @@ defmodule LambdaEthereumConsensus.Libp2pPort do SendResponse, SetHandler, SubscribeToTopic, - UnDeliverableMessage, + Tracer, UnsubscribeFromTopic, - ValidateMessage, - ValidateMessageGossip + ValidateMessage } require Logger @@ -320,63 +310,63 @@ defmodule LambdaEthereumConsensus.Libp2pPort do send(pid, {:response, result}) end - defp handle_notification(%AddPeerGossip{}, _state) do - :telemetry.execute([:network, :pubsub_peers], %{peers: 1}, %{ + defp handle_notification(%Tracer{t: {:add_peer, %{}}}, _state) do + :telemetry.execute([:network, :pubsub_peers], %{}, %{ result: "add" }) end - defp handle_notification(%RemovePeerGossip{}, _state) do - :telemetry.execute([:network, :pubsub_peers], %{peers: 0}, %{ + defp handle_notification(%Tracer{t: {:remove_peer, %{}}}, _state) do + :telemetry.execute([:network, :pubsub_peers], %{}, %{ result: "remove" }) end - defp handle_notification(%Join{topic: topic}, _state) do + 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(%Leave{topic: topic}, _state) do - :telemetry.execute([:network, :pubsub_topic_active], %{active: 0}, %{ + 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(%Graft{topic: topic}, _state) do + 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(%Prune{topic: topic}, _state) do + 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(%DeliverMessage{topic: topic}, _state) do + 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(%DuplicateMessage{topic: topic}, _state) do + 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(%RejectMessage{topic: topic}, _state) do + 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(%UnDeliverableMessage{topic: topic}, _state) do + 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(%ValidateMessageGossip{topic: topic}, _state) do + defp handle_notification(%Tracer{t: {:validate_message, %{topic: topic}}}, _state) do :telemetry.execute([:network, :pubsub_topics_validate_message], %{}, %{ topic: get_topic_name(topic) }) diff --git a/metrics/grafana/provisioning/dashboards/home.json b/metrics/grafana/provisioning/dashboards/home.json index 67529bae7..a4f1482ce 100644 --- a/metrics/grafana/provisioning/dashboards/home.json +++ b/metrics/grafana/provisioning/dashboards/home.json @@ -983,12 +983,12 @@ "disableTextWrap": false, "editorMode": "code", "exemplar": false, - "expr": "sum(network_pubsub_peers_peers{result=\"add\"}) - sum(network_pubsub_peers_peers{result=\"remove\"})", + "expr": "sum(network_pubsub_peers_count{result=\"add\"}) - sum(network_pubsub_peers_count{result=\"remove\"})", "fullMetaSearch": false, "includeNullMetadata": true, "instant": false, "interval": "", - "legendFormat": "{{topic}}", + "legendFormat": "__auto", "range": true, "refId": "A", "useBackend": false diff --git a/native/libp2p_port/internal/proto_helpers/proto_helpers.go b/native/libp2p_port/internal/proto_helpers/proto_helpers.go index b92c768ea..9fb9b6888 100644 --- a/native/libp2p_port/internal/proto_helpers/proto_helpers.go +++ b/native/libp2p_port/internal/proto_helpers/proto_helpers.go @@ -21,56 +21,69 @@ func ConfigFromInitArgs(initArgs *proto_defs.InitArgs) Config { } func AddPeerNotification() proto_defs.Notification { - return proto_defs.Notification{N: &proto_defs.Notification_AddPeer{}} + addPeerNotification := &proto_defs.AddPeerGossip{} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_AddPeer{AddPeer: addPeerNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func RemovePeerNotification() proto_defs.Notification { - return proto_defs.Notification{N: &proto_defs.Notification_RemovePeer{}} + removePeerNotification := &proto_defs.RemovePeerGossip{} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_RemovePeer{RemovePeer: removePeerNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func JoinNotification(topic string) proto_defs.Notification { joinNotification := &proto_defs.Join{Topic: topic} - return proto_defs.Notification{N: &proto_defs.Notification_Joined{Joined: joinNotification}} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_Joined{Joined: joinNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func LeaveNofication(topic string) proto_defs.Notification { leaveNofication := &proto_defs.Leave{Topic: topic} - return proto_defs.Notification{N: &proto_defs.Notification_Left{Left: leaveNofication}} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_Left{Left: leaveNofication}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func GraftNotification(topic string) proto_defs.Notification { graftNotification := &proto_defs.Graft{Topic: topic} - return proto_defs.Notification{N: &proto_defs.Notification_Grafted{Grafted: graftNotification}} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_Grafted{Grafted: graftNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func PruneNotification(topic string) proto_defs.Notification { pruneNotification := &proto_defs.Prune{Topic: topic} - return proto_defs.Notification{N: &proto_defs.Notification_Pruned{Pruned: pruneNotification}} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_Pruned{Pruned: pruneNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func ValidateMessageNotification(topic string) proto_defs.Notification { validateMessageNotification := &proto_defs.ValidateMessageGossip{Topic: topic} - return proto_defs.Notification{N: &proto_defs.Notification_ValidateMessage{ValidateMessage: validateMessageNotification}} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_ValidateMessage{ValidateMessage: validateMessageNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func DeliverMessageNotification(topic string) proto_defs.Notification { deliverMessageNotification := &proto_defs.DeliverMessage{Topic: topic} - return proto_defs.Notification{N: &proto_defs.Notification_DeliverMessage{DeliverMessage: deliverMessageNotification}} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_DeliverMessage{DeliverMessage: deliverMessageNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func UndeliverableMessageNotification(topic string) proto_defs.Notification { unDeliverableMessageNotification := &proto_defs.UnDeliverableMessage{Topic: topic} - return proto_defs.Notification{N: &proto_defs.Notification_UnDeliverableMessage{UnDeliverableMessage: unDeliverableMessageNotification}} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_UnDeliverableMessage{UnDeliverableMessage: unDeliverableMessageNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func RejectMessageNotification(topic string) proto_defs.Notification { rejectMessageNotification := &proto_defs.RejectMessage{Topic: topic} - return proto_defs.Notification{N: &proto_defs.Notification_RejectMessage{RejectMessage: rejectMessageNotification}} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_RejectMessage{RejectMessage: rejectMessageNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func DuplicateMessageNotification(topic string) proto_defs.Notification { duplicateMessageNotification := &proto_defs.DuplicateMessage{Topic: topic} - return proto_defs.Notification{N: &proto_defs.Notification_DuplicateMessage{DuplicateMessage: duplicateMessageNotification}} + tracer := &proto_defs.Tracer{T: &proto_defs.Tracer_DuplicateMessage{DuplicateMessage: duplicateMessageNotification}} + return proto_defs.Notification{N: &proto_defs.Notification_Tracer{Tracer: tracer}} } func GossipNotification(topic string, handler, msgId, message []byte) proto_defs.Notification { diff --git a/proto/libp2p.proto b/proto/libp2p.proto index c0e0111a6..936852217 100644 --- a/proto/libp2p.proto +++ b/proto/libp2p.proto @@ -158,22 +158,28 @@ message Result { } } +message Tracer { + oneof t { + Join joined = 1; + Leave left = 2; + Graft grafted = 3; + Prune pruned = 4; + ValidateMessageGossip validate_message = 5; + DeliverMessage deliver_message = 6; + UnDeliverableMessage un_deliverable_message = 7; + RejectMessage reject_message = 8; + DuplicateMessage duplicate_message = 9; + AddPeerGossip add_peer = 10; + RemovePeerGossip remove_peer = 11; + } +} + message Notification { oneof n { GossipSub gossip = 1; Request request = 2; NewPeer new_peer = 3; Result result = 4; - Join joined = 5; - Leave left = 6; - Graft grafted = 7; - Prune pruned = 8; - ValidateMessageGossip validate_message = 9; - DeliverMessage deliver_message = 10; - UnDeliverableMessage un_deliverable_message = 11; - RejectMessage reject_message = 12; - DuplicateMessage duplicate_message = 13; - AddPeerGossip add_peer = 14; - RemovePeerGossip remove_peer = 15; + Tracer tracer = 5; } }