Skip to content

feat: count the messages and the bytes in and out of the peer, for each command, in four counters of the metrics (#79) - #96

Open
lorenzolfm wants to merge 3 commits into
mainfrom
issue-79-messages
Open

lorenzolfm wants to merge 3 commits into
mainfrom
issue-79-messages

Conversation

@lorenzolfm

Copy link
Copy Markdown
Owner

Part of #79.

What

Why

Count in Socket. Each message that elo reads goes through Socket::receive. Each message that elo writes goes through Socket::send. So two calls count all of the messages, of the handshake and after it. Rejected: count in run_send and run_turn. That needs more calls, and the handshake has its own path.

When a message counts. A received message counts when elo has its full frame and the checksum is correct. A frame with a bad checksum ends the connection, and does not count. A sent message counts when write_all ends. A write that a send timeout stops does not count.

Bytes include the 24-byte header. The per-message bytes of Core's getpeerinfo include the header too. So the two can be compared. Metrics adds the header, so net.rs has no arithmetic, and the unit tests kill each mutant of it.

A fixed set of command values. The values are the 10 commands in protocol.rs, and other for each other command. A peer cannot add a series with a new command name. The table COMMANDS has the message type and the label of each command. A test checks that each label is the name of its message type.

The same values in the two directions. Sent and received have all 11 values, so one query can match the two directions. elo does not send headers, inv, wtxidrelay, sendaddrv2 or other, so these 5 sent series stay at 0. Rejected: a second set for the sent commands. It needs one more type, and a new command (#62 getdata) would go into two lists.

No reset at a reconnect. A counter must not go down. Prometheus rate() sees a reset as a restart.

8 KiB. With each value at its maximum, the body is now at most 4993 bytes (the assert in Text::end gives this number). 4 KiB is too small. So 8 KiB, the next power of 2, as for the 2 KiB in #95. That leaves about 3 KiB for the metrics of #62 and #64.

Doc nits. elo_reconnects_total counts each move into wait: also a failed lookup, dial or handshake, not only a connection that ended. The help and the README now say so. The README says that Prometheus keeps a 64-bit float, so it rounds a work above 2^53.

Checks

  • L3 metrics_of_elo_have_its_tip_its_step_each_reconnect_and_the_bytes_of_each_command: after a sync of 2001 headers, the bytes of each command are equal to the per-message bytes of getpeerinfo, in the two directions. Core sends sendcmpct and feefilter, and these go into other (2 messages, 65 bytes).
  • promtool check metrics (Prometheus 3.16) accepts a real scrape (3985 bytes).
  • nix flake check passes. L3 ran in a netns.
  • Mutants on the diff: 14 caught, 0 missed, 5 unviable.

Not confident

  • other hides which unknown command a peer sends. The log does not show it either. If that is necessary, more commands can go into COMMANDS.
  • The lookup of a command is a linear search of 10 entries for each message. That is small next to the read, and no benchmark exists yet (Benchmarks #32).
  • No unit test in net.rs checks the counts. Metrics has no read function for other modules, and I did not add one for a test. The L3 test checks the two calls against Core.

…ch command, in four counters of the metrics (#79)

The socket of a connection has the metrics, so each message is counted
at the one place where elo reads it and the one place where elo writes
it. A received message counts when elo has its full frame and the frame
is valid. A sent message counts when its write ends. The bytes include
the 24 bytes of the header, as in the per-message bytes of the peer.

The label `command` has a fixed set of values: each command that elo
knows, and `other` for each other command. So a peer cannot add series.
The sent and the received counters have the same values, so that one
query can match the two directions. Some sent series stay at 0.

The counters do not reset at a reconnect, as a counter must not go
down.

The longest body is now 4993 bytes, so `BODY_LENGTH_MAX` is 8 KiB.
…shake is a reconnect too, and that Prometheus rounds the work (#79)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant