Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into search_pit_resolved…
Browse files Browse the repository at this point in the history
…_indices
  • Loading branch information
jimczi committed Dec 12, 2023
2 parents 095c702 + df19514 commit cd229ef
Show file tree
Hide file tree
Showing 160 changed files with 973 additions and 1,147 deletions.
1 change: 1 addition & 0 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ testClusters.matching { it.name == "yamlRestTest"}.configureEach {
systemProperty 'es.transport.cname_in_publish_address', 'true'

requiresFeature 'es.index_mode_feature_flag_registered', Version.fromString("8.0.0")
requiresFeature 'es.failure_store_feature_flag_enabled', Version.fromString("8.12.0")

extraConfigFile 'op-jwks.json', project(':x-pack:test:idp-fixture').file("oidc/op-jwks.json")
extraConfigFile 'idp-docs-metadata.xml', project(':x-pack:test:idp-fixture').file("idp/shibboleth-idp/metadata/idp-docs-metadata.xml")
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog/102078.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 102078
summary: Derive expected replica size from primary
area: Allocation
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/103035.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 103035
summary: "x-pack/plugin/core: add `match_mapping_type` to `ecs@mappings` dynamic templates"
area: Data streams
type: bug
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/103176.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 103176
summary: Validate settings in `ReloadSecureSettings` API
area: Client
type: bug
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/103251.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 103251
summary: Wait for reroute before acking put-shutdown
area: Infra/Node Lifecycle
type: bug
issues: []
3 changes: 2 additions & 1 deletion docs/reference/rest-api/common-parms.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -611,9 +611,10 @@ The `similarity` parameter is the direct vector similarity calculation.

* `l2_norm`: also known as Euclidean, will include documents where the vector is within
the `dims` dimensional hypersphere with radius `similarity` with origin at `query_vector`.
* `cosine` & `dot_product`: Only return vectors where the cosine similarity or dot-product are at least the provided
* `cosine`, `dot_product`, and `max_inner_product`: Only return vectors where the cosine similarity or dot-product are at least the provided
`similarity`.
--
Read more here: <<knn-similarity-search, knn similarity search>>
end::knn-similarity[]

tag::lenient[]
Expand Down
13 changes: 13 additions & 0 deletions docs/reference/search/search-your-data/knn-search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ score = 0.9 * match_score + 0.1 * knn_score_image-vector + 0.5 * knn_score_title
```

[discrete]
[[knn-similarity-search]]
==== Search kNN with expected similarity

While kNN is a powerful tool, it always tries to return `k` nearest neighbors. Consequently, when using `knn` with
Expand All @@ -563,6 +564,18 @@ minimum similarity for a vector to be considered a match. The `knn` search flow
* Do not return any vectors that are further away than the configured `similarity`
--

NOTE: `similarity` is the true <<dense-vector-similarity, similarity>> before it has been transformed into `_score` and boost applied.

For each configured <<dense-vector-similarity, similarity>>, here is the corresponding inverted `_score` function. This is so if you are wanting to filter from a `_score` perspective, you can do this minor transformation to correctly reject irrelevant results.
--
- `l2_norm`: `sqrt((1 / _score) - 1)`
- `cosine`: `(2 * _score) - 1`
- `dot_product`: `(2 * _score) - 1`
- `max_inner_product`:
- `_score < 1`: `1 - (1 / _score)`
- `_score >= 1`: `_score - 1`
--

Here is an example. In this example we search for the given `query_vector` for `k` nearest neighbors. However, with
`filter` applied and requiring that the found vectors have at least the provided `similarity` between them.
[source,console]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.rest.ESRestTestCase;
import org.junit.ClassRule;
Expand All @@ -25,6 +26,7 @@ public abstract class DisabledSecurityDataStreamTestCase extends ESRestTestCase
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.feature(FeatureFlag.FAILURE_STORE_ENABLED)
.setting("xpack.security.enabled", "false")
.setting("xpack.watcher.enabled", "false")
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.test.cluster.ElasticsearchCluster;
import org.elasticsearch.test.cluster.FeatureFlag;
import org.elasticsearch.test.cluster.local.distribution.DistributionType;
import org.elasticsearch.test.cluster.util.resource.Resource;
import org.elasticsearch.test.rest.ESRestTestCase;
Expand All @@ -38,6 +39,7 @@ public class DataStreamLifecyclePermissionsRestIT extends ESRestTestCase {
@ClassRule
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.feature(FeatureFlag.FAILURE_STORE_ENABLED)
.setting("xpack.watcher.enabled", "false")
.setting("xpack.ml.enabled", "false")
.setting("xpack.security.enabled", "true")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import org.elasticsearch.ResourceAlreadyExistsException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.ResultDeduplicator;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction;
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeAction;
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest;
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeResponse;
Expand Down Expand Up @@ -719,7 +719,7 @@ private void deleteIndexOnce(String indexName, String reason) {
transportActionsDeduplicator.executeOnce(
deleteIndexRequest,
new ErrorRecordingActionListener(
DeleteIndexAction.NAME,
TransportDeleteIndexAction.TYPE.name(),
indexName,
errorStore,
Strings.format("Data stream lifecycle encountered an error trying to delete index [%s]", indexName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@
*/
public class DeleteDataStreamLifecycleAction {

public static final ActionType<AcknowledgedResponse> INSTANCE = new ActionType<>(
"indices:admin/data_stream/lifecycle/delete",
AcknowledgedResponse::readFrom
public static final ActionType<AcknowledgedResponse> INSTANCE = ActionType.acknowledgedResponse(
"indices:admin/data_stream/lifecycle/delete"
);

private DeleteDataStreamLifecycleAction() {/* no instances */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@
*/
public class PutDataStreamLifecycleAction {

public static final ActionType<AcknowledgedResponse> INSTANCE = new ActionType<>(
"indices:admin/data_stream/lifecycle/put",
AcknowledgedResponse::readFrom
public static final ActionType<AcknowledgedResponse> INSTANCE = ActionType.acknowledgedResponse(
"indices:admin/data_stream/lifecycle/put"
);

private PutDataStreamLifecycleAction() {/* no instances */}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import org.elasticsearch.test.rest.yaml.ESClientYamlSuiteTestCase;
import org.junit.ClassRule;

import static org.elasticsearch.test.cluster.FeatureFlag.FAILURE_STORE_ENABLED;

public class DataStreamsClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {

public DataStreamsClientYamlTestSuiteIT(final ClientYamlTestCandidate testCandidate) {
Expand All @@ -43,6 +45,7 @@ protected Settings restClientSettings() {
private static ElasticsearchCluster createCluster() {
LocalClusterSpecBuilder<ElasticsearchCluster> clusterBuilder = ElasticsearchCluster.local()
.distribution(DistributionType.DEFAULT)
.feature(FAILURE_STORE_ENABLED)
.setting("xpack.security.enabled", "true")
.keystore("bootstrap.password", "x-pack-test-password")
.user("x_pack_rest_user", "x-pack-test-password");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,8 @@ setup:
---
"Create data stream with failure store":
- skip:
version: all
reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/102873"
# version: " - 8.10.99"
# reason: "data stream failure stores only creatable in 8.11+"
version: " - 8.10.99"
reason: "data stream failure stores only creatable in 8.11+"

- do:
allowed_warnings:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,8 @@
---
"Put index template with failure store":
- skip:
version: all
reason: "AwaitsFix https://github.com/elastic/elasticsearch/issues/102873"
# version: " - 8.10.99"
# reason: "data stream failure stores only creatable in 8.11+"
version: " - 8.10.99"
reason: "data stream failure stores only creatable in 8.11+"
features: allowed_warnings

- do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
import org.elasticsearch.action.admin.indices.cache.clear.ClearIndicesCacheRequest;
import org.elasticsearch.action.admin.indices.close.CloseIndexRequest;
import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexAction;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction;
import org.elasticsearch.action.admin.indices.flush.FlushRequest;
import org.elasticsearch.action.admin.indices.flush.TransportShardFlushAction;
import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeAction;
Expand Down Expand Up @@ -502,14 +502,14 @@ public void testCloseIndex() {
}

public void testDeleteIndex() {
interceptTransportActions(DeleteIndexAction.NAME);
interceptTransportActions(TransportDeleteIndexAction.TYPE.name());

String[] randomIndicesOrAliases = randomUniqueIndices();
DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(randomIndicesOrAliases);
assertAcked(internalCluster().coordOnlyNodeClient().admin().indices().delete(deleteIndexRequest).actionGet());

clearInterceptedActions();
assertSameIndices(deleteIndexRequest, DeleteIndexAction.NAME);
assertSameIndices(deleteIndexRequest, TransportDeleteIndexAction.TYPE.name());
}

public void testGetMappings() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.cluster.node.reload.NodesReloadSecureSettingsResponse;
import org.elasticsearch.action.support.PlainActionFuture;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.settings.KeyStoreWrapper;
import org.elasticsearch.common.settings.SecureSetting;
import org.elasticsearch.common.settings.SecureSettings;
import org.elasticsearch.common.settings.SecureString;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.plugins.Plugin;
Expand Down Expand Up @@ -43,6 +46,8 @@
@ESIntegTestCase.ClusterScope(minNumDataNodes = 2)
public class ReloadSecureSettingsIT extends ESIntegTestCase {

private static final String VALID_SECURE_SETTING_NAME = "some.setting.that.exists";

@BeforeClass
public static void disableInFips() {
// Reload secure settings with a password protected keystore is tested in ReloadSecureSettingsWithPasswordProtectedKeystoreRestIT
Expand Down Expand Up @@ -350,9 +355,46 @@ public void testReloadWhileKeystoreChanged() throws Exception {
}
}

public void testInvalidKeyInSettings() throws Exception {
final Environment environment = internalCluster().getInstance(Environment.class);

try (KeyStoreWrapper keyStoreWrapper = KeyStoreWrapper.create()) {
keyStoreWrapper.setString(VALID_SECURE_SETTING_NAME, new char[0]);
keyStoreWrapper.save(environment.configFile(), new char[0], false);
}

PlainActionFuture<NodesReloadSecureSettingsResponse> actionFuture = new PlainActionFuture<>();
clusterAdmin().prepareReloadSecureSettings()
.setSecureStorePassword(new SecureString(new char[0]))
.setNodesIds(Strings.EMPTY_ARRAY)
.execute(actionFuture);

actionFuture.get().getNodes().forEach(nodeResponse -> assertThat(nodeResponse.reloadException(), nullValue()));

try (KeyStoreWrapper keyStoreWrapper = KeyStoreWrapper.create()) {
assertThat(keyStoreWrapper, notNullValue());
keyStoreWrapper.setString("some.setting.that.does.not.exist", new char[0]);
keyStoreWrapper.save(environment.configFile(), new char[0], false);
}

actionFuture = new PlainActionFuture<>();
clusterAdmin().prepareReloadSecureSettings()
.setSecureStorePassword(new SecureString(new char[0]))
.setNodesIds(Strings.EMPTY_ARRAY)
.execute(actionFuture);

actionFuture.get()
.getNodes()
.forEach(nodeResponse -> assertThat(nodeResponse.reloadException(), instanceOf(IllegalArgumentException.class)));
}

@Override
protected Collection<Class<? extends Plugin>> nodePlugins() {
final List<Class<? extends Plugin>> plugins = Arrays.asList(MockReloadablePlugin.class, MisbehavingReloadablePlugin.class);
final List<Class<? extends Plugin>> plugins = Arrays.asList(
MockWithSecureSettingPlugin.class,
MockReloadablePlugin.class,
MisbehavingReloadablePlugin.class
);
// shuffle as reload is called in order
Collections.shuffle(plugins, random());
return plugins;
Expand Down Expand Up @@ -455,4 +497,10 @@ public synchronized void setShouldThrow(boolean shouldThrow) {
}
}

public static class MockWithSecureSettingPlugin extends Plugin {
public List<Setting<?>> getSettings() {
return List.of(SecureSetting.secureString(VALID_SECURE_SETTING_NAME, null));
}
};

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void testDesiredBalanceOnMultiNodeCluster() throws Exception {
var clusterHealthResponse = clusterAdmin().health(new ClusterHealthRequest().waitForStatus(ClusterHealthStatus.GREEN)).get();
assertEquals(RestStatus.OK, clusterHealthResponse.status());

DesiredBalanceResponse desiredBalanceResponse = client().execute(GetDesiredBalanceAction.INSTANCE, new DesiredBalanceRequest())
DesiredBalanceResponse desiredBalanceResponse = client().execute(TransportGetDesiredBalanceAction.TYPE, new DesiredBalanceRequest())
.get();

assertEquals(1, desiredBalanceResponse.getRoutingTable().size());
Expand Down Expand Up @@ -75,7 +75,7 @@ public void testDesiredBalanceWithUnassignedShards() throws Exception {
var clusterHealthResponse = clusterAdmin().health(new ClusterHealthRequest(index).waitForStatus(ClusterHealthStatus.YELLOW)).get();
assertEquals(RestStatus.OK, clusterHealthResponse.status());

DesiredBalanceResponse desiredBalanceResponse = client().execute(GetDesiredBalanceAction.INSTANCE, new DesiredBalanceRequest())
DesiredBalanceResponse desiredBalanceResponse = client().execute(TransportGetDesiredBalanceAction.TYPE, new DesiredBalanceRequest())
.get();

assertEquals(1, desiredBalanceResponse.getRoutingTable().size());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ public void testDeleteDesiredNodesTasksAreBatchedCorrectly() throws Exception {

final List<ActionFuture<ActionResponse.Empty>> deleteDesiredNodesFutures = new ArrayList<>(15);
for (int i = 0; i < 15; i++) {
deleteDesiredNodesFutures.add(client().execute(DeleteDesiredNodesAction.INSTANCE, new DeleteDesiredNodesAction.Request()));
deleteDesiredNodesFutures.add(
client().execute(TransportDeleteDesiredNodesAction.TYPE, new TransportDeleteDesiredNodesAction.Request())
);
}

for (ActionFuture<ActionResponse.Empty> future : deleteDesiredNodesFutures) {
Expand Down Expand Up @@ -347,8 +349,8 @@ private UpdateDesiredNodesRequest randomDryRunUpdateDesiredNodesRequest(Version
}

private void deleteDesiredNodes() {
final DeleteDesiredNodesAction.Request request = new DeleteDesiredNodesAction.Request();
client().execute(DeleteDesiredNodesAction.INSTANCE, request).actionGet();
final TransportDeleteDesiredNodesAction.Request request = new TransportDeleteDesiredNodesAction.Request();
client().execute(TransportDeleteDesiredNodesAction.TYPE, request).actionGet();
}

private DesiredNodes getLatestDesiredNodes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,7 @@ protected Collection<Class<? extends Plugin>> getPlugins() {
return List.of(TestPlugin.class);
}

private static final ActionType<ActionResponse.Empty> TEST_ACTION = new ActionType<>(
TestTransportAction.NAME,
in -> ActionResponse.Empty.INSTANCE
);
private static final ActionType<ActionResponse.Empty> TEST_ACTION = ActionType.emptyResponse(TestTransportAction.NAME);

public static class TestPlugin extends Plugin implements ActionPlugin {
volatile CyclicBarrier barrier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

package org.elasticsearch.cluster;

import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.configuration.AddVotingConfigExclusionsRequest;
import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.configuration.ClearVotingConfigExclusionsRequest;
import org.elasticsearch.action.admin.cluster.configuration.TransportAddVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.configuration.TransportClearVotingConfigExclusionsAction;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException;
Expand Down Expand Up @@ -111,7 +111,7 @@ public void testTwoNodesNoMasterBlock() throws Exception {
String masterNode = internalCluster().getMasterName();
String otherNode = node1Name.equals(masterNode) ? node2Name : node1Name;
logger.info("--> add voting config exclusion for non-master node, to be sure it's not elected");
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(otherNode)).get();
client().execute(TransportAddVotingConfigExclusionsAction.TYPE, new AddVotingConfigExclusionsRequest(otherNode)).get();
logger.info("--> stop master node, no master block should appear");
Settings masterDataPathSettings = internalCluster().dataPathSettings(masterNode);
internalCluster().stopNode(masterNode);
Expand Down Expand Up @@ -156,12 +156,12 @@ public void testTwoNodesNoMasterBlock() throws Exception {
logger.info("--> clearing voting config exclusions");
ClearVotingConfigExclusionsRequest clearRequest = new ClearVotingConfigExclusionsRequest();
clearRequest.setWaitForRemoval(false);
client().execute(ClearVotingConfigExclusionsAction.INSTANCE, clearRequest).get();
client().execute(TransportClearVotingConfigExclusionsAction.TYPE, clearRequest).get();

masterNode = internalCluster().getMasterName();
otherNode = node1Name.equals(masterNode) ? node2Name : node1Name;
logger.info("--> add voting config exclusion for master node, to be sure it's not elected");
client().execute(AddVotingConfigExclusionsAction.INSTANCE, new AddVotingConfigExclusionsRequest(masterNode)).get();
client().execute(TransportAddVotingConfigExclusionsAction.TYPE, new AddVotingConfigExclusionsRequest(masterNode)).get();
logger.info("--> stop non-master node, no master block should appear");
Settings otherNodeDataPathSettings = internalCluster().dataPathSettings(otherNode);
internalCluster().stopNode(otherNode);
Expand Down
Loading

0 comments on commit cd229ef

Please sign in to comment.