mirror of
https://github.com/bisq-network/bisq.git
synced 2025-01-19 05:44:05 +01:00
Report size or faults of GetDataResponse and GetBlocksResponse.
Remove Unspecified and use optional instead. Add reporting for data requests and hash requests. Report commit hash only if present. Report messages only if an enum entry is present. Signed-off-by: HenrikJannsen <boilingfrog@gmx.com>
This commit is contained in:
parent
d5b4ce275b
commit
12e8b46859
@ -17,12 +17,14 @@
|
||||
|
||||
package bisq.seednode.reporting;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public enum DoubleValueReportingItem implements ReportingItem {
|
||||
Unspecified("", "Unspecified"),
|
||||
sentBytesPerSec("network", "sentBytesPerSec"),
|
||||
receivedBytesPerSec("network", "receivedBytesPerSec"),
|
||||
receivedMessagesPerSec("network", "receivedMessagesPerSec"),
|
||||
@ -47,16 +49,15 @@ public enum DoubleValueReportingItem implements ReportingItem {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static DoubleValueReportingItem from(String key, double value) {
|
||||
DoubleValueReportingItem item;
|
||||
public static Optional<DoubleValueReportingItem> from(String key, double value) {
|
||||
try {
|
||||
item = DoubleValueReportingItem.valueOf(key);
|
||||
DoubleValueReportingItem item = DoubleValueReportingItem.valueOf(key);
|
||||
item.setValue(value);
|
||||
return Optional.of(item);
|
||||
} catch (Throwable t) {
|
||||
item = Unspecified;
|
||||
log.warn("No enum value with {}", key);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
item.setValue(value);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -66,8 +67,8 @@ public enum DoubleValueReportingItem implements ReportingItem {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static DoubleValueReportingItem fromProto(protobuf.ReportingItem baseProto,
|
||||
protobuf.DoubleValueReportingItem proto) {
|
||||
public static Optional<DoubleValueReportingItem> fromProto(protobuf.ReportingItem baseProto,
|
||||
protobuf.DoubleValueReportingItem proto) {
|
||||
return DoubleValueReportingItem.from(baseProto.getKey(), proto.getValue());
|
||||
}
|
||||
|
||||
|
@ -17,13 +17,16 @@
|
||||
|
||||
package bisq.seednode.reporting;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public enum LongValueReportingItem implements ReportingItem {
|
||||
Unspecified("", "Unspecified"),
|
||||
OfferPayload("data", "OfferPayload"),
|
||||
BsqSwapOfferPayload("data", "BsqSwapOfferPayload"),
|
||||
MailboxStoragePayload("data", "MailboxStoragePayload"),
|
||||
TradeStatistics3("data", "TradeStatistics3"),
|
||||
AccountAgeWitness("data", "AccountAgeWitness"),
|
||||
@ -47,6 +50,21 @@ public enum LongValueReportingItem implements ReportingItem {
|
||||
sentBytes("network", "sentBytes"),
|
||||
receivedBytes("network", "receivedBytes"),
|
||||
|
||||
PreliminaryGetDataRequest("network", "PreliminaryGetDataRequest"),
|
||||
GetUpdatedDataRequest("network", "GetUpdatedDataRequest"),
|
||||
GetBlocksRequest("network", "GetBlocksRequest"),
|
||||
GetDaoStateHashesRequest("network", "GetDaoStateHashesRequest"),
|
||||
GetProposalStateHashesRequest("network", "GetProposalStateHashesRequest"),
|
||||
GetBlindVoteStateHashesRequest("network", "GetBlindVoteStateHashesRequest"),
|
||||
|
||||
GetDataResponse("network", "GetDataResponse"),
|
||||
GetBlocksResponse("network", "GetBlocksResponse"),
|
||||
GetDaoStateHashesResponse("network", "GetDaoStateHashesResponse"),
|
||||
GetProposalStateHashesResponse("network", "GetProposalStateHashesResponse"),
|
||||
GetBlindVoteStateHashesResponse("network", "GetBlindVoteStateHashesResponse"),
|
||||
|
||||
failedResponseClassName("network", "failedResponseClassName"),
|
||||
|
||||
usedMemoryInMB("node", "usedMemoryInMB"),
|
||||
totalMemoryInMB("node", "totalMemoryInMB"),
|
||||
jvmStartTimeInSec("node", "jvmStartTimeInSec");
|
||||
@ -69,16 +87,15 @@ public enum LongValueReportingItem implements ReportingItem {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static LongValueReportingItem from(String key, long value) {
|
||||
LongValueReportingItem item;
|
||||
public static Optional<LongValueReportingItem> from(String key, long value) {
|
||||
try {
|
||||
item = LongValueReportingItem.valueOf(key);
|
||||
LongValueReportingItem item = LongValueReportingItem.valueOf(key);
|
||||
item.setValue(value);
|
||||
return Optional.of(item);
|
||||
} catch (Throwable t) {
|
||||
item = Unspecified;
|
||||
log.warn("No enum value with {}", key);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
item.setValue(value);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -88,8 +105,8 @@ public enum LongValueReportingItem implements ReportingItem {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static LongValueReportingItem fromProto(protobuf.ReportingItem baseProto,
|
||||
protobuf.LongValueReportingItem proto) {
|
||||
public static Optional<LongValueReportingItem> fromProto(protobuf.ReportingItem baseProto,
|
||||
protobuf.LongValueReportingItem proto) {
|
||||
return LongValueReportingItem.from(baseProto.getKey(), proto.getValue());
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,8 @@ package bisq.seednode.reporting;
|
||||
import bisq.common.proto.ProtobufferRuntimeException;
|
||||
import bisq.common.proto.network.NetworkPayload;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public interface ReportingItem extends NetworkPayload {
|
||||
String getKey();
|
||||
|
||||
@ -35,7 +37,7 @@ public interface ReportingItem extends NetworkPayload {
|
||||
|
||||
protobuf.ReportingItem toProtoMessage();
|
||||
|
||||
static ReportingItem fromProto(protobuf.ReportingItem proto) {
|
||||
static Optional<? extends ReportingItem> fromProto(protobuf.ReportingItem proto) {
|
||||
switch (proto.getMessageCase()) {
|
||||
case STRING_VALUE_REPORTING_ITEM:
|
||||
return StringValueReportingItem.fromProto(proto, proto.getStringValueReportingItem());
|
||||
|
@ -23,6 +23,7 @@ import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import lombok.Getter;
|
||||
@ -50,7 +51,10 @@ public class ReportingItems extends ArrayList<ReportingItem> implements NetworkP
|
||||
public static ReportingItems fromProto(protobuf.ReportingItems proto) {
|
||||
ReportingItems reportingItems = new ReportingItems(proto.getAddress());
|
||||
reportingItems.addAll(proto.getReportingItemList().stream()
|
||||
.map(ReportingItem::fromProto).collect(Collectors.toList()));
|
||||
.map(ReportingItem::fromProto)
|
||||
.filter(Optional::isPresent)
|
||||
.map(Optional::get)
|
||||
.collect(Collectors.toList()));
|
||||
return reportingItems;
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,12 @@ import bisq.core.dao.monitoring.ProposalStateMonitoringService;
|
||||
import bisq.core.dao.monitoring.model.BlindVoteStateBlock;
|
||||
import bisq.core.dao.monitoring.model.DaoStateBlock;
|
||||
import bisq.core.dao.monitoring.model.ProposalStateBlock;
|
||||
import bisq.core.dao.monitoring.network.StateNetworkService;
|
||||
import bisq.core.dao.monitoring.network.messages.GetBlindVoteStateHashesRequest;
|
||||
import bisq.core.dao.monitoring.network.messages.GetDaoStateHashesRequest;
|
||||
import bisq.core.dao.monitoring.network.messages.GetProposalStateHashesRequest;
|
||||
import bisq.core.dao.node.full.network.FullNodeNetworkService;
|
||||
import bisq.core.dao.node.messages.GetBlocksRequest;
|
||||
import bisq.core.dao.state.DaoStateListener;
|
||||
import bisq.core.dao.state.DaoStateService;
|
||||
|
||||
@ -31,6 +37,9 @@ import bisq.network.p2p.P2PService;
|
||||
import bisq.network.p2p.network.NetworkNode;
|
||||
import bisq.network.p2p.network.Statistic;
|
||||
import bisq.network.p2p.peers.PeerManager;
|
||||
import bisq.network.p2p.peers.getdata.RequestDataManager;
|
||||
import bisq.network.p2p.peers.getdata.messages.GetUpdatedDataRequest;
|
||||
import bisq.network.p2p.peers.getdata.messages.PreliminaryGetDataRequest;
|
||||
import bisq.network.p2p.storage.P2PDataStorage;
|
||||
import bisq.network.p2p.storage.payload.ProtectedStorageEntry;
|
||||
|
||||
@ -103,6 +112,8 @@ public class SeedNodeReportingService {
|
||||
DaoStateMonitoringService daoStateMonitoringService,
|
||||
ProposalStateMonitoringService proposalStateMonitoringService,
|
||||
BlindVoteStateMonitoringService blindVoteStateMonitoringService,
|
||||
RequestDataManager requestDataManager,
|
||||
FullNodeNetworkService fullNodeNetworkService,
|
||||
@Named(Config.MAX_CONNECTIONS) int maxConnections,
|
||||
@Named(Config.SEED_NODE_REPORTING_SERVER_URL) String seedNodeReportingServerUrl) {
|
||||
this.p2PService = p2PService;
|
||||
@ -142,6 +153,106 @@ public class SeedNodeReportingService {
|
||||
}
|
||||
};
|
||||
daoFacade.addBsqStateListener(daoStateListener);
|
||||
|
||||
p2PService.getNetworkNode().addMessageListener((networkEnvelope, connection) -> {
|
||||
if (networkEnvelope instanceof PreliminaryGetDataRequest ||
|
||||
networkEnvelope instanceof GetUpdatedDataRequest ||
|
||||
networkEnvelope instanceof GetBlocksRequest ||
|
||||
networkEnvelope instanceof GetDaoStateHashesRequest ||
|
||||
networkEnvelope instanceof GetProposalStateHashesRequest ||
|
||||
networkEnvelope instanceof GetBlindVoteStateHashesRequest) {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
int serializedSize = networkEnvelope.toProtoNetworkEnvelope().getSerializedSize();
|
||||
String simpleName = networkEnvelope.getClass().getSimpleName();
|
||||
try {
|
||||
LongValueReportingItem reportingItem = LongValueReportingItem.valueOf(simpleName);
|
||||
reportingItems.add(reportingItem.withValue(serializedSize));
|
||||
sendReportingItems(reportingItems);
|
||||
} catch (Throwable t) {
|
||||
log.warn("Could not find enum for {}. Error={}", simpleName, t);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
requestDataManager.addResponseListener(new RequestDataManager.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(int serializedSize) {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetDataResponse.withValue(serializedSize));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFault() {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetDataResponse.withValue(-1));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
});
|
||||
|
||||
fullNodeNetworkService.addResponseListener(new FullNodeNetworkService.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(int serializedSize) {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetBlocksResponse.withValue(serializedSize));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFault() {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetBlocksResponse.withValue(-1));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
});
|
||||
|
||||
daoStateMonitoringService.addResponseListener(new StateNetworkService.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(int serializedSize) {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetDaoStateHashesResponse.withValue(serializedSize));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFault() {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetDaoStateHashesResponse.withValue(-1));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
});
|
||||
|
||||
proposalStateMonitoringService.addResponseListener(new StateNetworkService.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(int serializedSize) {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetProposalStateHashesResponse.withValue(serializedSize));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFault() {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetProposalStateHashesResponse.withValue(-1));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
});
|
||||
|
||||
blindVoteStateMonitoringService.addResponseListener(new StateNetworkService.ResponseListener() {
|
||||
@Override
|
||||
public void onSuccess(int serializedSize) {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetBlindVoteStateHashesResponse.withValue(serializedSize));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFault() {
|
||||
ReportingItems reportingItems = new ReportingItems(getMyAddress());
|
||||
reportingItems.add(LongValueReportingItem.GetBlindVoteStateHashesResponse.withValue(-1));
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void shutDown() {
|
||||
@ -213,7 +324,7 @@ public class SeedNodeReportingService {
|
||||
numItemsByType.putIfAbsent(className, 0);
|
||||
numItemsByType.put(className, numItemsByType.get(className) + 1);
|
||||
});
|
||||
numItemsByType.forEach((key, value) -> reportingItems.add(LongValueReportingItem.from(key, value)));
|
||||
numItemsByType.forEach((key, value) -> LongValueReportingItem.from(key, value).ifPresent(reportingItems::add));
|
||||
|
||||
// Network
|
||||
reportingItems.add(LongValueReportingItem.numConnections.withValue(networkNode.getAllConnections().size()));
|
||||
@ -233,16 +344,15 @@ public class SeedNodeReportingService {
|
||||
reportingItems.add(LongValueReportingItem.maxConnections.withValue(maxConnections));
|
||||
reportingItems.add(StringValueReportingItem.version.withValue(Version.VERSION));
|
||||
|
||||
// If no commit hash is found we use 0 in hex format
|
||||
String commitHash = Version.findCommitHash().orElse("00");
|
||||
reportingItems.add(StringValueReportingItem.commitHash.withValue(commitHash));
|
||||
Version.findCommitHash().ifPresent(commitHash -> reportingItems.add(StringValueReportingItem.commitHash.withValue(commitHash)));
|
||||
|
||||
sendReportingItems(reportingItems);
|
||||
}
|
||||
|
||||
private void sendReportingItems(ReportingItems reportingItems) {
|
||||
String truncated = Utilities.toTruncatedString(reportingItems.toString());
|
||||
try {
|
||||
log.info("Send report to monitor server: {}", reportingItems.toString());
|
||||
log.info("Going to send report to monitor server: {}", truncated);
|
||||
// We send the data as hex encoded protobuf data. We do not use the envelope as it is not part of the p2p system.
|
||||
byte[] protoMessageAsBytes = reportingItems.toProtoMessageAsBytes();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
@ -253,14 +363,16 @@ public class SeedNodeReportingService {
|
||||
httpClient.sendAsync(request, HttpResponse.BodyHandlers.ofString()).whenComplete((response, throwable) -> {
|
||||
if (throwable != null) {
|
||||
log.warn("Exception at sending reporting data. {}", throwable.getMessage());
|
||||
} else if (response.statusCode() != 200) {
|
||||
log.error("Response error message: {}", response);
|
||||
} else if (response.statusCode() == 200) {
|
||||
log.info("Sent successfully report to monitor server with {} items", reportingItems.size());
|
||||
} else {
|
||||
log.warn("Server responded with error. Response={}", response);
|
||||
}
|
||||
});
|
||||
} catch (RejectedExecutionException t) {
|
||||
log.warn("Did not send reportingItems {} because of RejectedExecutionException {}", reportingItems, t.toString());
|
||||
log.warn("Did not send reportingItems {} because of RejectedExecutionException {}", truncated, t.toString());
|
||||
} catch (Throwable t) {
|
||||
log.warn("Did not send reportingItems {} because of exception {}", reportingItems, t.toString());
|
||||
log.warn("Did not send reportingItems {} because of exception {}", truncated, t.toString());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,13 +17,14 @@
|
||||
|
||||
package bisq.seednode.reporting;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
|
||||
@Slf4j
|
||||
public enum StringValueReportingItem implements ReportingItem {
|
||||
Unspecified("", "Unspecified"),
|
||||
|
||||
daoStateHash("dao", "daoStateHash"),
|
||||
proposalHash("dao", "proposalHash"),
|
||||
blindVoteHash("dao", "blindVoteHash"),
|
||||
@ -49,16 +50,15 @@ public enum StringValueReportingItem implements ReportingItem {
|
||||
return this;
|
||||
}
|
||||
|
||||
public static StringValueReportingItem from(String key, String value) {
|
||||
StringValueReportingItem item;
|
||||
public static Optional<StringValueReportingItem> from(String key, String value) {
|
||||
try {
|
||||
item = StringValueReportingItem.valueOf(key);
|
||||
StringValueReportingItem item = StringValueReportingItem.valueOf(key);
|
||||
item.setValue(value);
|
||||
return Optional.of(item);
|
||||
} catch (Throwable t) {
|
||||
item = Unspecified;
|
||||
log.warn("No enum value with {}", key);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
item.setValue(value);
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -73,8 +73,8 @@ public enum StringValueReportingItem implements ReportingItem {
|
||||
.build();
|
||||
}
|
||||
|
||||
public static StringValueReportingItem fromProto(protobuf.ReportingItem baseProto,
|
||||
protobuf.StringValueReportingItem proto) {
|
||||
public static Optional<StringValueReportingItem> fromProto(protobuf.ReportingItem baseProto,
|
||||
protobuf.StringValueReportingItem proto) {
|
||||
return StringValueReportingItem.from(baseProto.getKey(), proto.getValue());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user