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

cardano-ping trace log changes #4593

Merged
merged 3 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions cardano-ping/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Revision history for cardano-ping

## 0.2.0.4 -- 2023-06-12

* Using `ISO8601` time format.
* Only print negotiated version, if negotiation took place on the remote side.
* Fixed formatting of ping messages.

## 0.2.0.3 -- 2023-06-09

* For versions strictly lower than `NodeToNodeV_11`, send
Expand Down
3 changes: 2 additions & 1 deletion cardano-ping/cardano-ping.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: cardano-ping
version: 0.2.0.3
version: 0.2.0.4
synopsis: Utility for pinging cardano nodes
description: Utility for pinging cardano nodes.
license: Apache-2.0
Expand All @@ -27,6 +27,7 @@ library
cborg >=0.2.8 && <0.3,
bytestring >=0.10 && <0.12,
contra-tracer >=0.1 && <0.2,
time,

si-timers ^>=1.1,
strict-stm,
Expand Down
16 changes: 11 additions & 5 deletions cardano-ping/src/Cardano/Network/Ping.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import Data.ByteString.Lazy (ByteString)
import Data.Maybe (fromMaybe,)
import Data.TDigest (insert, maximumValue, minimumValue, tdigest, mean, quantile, stddev, TDigest)
import Data.Text (unpack)
import Data.Time.Format.ISO8601 (iso8601Show)
import Data.Word (Word16, Word32)
import Network.Mux.Bearer (MakeBearer (..), makeSocketBearer)
import Network.Mux.Timeout (TimeoutFn, withTimeoutSerial)
Expand Down Expand Up @@ -93,7 +94,7 @@ logger msgQueue json query = go True
let bs' = case (json, first) of
(True, False) -> LBS.Char.pack ",\n" <> bs
(True, True) -> LBS.Char.pack "{ \"pongs\": [ " <> bs
(False, True) -> LBS.Char.pack " timestamp, host, cookie, sample, median, p90, mean, min, max, std\n" <> bs
(False, True) -> LBS.Char.pack "timestamp, host, cookie, sample, median, p90, mean, min, max, std\n" <> bs
(False, False) -> bs

LBS.Char.putStr bs'
Expand Down Expand Up @@ -413,8 +414,8 @@ data StatPoint = StatPoint
instance Show StatPoint where
show :: StatPoint -> String
show StatPoint {..} =
printf "%36s, %-28s, %7d, %7.3f, %7.3f, %7.3f, %7.3f, %7.3f, %7.3f, %7.3f"
(show spTimestamp) spHost spCookie spSample spMedian spP90 spMean spMin spMax spStd
printf "%-31s %-28s %7d, %7.3f, %7.3f, %7.3f, %7.3f, %7.3f, %7.3f, %7.3f"
(iso8601Show spTimestamp ++ ",") (spHost ++ ",") spCookie spSample spMedian spP90 spMean spMin spMax spStd

instance ToJSON StatPoint where
toJSON :: StatPoint -> Value
Expand Down Expand Up @@ -498,9 +499,14 @@ pingClient stdout stderr PingOpts{pingOptsQuiet, pingOptsJson, pingOptsCount, pi
Left err -> do
eprint $ printf "%s Version negotiation error %s\nReceived versions: %s\n" peerStr err (show recVersions)
Right version -> do
unless pingOptsQuiet $
let querySupported = version >= NodeToNodeVersionV11 minBound minBound
when ( (not pingOptsHandshakeQuery && not pingOptsQuiet)
|| ( pingOptsHandshakeQuery && not querySupported)) $
-- print the negotiated version iff not quiet or querying but, query
-- is not supported by the remote host.
printf "%s Negotiated version %s\n" peerStr (show version)
when (pingOptsHandshakeQuery && version >= NodeToNodeVersionV11 minBound minBound) $
when (pingOptsHandshakeQuery && querySupported) $
-- print query results if it was supported by the remote side
printf "%s Queried versions %s\n" peerStr (show recVersions)
unless pingOptsHandshakeQuery $ do
keepAlive bearer timeoutfn peerStr version (tdigest []) 0
Expand Down
Loading