Skip to content

Commit

Permalink
Merge pull request #137 from symbol/dev
Browse files Browse the repository at this point in the history
Releasing v1.1.5
  • Loading branch information
yilmazbahadir authored Jan 24, 2022
2 parents ace929e + d546410 commit c424a9f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ All notable changes to this project will be documented in this file.

The changelog format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [v1.1.5][v1.1.5] - 24-Jan-2022

Package | Version | Link
---|---|---
REST Core| v2.4.0 | [catapult-rest][[email protected]]
SDK Core| v1.0.3 | [symbol-sdk][[email protected]]

### Fix
- Fixed duplicate nodes and nodes from the wrong networks removal issue [#134](https://github.com/symbol/statistics-service/pull/134)

## [v1.1.4][v1.1.4] - 18-Jan-2022

Package | Version | Link
Expand Down Expand Up @@ -155,6 +165,7 @@ REST Core| v2.1.0 | [catapult-rest](https://github.com/nemtech/catapult-rest/rel
### Fixes
- Cors error. [#13](https://github.com/nemgrouplimited/symbol-statistics-service/issues/13)

[v1.1.5]: https://github.com/symbol/statistics-service/releases/tag/v1.1.5
[v1.1.4]: https://github.com/symbol/statistics-service/releases/tag/v1.1.4
[v1.1.3]: https://github.com/symbol/statistics-service/releases/tag/v1.1.3
[v1.1.2]: https://github.com/symbol/statistics-service/releases/tag/v1.1.2
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 23 additions & 10 deletions src/services/NodeMonitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export class NodeMonitor {
private nodesStats: NodesStats;
private nodeCountTimeSeriesService: TimeSeriesService<AbstractTimeSeries, AbstractTimeSeriesDocument>;
private nodeList: INode[];
private nodeInfoList: INode[];
private isRunning: boolean;
private interval: number;
private nodeInfoChunks: number;
private nodePeersChunkSize: number;
private nodeInfoDelay: number;
private networkIdentifier: number;
private generationHashSeed: string;

Expand All @@ -39,11 +39,11 @@ export class NodeMonitor {
NodeCountSeries,
);
this.nodeList = [];
this.nodeInfoList = [];
this.isRunning = false;
this.interval = _interval || 300000;
this.nodeInfoChunks = monitor.NUMBER_OF_NODE_REQUEST_CHUNK;
this.nodePeersChunkSize = monitor.NODE_PEERS_REQUEST_CHUNK_SIZE;
this.nodeInfoDelay = 1000;
this.networkIdentifier = 0;
this.generationHashSeed = '';

Expand Down Expand Up @@ -170,19 +170,19 @@ export class NodeMonitor {
const nodeInfoPromises = [...nodes].map((node) => this.getNodeInfo(node));
const arrayOfNodeInfo = await Promise.all(nodeInfoPromises);

this.addNodesToList(arrayOfNodeInfo);
this.addNodesToNodeInfoList(arrayOfNodeInfo.filter((node) => !!node) as INode[]);
return arrayOfNodeInfo;
});

this.nodeList.forEach((node) => this.nodesStats.addToStats(node));
this.nodeInfoList.forEach((node) => this.nodesStats.addToStats(node));
logger.info(
`[getNodeListInfo] Total node count(after nodeInfo): ${this.nodeList.length}, time elapsed: [${showDuration(
`[getNodeListInfo] Total node count(after nodeInfo): ${this.nodeInfoList.length}, time elapsed: [${showDuration(
startTime - new Date().getTime(),
)}]`,
);
};

private async getNodeInfo(node: INode): Promise<INode> {
private async getNodeInfo(node: INode): Promise<INode | undefined> {
let nodeWithInfo: INode = { ...node };
const nodeHost = node.host;

Expand All @@ -204,6 +204,14 @@ export class NodeMonitor {
const nodeStatus = await ApiNodeService.getNodeInfo(hostUrl);

if (nodeStatus) {
// if the values we got are different than the node/info then remove the node from the list
if (
nodeStatus.publicKey !== node.publicKey ||
nodeStatus.networkIdentifier !== this.networkIdentifier ||
nodeStatus.networkGenerationHashSeed !== this.generationHashSeed
) {
return undefined;
}
Object.assign(nodeWithInfo, nodeStatus);
if (!nodeWithInfo.host) {
nodeWithInfo.host = nodeHost;
Expand All @@ -228,6 +236,7 @@ export class NodeMonitor {
private clear = () => {
logger.info(`Clear`);
this.nodeList = [];
this.nodeInfoList = [];
this.nodesStats.clear();
};

Expand All @@ -239,19 +248,19 @@ export class NodeMonitor {
total: this.nodesStats.getTotal(),
},
});
if (this.nodeList.length > 0) {
if (this.nodeInfoList.length > 0) {
logger.info(`Update collection`);
const prevNodeList = await DataBase.getNodeList();

this.nodeList = this.removeStaleNodesAndUpdateLastAvailable(this.nodeList);
this.nodeInfoList = this.removeStaleNodesAndUpdateLastAvailable(this.nodeInfoList);
try {
await DataBase.updateNodeList(this.nodeList);
await DataBase.updateNodeList(this.nodeInfoList);
await DataBase.updateNodesStats(this.nodesStats);
} catch (e) {
logger.error(`Failed to update collection. ${e.message}`);
await DataBase.updateNodeList(prevNodeList);
}
} else logger.error(`Failed to update collection. Collection length = ${this.nodeList.length}`);
} else logger.error(`Failed to update collection. Collection length = ${this.nodeInfoList.length}`);
};

private removeStaleNodesAndUpdateLastAvailable(nodes: INode[]): INode[] {
Expand Down Expand Up @@ -351,4 +360,8 @@ export class NodeMonitor {
}
});
};

private addNodesToNodeInfoList = (nodes: INode[]) => {
this.nodeInfoList = this.nodeInfoList.concat(nodes);
};
}

0 comments on commit c424a9f

Please sign in to comment.