From bee0f6d8fbc0caa3f5991ea2aa9d401063334605 Mon Sep 17 00:00:00 2001 From: Artem Vysochyn Date: Tue, 8 Oct 2024 21:42:05 +0300 Subject: [PATCH] Improved number pattern in logs --- .../fdetector/FailureDetectorImpl.java | 67 ++++++++++++------- .../cluster/gossip/GossipProtocolImpl.java | 23 +++++-- .../membership/MembershipProtocolImpl.java | 2 +- .../cluster/metadata/MetadataStoreImpl.java | 8 +-- 4 files changed, 64 insertions(+), 36 deletions(-) diff --git a/cluster/src/main/java/io/scalecube/cluster/fdetector/FailureDetectorImpl.java b/cluster/src/main/java/io/scalecube/cluster/fdetector/FailureDetectorImpl.java index a85b4b3c..dc6f3d0f 100644 --- a/cluster/src/main/java/io/scalecube/cluster/fdetector/FailureDetectorImpl.java +++ b/cluster/src/main/java/io/scalecube/cluster/fdetector/FailureDetectorImpl.java @@ -91,7 +91,7 @@ public FailureDetectorImpl( ex -> LOGGER.log( Level.ERROR, - "[{0}][{1}][onMessage][error] cause:", + "[{0}][{1,number,#}][onMessage][error] cause:", localMember, currentPeriod, ex)), @@ -102,7 +102,7 @@ public FailureDetectorImpl( ex -> LOGGER.log( Level.ERROR, - "[{0}][{1}][onMembershipEvent][error] cause:", + "[{0}][{1,number,#}][onMembershipEvent][error] cause:", localMember, currentPeriod, ex)))); @@ -148,7 +148,8 @@ private void doPing() { PingData pingData = new PingData(localMember, pingMember); Message pingMsg = Message.withData(pingData).qualifier(PING).correlationId(cid).build(); - LOGGER.log(Level.DEBUG, "[{0}][{1}] Send Ping to {2}", localMember, period, pingMember); + LOGGER.log( + Level.DEBUG, "[{0}][{1,number,#}] Send Ping to {2}", localMember, period, pingMember); String address = pingMember.address(); transport .requestResponse(address, pingMsg) @@ -158,7 +159,7 @@ private void doPing() { message -> { LOGGER.log( Level.DEBUG, - "[{0}][{1}] Received PingAck from {2}", + "[{0}][{1,number,#}] Received PingAck from {2}", localMember, period, message.sender()); @@ -167,7 +168,7 @@ private void doPing() { ex -> { LOGGER.log( Level.DEBUG, - "[{0}][{1}] Failed to get PingAck from {2} within {3} ms", + "[{0}][{1,number,#}] Failed to get PingAck from {2} within {3} ms", localMember, period, pingMember, @@ -177,7 +178,8 @@ private void doPing() { final List pingReqMembers = selectPingReqMembers(pingMember); if (timeLeft <= 0 || pingReqMembers.isEmpty()) { - LOGGER.log(Level.DEBUG, "[{0}][{1}] No PingReq occurred", localMember, period); + LOGGER.log( + Level.DEBUG, "[{0}][{1,number,#}] No PingReq occurred", localMember, period); publishPingResult(period, pingMember, MemberStatus.SUSPECT); } else { doPingReq(currentPeriod, pingMember, pingReqMembers, cid); @@ -194,7 +196,7 @@ private void doPingReq( .build(); LOGGER.log( Level.DEBUG, - "[{0}][{1}] Send PingReq to {2} for {3}", + "[{0}][{1,number,#}] Send PingReq to {2} for {3}", localMember, period, pingReqMembers, @@ -211,7 +213,7 @@ private void doPingReq( message -> { LOGGER.log( Level.DEBUG, - "[{0}][{1}] Received transit PingAck from {2} to {3}", + "[{0}][{1,number,#}] Received transit PingAck from {2} to {3}", localMember, period, message.sender(), @@ -221,8 +223,9 @@ private void doPingReq( throwable -> { LOGGER.log( Level.DEBUG, - "[{0}][{1}] " - + "Timeout getting transit PingAck from {2} to {3} within {4} ms", + "[{0}][{1,number,#}] " + + "Timeout getting transit " + + "PingAck from {2} to {3} within {4,number,#}ms", localMember, period, member, @@ -250,13 +253,14 @@ private void onMessage(Message message) { private void onPing(Message message) { long period = this.currentPeriod; String sender = message.sender(); - LOGGER.log(Level.DEBUG, "[{0}][{1}] Received Ping from {2}", localMember, period, sender); + LOGGER.log( + Level.DEBUG, "[{0}][{1,number,#}] Received Ping from {2}", localMember, period, sender); PingData data = message.data(); data = data.withAckType(AckType.DEST_OK); if (!data.getTo().id().equals(localMember.id())) { LOGGER.log( Level.DEBUG, - "[{0}][{1}] Received Ping from {2} to {3}, but local member is {4}", + "[{0}][{1,number,#}] Received Ping from {2} to {3}, but local member is {4}", localMember, period, sender, @@ -268,7 +272,8 @@ private void onPing(Message message) { Message ackMessage = Message.withData(data).qualifier(PING_ACK).correlationId(correlationId).build(); String address = data.getFrom().address(); - LOGGER.log(Level.DEBUG, "[{0}][{1}] Send PingAck to {2}", localMember, period, address); + LOGGER.log( + Level.DEBUG, "[{0}][{1,number,#}] Send PingAck to {2}", localMember, period, address); transport .send(address, ackMessage) .subscribe( @@ -276,7 +281,7 @@ private void onPing(Message message) { ex -> LOGGER.log( Level.DEBUG, - "[{0}][{1}] Failed to send PingAck to {2}, cause: {3}", + "[{0}][{1,number,#}] Failed to send PingAck to {2}, cause: {3}", localMember, period, address, @@ -287,7 +292,11 @@ private void onPing(Message message) { private void onPingReq(Message message) { long period = this.currentPeriod; LOGGER.log( - Level.DEBUG, "[{0}][{1}] Received PingReq from {2}", localMember, period, message.sender()); + Level.DEBUG, + "[{0}][{1,number,#}] Received PingReq from {2}", + localMember, + period, + message.sender()); PingData data = message.data(); Member target = data.getTo(); Member originalIssuer = data.getFrom(); @@ -296,7 +305,8 @@ private void onPingReq(Message message) { Message pingMessage = Message.withData(pingReqData).qualifier(PING).correlationId(correlationId).build(); String address = target.address(); - LOGGER.log(Level.DEBUG, "[{0}][{1}] Send transit Ping to {2}", localMember, period, address); + LOGGER.log( + Level.DEBUG, "[{0}][{1,number,#}] Send transit Ping to {2}", localMember, period, address); transport .send(address, pingMessage) .subscribe( @@ -304,7 +314,7 @@ private void onPingReq(Message message) { ex -> LOGGER.log( Level.DEBUG, - "[{0}][{1}] Failed to send transit Ping to {2}, cause: {3}", + "[{0}][{1,number,#}] Failed to send transit Ping to {2}, cause: {3}", localMember, period, address, @@ -319,7 +329,7 @@ private void onTransitPingAck(Message message) { long period = this.currentPeriod; LOGGER.log( Level.DEBUG, - "[{0}][{1}] Received transit PingAck from {2}", + "[{0}][{1,number,#}] Received transit PingAck from {2}", localMember, period, message.sender()); @@ -332,7 +342,11 @@ private void onTransitPingAck(Message message) { Message.withData(originalAckData).qualifier(PING_ACK).correlationId(correlationId).build(); String address = target.address(); LOGGER.log( - Level.DEBUG, "[{0}][{1}] Resend transit PingAck to {2}", localMember, period, address); + Level.DEBUG, + "[{0}][{1,number,#}] Resend transit PingAck to {2}", + localMember, + period, + address); transport .send(address, originalAckMessage) .subscribe( @@ -340,7 +354,7 @@ private void onTransitPingAck(Message message) { ex -> LOGGER.log( Level.DEBUG, - "[{0}][{1}] Failed to resend transit PingAck to {2}, cause: {3}", + "[{0}][{1,number,#}] Failed to resend transit PingAck to {2}, cause: {3}", localMember, period, address, @@ -354,7 +368,7 @@ private void onMembershipEvent(MembershipEvent event) { if (removed) { LOGGER.log( Level.DEBUG, - "[{0}][{1}] Removed {2} from pingMembers list (size={3})", + "[{0}][{1,number,#}] Removed {2} from pingMembers list (size={3})", localMember, currentPeriod, member, @@ -368,7 +382,7 @@ private void onMembershipEvent(MembershipEvent event) { pingMembers.add(index, member); LOGGER.log( Level.DEBUG, - "[{0}][{1}] Added {2} to pingMembers list (size={3})", + "[{0}][{1,number,#}] Added {2} to pingMembers list (size={3})", localMember, currentPeriod, member, @@ -407,7 +421,12 @@ private List selectPingReqMembers(Member pingMember) { private void publishPingResult(long period, Member member, MemberStatus status) { LOGGER.log( - Level.DEBUG, "[{0}][{1}] Member {2} detected as {3}", localMember, period, member, status); + Level.DEBUG, + "[{0}][{1,number,#}] Member {2} detected as {3}", + localMember, + period, + member, + status); sink.emitNext(new FailureDetectorEvent(member, status), busyLooping(Duration.ofSeconds(3))); } @@ -430,7 +449,7 @@ private MemberStatus computeMemberStatus(Message message, long period) { default: LOGGER.log( Level.WARNING, - "[{0}][{1}] Unknown PingData.AckType received: {2}", + "[{0}][{1,number,#}] Unknown PingData.AckType received: {2}", localMember, period, ackType); diff --git a/cluster/src/main/java/io/scalecube/cluster/gossip/GossipProtocolImpl.java b/cluster/src/main/java/io/scalecube/cluster/gossip/GossipProtocolImpl.java index 28cb2857..66746cfd 100644 --- a/cluster/src/main/java/io/scalecube/cluster/gossip/GossipProtocolImpl.java +++ b/cluster/src/main/java/io/scalecube/cluster/gossip/GossipProtocolImpl.java @@ -169,7 +169,11 @@ private void doSpreadGossip() { Set gossipsToRemove = getGossipsToRemove(period); if (!gossipsToRemove.isEmpty()) { LOGGER.log( - Level.DEBUG, "[{0}][{1}] Sweep gossips: {2}", localMember, period, gossipsToRemove); + Level.DEBUG, + "[{0}][{1,number,#}] Sweep gossips: {2}", + localMember, + period, + gossipsToRemove); for (String gossipId : gossipsToRemove) { gossips.remove(gossipId); } @@ -180,7 +184,7 @@ private void doSpreadGossip() { if (!gossipsThatSpread.isEmpty()) { LOGGER.log( Level.DEBUG, - "[{0}][{1}] Most likely disseminated gossips: {2}", + "[{0}][{1,number,#}] Most likely disseminated gossips: {2}", localMember, period, gossipsThatSpread); @@ -193,7 +197,11 @@ private void doSpreadGossip() { } } catch (Exception ex) { LOGGER.log( - Level.WARNING, "[{0}][{1}][doSpreadGossip] Exception occurred:", localMember, period, ex); + Level.WARNING, + "[{0}][{1,number,#}][doSpreadGossip] Exception occurred:", + localMember, + period, + ex); } } @@ -240,7 +248,7 @@ private void checkGossipSegmentation() { if (sequenceIdCollector.size() > intervalsThreshold) { LOGGER.log( Level.WARNING, - "[{0}][{1}] Too many missed gossip messages from original gossiper: {2}, " + "[{0}][{1,number,#}] Too many missed gossip messages from original gossiper: {2}, " + "current node({3}) was SUSPECTED much for a long time or connection problem", localMember, currentPeriod, @@ -260,7 +268,7 @@ private void onMembershipEvent(MembershipEvent event) { if (removed) { LOGGER.log( Level.DEBUG, - "[{0}][{1}] Removed {2} from remoteMembers list (size={3})", + "[{0}][{1,number,#}] Removed {2} from remoteMembers list (size={3,number,#})", localMember, currentPeriod, member, @@ -271,7 +279,7 @@ private void onMembershipEvent(MembershipEvent event) { remoteMembers.add(member); LOGGER.log( Level.DEBUG, - "[{0}][{1}] Added {2} to remoteMembers list (size={3})", + "[{0}][{1,number,#}] Added {2} to remoteMembers list (size={3,number,#})", localMember, currentPeriod, member, @@ -316,7 +324,8 @@ private void spreadGossipsTo(long period, Member member) { ex -> LOGGER.log( Level.DEBUG, - "[{0}][{1}] Failed to send GossipReq({2}) to {3}, cause: {4}", + "[{0}][{1,number,#}] " + + "Failed to send GossipReq({2}) to {3}, cause: {4}", localMember, period, message, diff --git a/cluster/src/main/java/io/scalecube/cluster/membership/MembershipProtocolImpl.java b/cluster/src/main/java/io/scalecube/cluster/membership/MembershipProtocolImpl.java index 855319aa..7ecf5067 100644 --- a/cluster/src/main/java/io/scalecube/cluster/membership/MembershipProtocolImpl.java +++ b/cluster/src/main/java/io/scalecube/cluster/membership/MembershipProtocolImpl.java @@ -850,7 +850,7 @@ private void scheduleSuspicionTimeoutTask(MembershipRecord r) { id -> { LOGGER.log( Level.DEBUG, - "[{0}] Scheduled SuspicionTimeoutTask for {1}, suspicionTimeout: {2}", + "[{0}] Scheduled SuspicionTimeoutTask for {1}, suspicionTimeout: {2,number,#}ms", localMember, id, suspicionTimeout); diff --git a/cluster/src/main/java/io/scalecube/cluster/metadata/MetadataStoreImpl.java b/cluster/src/main/java/io/scalecube/cluster/metadata/MetadataStoreImpl.java index 52e0c29a..c5710d6a 100644 --- a/cluster/src/main/java/io/scalecube/cluster/metadata/MetadataStoreImpl.java +++ b/cluster/src/main/java/io/scalecube/cluster/metadata/MetadataStoreImpl.java @@ -117,14 +117,14 @@ public ByteBuffer updateMetadata(Member member, ByteBuffer metadata) { if (result == null) { LOGGER.log( Level.DEBUG, - "[{0}] Added metadata(size={1}) for member {2}", + "[{0}] Added metadata(size={1,number,#}) for member {2}", localMember, value.remaining(), member); } else { LOGGER.log( Level.DEBUG, - "[{0}] Updated metadata(size={1}) for member {2}", + "[{0}] Updated metadata(size={1,number,#}) for member {2}", localMember, value.remaining(), member); @@ -142,7 +142,7 @@ public ByteBuffer removeMetadata(Member member) { if (metadata != null) { LOGGER.log( Level.DEBUG, - "[{0}] Removed metadata(size={1}) for member {2}", + "[{0}] Removed metadata(size={1,number,#}) for member {2}", localMember, metadata.remaining(), member); @@ -187,7 +187,7 @@ public Mono fetchMetadata(Member member) { LOGGER.log( Level.WARNING, "[{0}][{1}] Timeout getting GetMetadataResp " - + "from {2} within {3} ms, cause: {4}", + + "from {2} within {3,number,#}ms, cause: {4}", localMember, cid, targetAddress,