Skip to content

Commit

Permalink
NMS-15853: Improve logging for node lookups in BMP message processing.
Browse files Browse the repository at this point in the history
  • Loading branch information
j-white authored Aug 1, 2023
1 parent 8d85377 commit 76f2288
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,27 @@ public void handleMessage(final TelemetryMessageLogEntry messageLogEntry,
Optional<Integer> exporterNodeId = this.interfaceToNodeCache.getFirstNodeId(messageLog.getLocation(), exporterAddress);

if (!exporterNodeId.isPresent()) {
LOG.info("Unable to find node for exporter address: {}", exporterAddress);

if (message.hasBgpId()) {
final String bgpId = InetAddressUtils.toIpAddrString(address(message.getBgpId()));
LOG.info("Unable to find node for exporter address: {} at location: {}. Trying to lookup by bgpId: {}",
exporterAddress, messageLog.getLocation(), bgpId);
final List<OnmsNode> nodes = nodeDao.findNodeWithMetaData(contextKey.getContext(), contextKey.getKey(), bgpId);

if (nodes.size() > 0) {
Integer effectiveId = nodes.get(0).getId();

if (nodes.size() > 1) {
LOG.warn("More that one node match bgpId: {}", bgpId);
LOG.warn("More that one node match bgpId: {}. Using the first: {}", bgpId, effectiveId);
}

exporterNodeId = Optional.of(nodes.get(0).getId());
exporterNodeId = Optional.of(effectiveId);
} else {
LOG.warn("Unable to find node for bgpId: {}", bgpId);
LOG.warn("Unable to find node for bgpId: {}. Message will be ignored.", bgpId);
return;
}
} else {
LOG.info("Unable to find node for exporter address: {} at location: {}. Message has no bgpId. Message will be ignored.",
exporterAddress, messageLog.getLocation());
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,29 @@ public Stream<CollectionSetWithAgent> handleCollectionMessage(final TelemetryMes
Optional<Integer> exporterNodeId = this.interfaceToNodeCache.getFirstNodeId(messageLog.getLocation(), exporterAddress);

if (!exporterNodeId.isPresent()) {
LOG.warn("Unable to find node for exporter address: {}", exporterAddress);

if (message.hasBgpId()) {
final InetAddress bgpId = address(message.getBgpId());
LOG.info("Unable to find node for exporter address: {} at location: {}. Trying to lookup by bgpId: {}",
exporterAddress, messageLog.getLocation(), bgpId);

final ExporterInfo exporterInfo = transactionTemplate.execute(new TransactionCallback<ExporterInfo>() {
@Override
public ExporterInfo doInTransaction(final TransactionStatus transactionStatus) {
final List<OnmsNode> nodes = nodeDao.findNodeWithMetaData(contextKey.getContext(), contextKey.getKey(), InetAddressUtils.toIpAddrString(bgpId));

if (!nodes.isEmpty()) {
final OnmsNode firstNode = nodes.get(0);
if (nodes.size() > 1) {
LOG.warn("More that one node match bgpId: {}", bgpId);
LOG.warn("More that one node match bgpId: {}. Using the first: {}", bgpId, firstNode.getId());
}
final OnmsNode firstNode = nodes.get(0);

if (firstNode.containsInterface(bgpId)) {
return new ExporterInfo(firstNode.getId(), bgpId);
} else {
return new ExporterInfo(firstNode.getId(), firstNode.getPrimaryInterface().getIpAddress());
}

} else {
LOG.warn("Unable to find node for bgpId: {}", bgpId);
LOG.warn("Unable to find node for bgpId: {}. Message will be ignored.", bgpId);
return null;
}
}
Expand All @@ -159,6 +158,8 @@ public ExporterInfo doInTransaction(final TransactionStatus transactionStatus) {
exporterAddress = exporterInfo.nodeAddress;

} else {
LOG.info("Unable to find node for exporter address: {} at location: {}. Message has no bgpId. Message will be ignored.",
exporterAddress, messageLog.getLocation());
return Stream.empty();
}
}
Expand Down

0 comments on commit 76f2288

Please sign in to comment.