Skip to content

Commit

Permalink
Address comments on PR.
Browse files Browse the repository at this point in the history
Signed-off-by: Rishikesh1159 <[email protected]>
  • Loading branch information
Rishikesh1159 committed Oct 20, 2023
1 parent 5449d36 commit 5765b25
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@ public SegmentReplicationStatsTracker(IndicesService indicesService) {
rejectionCount = ConcurrentCollections.newConcurrentMap();
}

public SegmentReplicationRejectionStats getRejectionStats() {
long rejectionCount = 0;
for (IndexService indexService : indicesService) {
if (indexService.getIndexSettings().isSegRepEnabled()) {
for (IndexShard indexShard : indexService) {
if (indexShard.indexSettings().isSegRepEnabled() && indexShard.routingEntry().primary()) {
rejectionCount += getStatsForShard(indexShard).getRejectedRequestCount();
}
}
}
}
return new SegmentReplicationRejectionStats(rejectionCount);
public SegmentReplicationRejectionStats getTotalRejectionStats() {
return new SegmentReplicationRejectionStats(this.rejectionCount.values().stream().mapToInt(AtomicInteger::get).sum());
}

protected Map<ShardId, AtomicInteger> getRejectionCount() {
return rejectionCount;
}

public SegmentReplicationStats getStats() {
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/java/org/opensearch/node/NodeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public NodeStats stats(
fileCacheStats && fileCache != null ? fileCache.fileCacheStats() : null,
taskCancellation ? this.taskCancellationMonitoringService.stats() : null,
searchPipelineStats ? this.searchPipelineService.stats() : null,
segmentReplicationTrackerStats ? this.segmentReplicationStatsTracker.getRejectionStats() : null,
segmentReplicationTrackerStats ? this.segmentReplicationStatsTracker.getTotalRejectionStats() : null,
repositoriesStats ? this.repositoriesService.getRepositoriesStats() : null
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

package org.opensearch.index;

import org.opensearch.indices.IndicesService;
import org.opensearch.test.OpenSearchTestCase;

import static org.mockito.Mockito.mock;

public class SegmentReplicationStatsTrackerTests extends OpenSearchTestCase {

private IndicesService indicesService = mock(IndicesService.class);

public void testRejectedCountWhenEmpty() {
SegmentReplicationStatsTracker segmentReplicationStatsTracker = new SegmentReplicationStatsTracker(indicesService);

// Verify that total rejection count is 0 on an empty rejectionCount map in statsTracker.
assertTrue(segmentReplicationStatsTracker.getRejectionCount().isEmpty());
assertEquals(segmentReplicationStatsTracker.getTotalRejectionStats().getTotalRejectionCount(), 0L);
}

}

0 comments on commit 5765b25

Please sign in to comment.