Skip to content

Commit ad95bff

Browse files
committed
added integration tests
Signed-off-by: Anthony Leong <aj.leong623@gmail.com>
1 parent ae2c661 commit ad95bff

File tree

3 files changed

+119
-9
lines changed

3 files changed

+119
-9
lines changed

server/src/internalClusterTest/java/org/opensearch/nodestats/NodeStatsIT.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.opensearch.action.admin.cluster.node.stats.NodeStats;
1414
import org.opensearch.action.admin.cluster.node.stats.NodesStatsResponse;
1515
import org.opensearch.action.admin.indices.stats.CommonStatsFlags;
16+
import org.opensearch.action.admin.indices.stats.DocStatusStats;
1617
import org.opensearch.action.bulk.BulkItemResponse;
1718
import org.opensearch.action.bulk.BulkRequest;
1819
import org.opensearch.action.bulk.BulkResponse;
@@ -32,7 +33,6 @@
3233
import org.opensearch.index.IndexNotFoundException;
3334
import org.opensearch.index.engine.DocumentMissingException;
3435
import org.opensearch.index.engine.VersionConflictEngineException;
35-
import org.opensearch.index.shard.IndexingStats.Stats.DocStatusStats;
3636
import org.opensearch.indices.NodeIndicesStats;
3737
import org.opensearch.test.OpenSearchIntegTestCase;
3838
import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope;
@@ -47,7 +47,7 @@
4747
import java.util.LinkedHashMap;
4848
import java.util.List;
4949
import java.util.Map;
50-
import java.util.concurrent.atomic.AtomicLong;
50+
import java.util.concurrent.atomic.LongAdder;
5151

5252
import static java.util.Collections.singletonMap;
5353
import static org.opensearch.test.hamcrest.OpenSearchAssertions.assertAcked;
@@ -281,15 +281,14 @@ public void testNodeIndicesStatsDocStatsWithAggregations() {
281281
.getNodes()
282282
.get(0)
283283
.getIndices()
284-
.getIndexing()
285-
.getTotal()
284+
.getStatusCounterStats()
286285
.getDocStatusStats();
287286

288287
assertTrue(
289288
Arrays.equals(
290289
docStatusStats.getDocStatusCounter(),
291290
expectedDocStatusStats.getDocStatusCounter(),
292-
Comparator.comparingLong(AtomicLong::longValue)
291+
Comparator.comparingLong(LongAdder::longValue)
293292
)
294293
);
295294
}
@@ -543,15 +542,14 @@ private void assertDocStatusStats() {
543542
.getNodes()
544543
.get(0)
545544
.getIndices()
546-
.getIndexing()
547-
.getTotal()
545+
.getStatusCounterStats()
548546
.getDocStatusStats();
549547

550548
assertTrue(
551549
Arrays.equals(
552550
docStatusStats.getDocStatusCounter(),
553551
expectedDocStatusStats.getDocStatusCounter(),
554-
Comparator.comparingLong(AtomicLong::longValue)
552+
Comparator.comparingLong(LongAdder::longValue)
555553
)
556554
);
557555
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
/*
10+
* Licensed to Elasticsearch under one or more contributor
11+
* license agreements. See the NOTICE file distributed with
12+
* this work for additional information regarding copyright
13+
* ownership. Elasticsearch licenses this file to you under
14+
* the Apache License, Version 2.0 (the "License"); you may
15+
* not use this file except in compliance with the License.
16+
* You may obtain a copy of the License at
17+
*
18+
* http://www.apache.org/licenses/LICENSE-2.0
19+
*
20+
* Unless required by applicable law or agreed to in writing,
21+
* software distributed under the License is distributed on an
22+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23+
* KIND, either express or implied. See the License for the
24+
* specific language governing permissions and limitations
25+
* under the License.
26+
*/
27+
28+
/*
29+
* Modifications Copyright OpenSearch Contributors. See
30+
* GitHub history for details.
31+
*/
32+
33+
package org.opensearch.search.msearch;
34+
35+
import org.opensearch.ExceptionsHelper;
36+
import org.opensearch.action.admin.indices.stats.SearchResponseStatusStats;
37+
import org.opensearch.action.search.MultiSearchRequestBuilder;
38+
import org.opensearch.action.search.MultiSearchResponse;
39+
import org.opensearch.action.search.SearchResponse;
40+
import org.opensearch.index.query.QueryBuilders;
41+
import org.opensearch.test.OpenSearchIntegTestCase;
42+
import org.opensearch.test.OpenSearchIntegTestCase.ClusterScope;
43+
import org.opensearch.test.OpenSearchIntegTestCase.Scope;
44+
45+
import java.util.Arrays;
46+
import java.util.Comparator;
47+
import java.util.concurrent.atomic.LongAdder;
48+
49+
@ClusterScope(scope = Scope.TEST, numDataNodes = 1, numClientNodes = 0, supportsDedicatedMasters = false)
50+
public class MultiSearchStatsIT extends OpenSearchIntegTestCase {
51+
private final SearchResponseStatusStats expectedSearchResponseStatusStats = new SearchResponseStatusStats();
52+
53+
public void testNodeIndicesStatsDocStatusStatsIndexBulk() {
54+
createIndex("test");
55+
ensureGreen();
56+
client().prepareIndex("test").setId("1").setSource("field", "xxx").get();
57+
client().prepareIndex("test").setId("2").setSource("field", "yyy").get();
58+
refresh();
59+
60+
int failureCount = randomIntBetween(0, 50);
61+
int successCount = randomIntBetween(0, 50);
62+
63+
MultiSearchRequestBuilder multiSearchRequestBuilder = client().prepareMultiSearch();
64+
65+
for (int i = 0; i < failureCount; i++) {
66+
multiSearchRequestBuilder.add(client().prepareSearch("noIndex").setQuery(QueryBuilders.termQuery("field", "yyy")));
67+
}
68+
69+
for (int i = 0; i < successCount; i++) {
70+
multiSearchRequestBuilder.add(client().prepareSearch("test").setQuery(QueryBuilders.matchAllQuery()));
71+
}
72+
73+
MultiSearchResponse response = multiSearchRequestBuilder.get();
74+
75+
for (MultiSearchResponse.Item item : response) {
76+
if (item.isFailure()) {
77+
updateExpectedDocStatusCounter(expectedSearchResponseStatusStats, item.getFailure());
78+
} else {
79+
updateExpectedDocStatusCounter(expectedSearchResponseStatusStats, item.getResponse());
80+
}
81+
}
82+
assertSearchResponseStatusStats();
83+
}
84+
85+
private void assertSearchResponseStatusStats() {
86+
SearchResponseStatusStats searchResponseStatusStats = client().admin()
87+
.cluster()
88+
.prepareNodesStats()
89+
.execute()
90+
.actionGet()
91+
.getNodes()
92+
.get(0)
93+
.getIndices()
94+
.getStatusCounterStats()
95+
.getSearchResponseStatusStats();
96+
97+
Arrays.equals(
98+
searchResponseStatusStats.getSearchResponseStatusCounter(),
99+
expectedSearchResponseStatusStats.getSearchResponseStatusCounter(),
100+
Comparator.comparingLong(LongAdder::longValue)
101+
);
102+
}
103+
104+
private void updateExpectedDocStatusCounter(SearchResponseStatusStats expectedSearchResponseStatusStats, SearchResponse r) {
105+
expectedSearchResponseStatusStats.inc(r.status());
106+
}
107+
108+
private void updateExpectedDocStatusCounter(SearchResponseStatusStats expectedSearchResponseStatusStats, Exception e) {
109+
expectedSearchResponseStatusStats.inc(ExceptionsHelper.status(e));
110+
}
111+
}

server/src/main/java/org/opensearch/indices/IndicesService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1367,9 +1367,10 @@ public IndicesQueryCache getIndicesQueryCache() {
13671367
*
13681368
* @param stats Instance storing {@link DocStatusStats}
13691369
*/
1370+
/*@Deprecated(since = "3.3.0")
13701371
public void addDocStatusStats(final org.opensearch.index.shard.IndexingStats.Stats.DocStatusStats stats) {
13711372
oldShardsStats.indexingStats.getTotal().getDocStatusStats().add(stats);
1372-
}
1373+
}*/
13731374

13741375
/**
13751376
* Accumulate stats from the passed Object

0 commit comments

Comments
 (0)