Skip to content

Commit

Permalink
Merge branch '2.x' into backport-16201-to-2.x
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Widdis <[email protected]>
  • Loading branch information
dbwiddis authored Oct 22, 2024
2 parents d3a5070 + 0f110e8 commit 329df39
Show file tree
Hide file tree
Showing 16 changed files with 1,499 additions and 123 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Add method to return dynamic SecureTransportParameters from SecureTransportSettingsProvider interface ([#16387](https://github.com/opensearch-project/OpenSearch/pull/16387)
- Add _list/shards API as paginated alternate to _cat/shards ([#14641](https://github.com/opensearch-project/OpenSearch/pull/14641))
- [Star Tree - Search] Add support for metric aggregations with/without term query ([15289](https://github.com/opensearch-project/OpenSearch/pull/15289))
- URI path filtering support in cluster stats API ([#15938](https://github.com/opensearch-project/OpenSearch/pull/15938))


### Dependencies
- Bump `org.apache.logging.log4j:log4j-core` from 2.23.1 to 2.24.0 ([#15858](https://github.com/opensearch-project/OpenSearch/pull/15858))
Expand Down Expand Up @@ -86,8 +88,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix multi-search with template doesn't return status code ([#16265](https://github.com/opensearch-project/OpenSearch/pull/16265))
- [Streaming Indexing] Fix intermittent 'The bulk request must be terminated by a newline [\n]' failures [#16337](https://github.com/opensearch-project/OpenSearch/pull/16337))
- Fix wrong default value when setting `index.number_of_routing_shards` to null on index creation ([#16331](https://github.com/opensearch-project/OpenSearch/pull/16331))
- Fix inefficient Stream API call chains ending with count() ([#15386](https://github.com/opensearch-project/OpenSearch/pull/15386))
- [Workload Management] Make query groups persistent across process restarts [#16370](https://github.com/opensearch-project/OpenSearch/pull/16370)
- Fix missing fields in task index mapping to ensure proper task result storage ([#16201](https://github.com/opensearch-project/OpenSearch/pull/16201))
- Fix typo super->sb in method toString() of RemoteStoreNodeAttribute ([#15362](https://github.com/opensearch-project/OpenSearch/pull/15362))
- Fix array hashCode calculation in ResyncReplicationRequest ([#16378](https://github.com/opensearch-project/OpenSearch/pull/16378))

### Security
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,19 +510,25 @@ static Result selectBestResult(Result result1, Result result2) {
}

private static int minTermLength(Set<QueryExtraction> extractions) {
// In case there are only range extractions, then we return Integer.MIN_VALUE,
// so that selectBestExtraction(...) we are likely to prefer the extractions that contains at least a single extraction
if (extractions.stream().filter(queryExtraction -> queryExtraction.term != null).count() == 0
&& extractions.stream().filter(queryExtraction -> queryExtraction.range != null).count() > 0) {
return Integer.MIN_VALUE;
}

boolean hasTerm = false;
boolean hasRange = false;
int min = Integer.MAX_VALUE;

for (QueryExtraction qt : extractions) {
if (qt.term != null) {
hasTerm = true;
min = Math.min(min, qt.bytes().length);
}
if (qt.range != null) {
hasRange = true;
}
}

// If there are no terms but there are ranges, return Integer.MIN_VALUE
if (!hasTerm && hasRange) {
return Integer.MIN_VALUE;
}

return min;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.upgrades;

import org.opensearch.Version;
import org.opensearch.client.Request;
import org.opensearch.client.Response;

import java.io.IOException;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public class ClusterStatsIT extends AbstractRollingTestCase {

private final List<String> nodeStatsMetrics = List.of("os", "process", "jvm", "fs", "plugins", "ingest", "network_types", "discovery_types", "packaging_types");

private final List<String> indicesStatsMetrics = List.of("shards", "docs", "store", "fielddata", "query_cache", "completion", "segments", "analysis", "mappings");

public void testClusterStats() throws IOException {
Response response = client().performRequest(new Request("GET", "/_cluster/stats"));
validateClusterStatsWithFilterResponse(response, nodeStatsMetrics, indicesStatsMetrics);
if (AbstractRollingTestCase.UPGRADE_FROM_VERSION.onOrAfter(Version.V_2_18_0) || (
CLUSTER_TYPE == ClusterType.UPGRADED && Version.CURRENT.onOrAfter(Version.V_2_18_0))) {
response = client().performRequest(new Request("GET", "/_cluster/stats/os/nodes/_all"));
validateClusterStatsWithFilterResponse(response, List.of("os"), Collections.emptyList());
response = client().performRequest(new Request("GET", "/_cluster/stats/indices/mappings/nodes/_all"));
validateClusterStatsWithFilterResponse(response, Collections.emptyList(), List.of("mappings"));
response = client().performRequest(new Request("GET", "/_cluster/stats/os,indices/mappings/nodes/_all"));
validateClusterStatsWithFilterResponse(response, List.of("os"), List.of("mappings"));
}
}

private void validateClusterStatsWithFilterResponse(Response response, List<String> requestedNodesStatsMetrics, List<String> requestedIndicesStatsMetrics) throws IOException {
assertEquals(200, response.getStatusLine().getStatusCode());
Map<String, Object> entity = entityAsMap(response);
if (requestedNodesStatsMetrics != null && !requestedNodesStatsMetrics.isEmpty()) {
assertTrue(entity.containsKey("nodes"));
Map<?, ?> nodesStats = (Map<?, ?>) entity.get("nodes");
for (String metric : nodeStatsMetrics) {
if (requestedNodesStatsMetrics.contains(metric)) {
assertTrue(nodesStats.containsKey(metric));
} else {
assertFalse(nodesStats.containsKey(metric));
}
}
}

if (requestedIndicesStatsMetrics != null && !requestedIndicesStatsMetrics.isEmpty()) {
assertTrue(entity.containsKey("indices"));
Map<?, ?> indicesStats = (Map<?, ?>) entity.get("indices");
for (String metric : indicesStatsMetrics) {
if (requestedIndicesStatsMetrics.contains(metric)) {
assertTrue(indicesStats.containsKey(metric));
} else {
assertFalse(indicesStats.containsKey(metric));
}
}
}
}
}
Loading

0 comments on commit 329df39

Please sign in to comment.