-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve sync committee gossip logging (#6640)
Makes failures to gossip more visible, using the same throttling as applied to attestations.
- Loading branch information
Showing
7 changed files
with
221 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...king/eth2/src/main/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLogger.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright ConsenSys Software Inc., 2022 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.networking.eth2.gossip; | ||
|
||
import com.google.common.base.Throwables; | ||
import io.libp2p.pubsub.MessageAlreadySeenException; | ||
import io.libp2p.pubsub.NoPeersForOutboundMessageException; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
|
||
public class GossipFailureLogger { | ||
private static final Logger LOG = LogManager.getLogger(); | ||
|
||
private final String messageType; | ||
private UInt64 lastErroredSlot; | ||
private Throwable lastRootCause; | ||
|
||
public GossipFailureLogger(final String messageType) { | ||
this.messageType = messageType; | ||
} | ||
|
||
public synchronized void logWithSuppression(final Throwable error, final UInt64 slot) { | ||
final Throwable rootCause = Throwables.getRootCause(error); | ||
|
||
final boolean suppress = | ||
slot.equals(lastErroredSlot) && rootCause.getClass().equals(lastRootCause.getClass()); | ||
|
||
lastErroredSlot = slot; | ||
lastRootCause = rootCause; | ||
|
||
if (lastRootCause instanceof MessageAlreadySeenException) { | ||
LOG.debug( | ||
"Failed to publish {}(s) for slot {} because the message has already been seen", | ||
messageType, | ||
lastErroredSlot); | ||
} else if (lastRootCause instanceof NoPeersForOutboundMessageException) { | ||
LOG.log( | ||
suppress ? Level.DEBUG : Level.WARN, | ||
"Failed to publish {}(s) for slot {} because no peers were available on the required gossip topic", | ||
messageType, | ||
lastErroredSlot); | ||
} else { | ||
LOG.log( | ||
suppress ? Level.DEBUG : Level.ERROR, | ||
"Failed to publish {}(s) for slot {}", | ||
messageType, | ||
lastErroredSlot, | ||
error); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
.../eth2/src/test/java/tech/pegasys/teku/networking/eth2/gossip/GossipFailureLoggerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright ConsenSys Software Inc., 2022 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.networking.eth2.gossip; | ||
|
||
import io.libp2p.pubsub.MessageAlreadySeenException; | ||
import io.libp2p.pubsub.NoPeersForOutboundMessageException; | ||
import org.junit.jupiter.api.Test; | ||
import tech.pegasys.infrastructure.logging.LogCaptor; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
|
||
class GossipFailureLoggerTest { | ||
|
||
public static final String ALREADY_SEEN_MESSAGE = | ||
"Failed to publish thingy(s) for slot 1 because the message has already been seen"; | ||
public static final UInt64 SLOT = UInt64.ONE; | ||
public static final String NO_PEERS_MESSAGE = noPeersMessage(SLOT.intValue()); | ||
|
||
public static final String GENERIC_FAILURE_MESSAGE = "Failed to publish thingy(s) for slot 1"; | ||
|
||
private final GossipFailureLogger logger = new GossipFailureLogger("thingy"); | ||
|
||
@Test | ||
void shouldLogAlreadySeenErrorsAtDebugLevel() { | ||
try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { | ||
logger.logWithSuppression( | ||
new RuntimeException("Foo", new MessageAlreadySeenException("Dupe")), SLOT); | ||
logCaptor.assertDebugLog(ALREADY_SEEN_MESSAGE); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldLogFirstNoPeersErrorsAtWarningLevel() { | ||
try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { | ||
logger.logWithSuppression( | ||
new RuntimeException("Foo", new NoPeersForOutboundMessageException("So Lonely")), SLOT); | ||
logCaptor.assertWarnLog(NO_PEERS_MESSAGE); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldLogRepeatedNoPeersErrorsAtDebugLevel() { | ||
try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { | ||
logger.logWithSuppression( | ||
new RuntimeException("Foo", new NoPeersForOutboundMessageException("So Lonely")), SLOT); | ||
logCaptor.clearLogs(); | ||
|
||
logger.logWithSuppression( | ||
new IllegalStateException( | ||
"Foo", new NoPeersForOutboundMessageException("Not a friend in the world")), | ||
SLOT); | ||
logCaptor.assertDebugLog(NO_PEERS_MESSAGE); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldLogNoPeersErrorsWithDifferentSlotsAtWarnLevel() { | ||
try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { | ||
logger.logWithSuppression( | ||
new RuntimeException("Foo", new NoPeersForOutboundMessageException("So Lonely")), SLOT); | ||
logCaptor.assertWarnLog(NO_PEERS_MESSAGE); | ||
|
||
logger.logWithSuppression( | ||
new IllegalStateException( | ||
"Foo", new NoPeersForOutboundMessageException("Not a friend in the world")), | ||
UInt64.valueOf(2)); | ||
logCaptor.assertWarnLog(noPeersMessage(2)); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldLogNoPeersErrorsAtWarnLevelWhenSeparatedByADifferentException() { | ||
try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { | ||
logger.logWithSuppression( | ||
new RuntimeException("Foo", new NoPeersForOutboundMessageException("So Lonely")), SLOT); | ||
logCaptor.assertWarnLog(NO_PEERS_MESSAGE); | ||
logCaptor.clearLogs(); | ||
|
||
logger.logWithSuppression(new MessageAlreadySeenException("Dupe"), SLOT); | ||
|
||
logger.logWithSuppression( | ||
new IllegalStateException( | ||
"Foo", new NoPeersForOutboundMessageException("Not a friend in the world")), | ||
SLOT); | ||
logCaptor.assertWarnLog(NO_PEERS_MESSAGE); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldLogFirstGenericErrorAtErrorLevel() { | ||
try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { | ||
logger.logWithSuppression( | ||
new RuntimeException("Foo", new IllegalStateException("Boom")), SLOT); | ||
logCaptor.assertErrorLog(GENERIC_FAILURE_MESSAGE); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldLogRepeatedGenericErrorsAtDebugLevel() { | ||
try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { | ||
logger.logWithSuppression( | ||
new RuntimeException("Foo", new IllegalStateException("Boom")), SLOT); | ||
logCaptor.clearLogs(); | ||
|
||
logger.logWithSuppression( | ||
new IllegalStateException("Foo", new IllegalStateException("goes the dynamite")), SLOT); | ||
logCaptor.assertDebugLog(GENERIC_FAILURE_MESSAGE); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldLogMultipleGenericErrorsWithDifferentCausesAtErrorLevel() { | ||
try (final LogCaptor logCaptor = LogCaptor.forClass(GossipFailureLogger.class)) { | ||
logger.logWithSuppression( | ||
new RuntimeException("Foo", new IllegalStateException("Boom")), SLOT); | ||
logCaptor.assertErrorLog(GENERIC_FAILURE_MESSAGE); | ||
logCaptor.clearLogs(); | ||
|
||
logger.logWithSuppression( | ||
new IllegalStateException("Foo", new IllegalArgumentException("goes the dynamite")), | ||
SLOT); | ||
logCaptor.assertErrorLog(GENERIC_FAILURE_MESSAGE); | ||
} | ||
} | ||
|
||
private static String noPeersMessage(final int slot) { | ||
return "Failed to publish thingy(s) for slot " | ||
+ slot | ||
+ " because no peers were available on the required gossip topic"; | ||
} | ||
} |