Skip to content

Commit

Permalink
Add statsName field on stream while constructing PersistedStateStats (o…
Browse files Browse the repository at this point in the history
…pensearch-project#10964) (opensearch-project#10976)

(cherry picked from commit f372cbf)

Signed-off-by: Aman Khare <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Aman Khare <[email protected]>
  • Loading branch information
3 people authored Oct 28, 2023
1 parent 50642fa commit 0f7649f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,31 @@ public void testRemoteStateStats() {
.addMetric(NodesStatsRequest.Metric.DISCOVERY.metricName())
.get();

// assert cluster state stats
assertClusterManagerClusterStateStats(nodesStatsResponse);

NodesStatsResponse nodesStatsResponseDataNode = client().admin()
.cluster()
.prepareNodesStats(dataNode)
.addMetric(NodesStatsRequest.Metric.DISCOVERY.metricName())
.get();
// assert cluster state stats for data node
DiscoveryStats dataNodeDiscoveryStats = nodesStatsResponseDataNode.getNodes().get(0).getDiscoveryStats();
assertNotNull(dataNodeDiscoveryStats.getClusterStateStats());
assertEquals(0, dataNodeDiscoveryStats.getClusterStateStats().getUpdateSuccess());

// call nodes/stats with nodeId filter
NodesStatsResponse nodesStatsNodeIdFilterResponse = client().admin()
.cluster()
.prepareNodesStats(dataNode)
.addMetric(NodesStatsRequest.Metric.DISCOVERY.metricName())
.setNodesIds(clusterManagerNode)
.get();

assertClusterManagerClusterStateStats(nodesStatsNodeIdFilterResponse);
}

private void assertClusterManagerClusterStateStats(NodesStatsResponse nodesStatsResponse) {
// assert cluster state stats
DiscoveryStats discoveryStats = nodesStatsResponse.getNodes().get(0).getDiscoveryStats();

Expand All @@ -125,16 +150,43 @@ public void testRemoteStateStats() {
assertTrue(discoveryStats.getClusterStateStats().getPersistenceStats().get(0).getSuccessCount() > 1);
assertEquals(0, discoveryStats.getClusterStateStats().getPersistenceStats().get(0).getFailedCount());
assertTrue(discoveryStats.getClusterStateStats().getPersistenceStats().get(0).getTotalTimeInMillis() > 0);
}

NodesStatsResponse nodesStatsResponseDataNode = client().admin()
.cluster()
.prepareNodesStats(dataNode)
.addMetric(NodesStatsRequest.Metric.DISCOVERY.metricName())
.get();
// assert cluster state stats for data node
DiscoveryStats dataNodeDiscoveryStats = nodesStatsResponseDataNode.getNodes().get(0).getDiscoveryStats();
assertNotNull(dataNodeDiscoveryStats.getClusterStateStats());
assertEquals(0, dataNodeDiscoveryStats.getClusterStateStats().getUpdateSuccess());
public void testRemoteStateStatsFromAllNodes() {
int shardCount = randomIntBetween(1, 5);
int replicaCount = 1;
int dataNodeCount = shardCount * (replicaCount + 1);
int clusterManagerNodeCount = 3;
prepareCluster(clusterManagerNodeCount, dataNodeCount, INDEX_NAME, replicaCount, shardCount);
String[] allNodes = internalCluster().getNodeNames();
// call _nodes/stats/discovery from all the nodes
for (String node : allNodes) {
NodesStatsResponse nodesStatsResponse = client().admin()
.cluster()
.prepareNodesStats(node)
.addMetric(NodesStatsRequest.Metric.DISCOVERY.metricName())
.get();
validateNodesStatsResponse(nodesStatsResponse);
}

// call _nodes/stats/discovery from all the nodes with random nodeId filter
for (String node : allNodes) {
NodesStatsResponse nodesStatsResponse = client().admin()
.cluster()
.prepareNodesStats(node)
.addMetric(NodesStatsRequest.Metric.DISCOVERY.metricName())
.setNodesIds(allNodes[randomIntBetween(0, allNodes.length - 1)])
.get();
validateNodesStatsResponse(nodesStatsResponse);
}
}

private void validateNodesStatsResponse(NodesStatsResponse nodesStatsResponse) {
// _nodes/stats/discovery must never fail due to any exception
assertFalse(nodesStatsResponse.toString().contains("exception"));
assertNotNull(nodesStatsResponse.getNodes());
assertNotNull(nodesStatsResponse.getNodes().get(0));
assertNotNull(nodesStatsResponse.getNodes().get(0).getDiscoveryStats());
}

private void setReplicaCount(int replicaCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @opensearch.internal
*/
public class PersistedStateStats implements Writeable, ToXContentObject {
private String statsName;
private final String statsName;
private AtomicLong totalTimeInMillis = new AtomicLong(0);
private AtomicLong failedCount = new AtomicLong(0);
private AtomicLong successCount = new AtomicLong(0);
Expand All @@ -37,6 +37,7 @@ public PersistedStateStats(String statsName) {

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeString(statsName);
out.writeVLong(successCount.get());
out.writeVLong(failedCount.get());
out.writeVLong(totalTimeInMillis.get());
Expand All @@ -53,6 +54,7 @@ public void writeTo(StreamOutput out) throws IOException {
}

public PersistedStateStats(StreamInput in) throws IOException {
this.statsName = in.readString();
this.successCount = new AtomicLong(in.readVLong());
this.failedCount = new AtomicLong(in.readVLong());
this.totalTimeInMillis = new AtomicLong(in.readVLong());
Expand Down Expand Up @@ -113,6 +115,10 @@ protected void addToExtendedFields(String extendedField, AtomicLong extendedFiel
this.extendedFields.put(extendedField, extendedFieldValue);
}

public String getStatsName() {
return statsName;
}

/**
* Fields for parsing and toXContent
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ public void testSerialization() throws IOException {
.getPersistenceStats()
.get(0);
PersistedStateStats remoteStateStats = stateStats.getPersistenceStats().get(0);
assertEquals(remoteStateStats.getStatsName(), deserializedRemoteStateStats.getStatsName());
assertEquals(remoteStateStats.getFailedCount(), deserializedRemoteStateStats.getFailedCount());
assertEquals(remoteStateStats.getSuccessCount(), deserializedRemoteStateStats.getSuccessCount());
assertEquals(remoteStateStats.getTotalTimeInMillis(), deserializedRemoteStateStats.getTotalTimeInMillis());
Expand Down

0 comments on commit 0f7649f

Please sign in to comment.