Skip to content

Commit

Permalink
merge from upstream
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Petrov <anthony@swirldslabs.com>
  • Loading branch information
anthony-swirldslabs committed Nov 21, 2024
2 parents a711b60 + 76d3126 commit eb58071
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static com.swirlds.platform.StateInitializer.initializeState;
import static com.swirlds.platform.event.preconsensus.PcesBirthRoundMigration.migratePcesToBirthRoundMode;
import static com.swirlds.platform.state.BirthRoundStateMigration.modifyStateForBirthRoundMigration;
import static com.swirlds.platform.state.address.AddressBookMetrics.registerAddressBookMetrics;
import static com.swirlds.platform.state.address.RosterMetrics.registerRosterMetrics;
import static com.swirlds.platform.state.snapshot.SignedStateFileReader.getSavedStateFiles;

import com.hedera.hapi.node.state.roster.Roster;
Expand Down Expand Up @@ -222,7 +222,7 @@ public SwirldsPlatform(@NonNull final PlatformComponentBuilder builder) {

platformWiring = new PlatformWiring(platformContext, blocks.model(), blocks.applicationCallbacks());

registerAddressBookMetrics(platformContext.getMetrics(), currentAddressBook, selfId);
registerRosterMetrics(platformContext.getMetrics(), currentRoster, selfId);

RuntimeMetrics.setup(platformContext.getMetrics());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import com.swirlds.platform.state.signed.ReservedSignedState;
import com.swirlds.platform.state.signed.SignedState;
import com.swirlds.platform.system.SoftwareVersion;
import com.swirlds.platform.system.address.AddressBook;
import com.swirlds.platform.system.status.PlatformStatus;
import com.swirlds.platform.system.status.StatusActionSubmitter;
import com.swirlds.platform.wiring.NoInput;
Expand Down Expand Up @@ -227,8 +226,7 @@ public SyncGossip(
networkMetrics = new NetworkMetrics(platformContext.getMetrics(), selfId, roster);
platformContext.getMetrics().addUpdater(networkMetrics::update);

final AddressBook addressBook = RosterUtils.buildAddressBook(roster);
reconnectMetrics = new ReconnectMetrics(platformContext.getMetrics(), addressBook);
reconnectMetrics = new ReconnectMetrics(platformContext.getMetrics(), roster);

final StateConfig stateConfig = platformContext.getConfiguration().getConfigData(StateConfig.class);

Expand All @@ -255,7 +253,7 @@ public SyncGossip(
new ReconnectLearnerFactory(
platformContext,
threadManager,
addressBook,
RosterUtils.buildAddressBook(roster),
reconnectConfig.asyncStreamTimeout(),
reconnectMetrics),
stateConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@
import static com.swirlds.metrics.api.FloatFormats.FORMAT_10_0;
import static com.swirlds.metrics.api.Metrics.PLATFORM_CATEGORY;

import com.hedera.hapi.node.state.roster.Roster;
import com.swirlds.common.metrics.extensions.CountPerSecond;
import com.swirlds.common.platform.NodeId;
import com.swirlds.common.units.TimeUnit;
import com.swirlds.metrics.api.Counter;
import com.swirlds.metrics.api.LongAccumulator;
import com.swirlds.metrics.api.Metrics;
import com.swirlds.platform.system.address.Address;
import com.swirlds.platform.system.address.AddressBook;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.time.Duration;
import java.util.HashMap;
Expand Down Expand Up @@ -62,7 +60,7 @@ public class ReconnectMetrics {
/**
* Number of reconnect rejections per second per peer in the address book.
*/
private final Map<NodeId, CountPerSecond> rejectionFrequency = new HashMap<>();
private final Map<Long, CountPerSecond> rejectionFrequency = new HashMap<>();

private static final LongAccumulator.Config SENDER_DURATION_CONFIG = new LongAccumulator.Config(
RECONNECT_CATEGORY, "senderReconnectDurationSeconds")
Expand Down Expand Up @@ -92,32 +90,33 @@ public class ReconnectMetrics {
*
* @param metrics
* reference to the metrics-system
* @param roster the roster reflecting the address book to register metrics for
* @throws IllegalArgumentException if {@code metrics} is {@code null}
*/
public ReconnectMetrics(@NonNull final Metrics metrics, @NonNull final AddressBook addressBook) {
public ReconnectMetrics(@NonNull final Metrics metrics, @NonNull final Roster roster) {
Objects.requireNonNull(metrics, "metrics");
Objects.requireNonNull(addressBook, "addressBook");
Objects.requireNonNull(roster, "roster");
senderStartTimes = metrics.getOrCreate(SENDER_START_TIMES_CONFIG);
receiverStartTimes = metrics.getOrCreate(RECEIVER_START_TIMES_CONFIG);
senderEndTimes = metrics.getOrCreate(SENDER_END_TIMES_CONFIG);
receiverEndTimes = metrics.getOrCreate(RECEIVER_END_TIMES_CONFIG);
senderReconnectDurationSeconds = metrics.getOrCreate(SENDER_DURATION_CONFIG);
receiverReconnectDurationSeconds = metrics.getOrCreate(RECEIVER_DURATION_CONFIG);

for (final Address address : addressBook) {
final NodeId nodeId = address.getNodeId();
roster.rosterEntries().forEach(entry -> {
final long nodeId = entry.nodeId();
rejectionFrequency.put(
nodeId,
new CountPerSecond(
metrics,
new CountPerSecond.Config(
PLATFORM_CATEGORY,
String.format("reconnectRejections_per_sec_%02d", nodeId.id()))
String.format("reconnectRejections_per_sec_%02d", nodeId))
.withDescription(String.format(
"number of reconnections rejected per second from node %02d", nodeId.id()))
"number of reconnections rejected per second from node %02d", nodeId))
.withUnit("rejectionsPerSec")
.withFormat(FORMAT_10_0)));
}
});
}

public void incrementSenderStartTimes() {
Expand Down Expand Up @@ -147,10 +146,10 @@ public void incrementReceiverEndTimes() {
*
* @param nodeId the peer being rejected.
*/
public void recordReconnectRejection(@NonNull final NodeId nodeId) {
Objects.requireNonNull(nodeId);
if (rejectionFrequency.containsKey(nodeId)) {
rejectionFrequency.get(nodeId).count();
public void recordReconnectRejection(final long nodeId) {
final Long id = nodeId;
if (rejectionFrequency.containsKey(id)) {
rejectionFrequency.get(id).count();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private void reconnectRejected() {
teacherState.close();
teacherState = null;
}
reconnectMetrics.recordReconnectRejection(peerId);
reconnectMetrics.recordReconnectRejection(peerId.id());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,36 @@

package com.swirlds.platform.state.address;

import com.hedera.hapi.node.state.roster.Roster;
import com.swirlds.common.metrics.FunctionGauge;
import com.swirlds.common.platform.NodeId;
import com.swirlds.metrics.api.Metrics;
import com.swirlds.platform.system.address.AddressBook;
import edu.umd.cs.findbugs.annotations.NonNull;

/**
* A utility class to encapsulate the metrics for the address book.
*/
public final class AddressBookMetrics {
public final class RosterMetrics {

private AddressBookMetrics() {}
private RosterMetrics() {}

/**
* Register the metrics for the address book.
*
* @param metrics the metrics engine
* @param addressBook the address book to register metrics for
* @param roster the roster to register metrics for
* @param selfId the ID of the node
*/
public static void registerAddressBookMetrics(
@NonNull final Metrics metrics, @NonNull final AddressBook addressBook, @NonNull final NodeId selfId) {
public static void registerRosterMetrics(
@NonNull final Metrics metrics, @NonNull final Roster roster, @NonNull final NodeId selfId) {

metrics.getOrCreate(new FunctionGauge.Config<>(Metrics.INFO_CATEGORY, "memberID", Long.class, selfId::id)
.withUnit("nodeID")
.withDescription("The node ID number of this member"));

metrics.getOrCreate(
new FunctionGauge.Config<>(Metrics.INFO_CATEGORY, "members", Integer.class, addressBook::getSize)
.withUnit("count")
.withDescription("total number of nodes currently in the address book"));
metrics.getOrCreate(new FunctionGauge.Config<>(
Metrics.INFO_CATEGORY, "members", Integer.class, roster.rosterEntries()::size)
.withUnit("count")
.withDescription("total number of nodes currently in the roster"));
}
}

0 comments on commit eb58071

Please sign in to comment.