-
Notifications
You must be signed in to change notification settings - Fork 25.2k
Make S3 custom query parameter optional #128043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
elasticsearchmachine
merged 13 commits into
elastic:main
from
DaveCTurner:2025/05/12/optional-s3-custom-query-parameter
May 20, 2025
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6814d98
Make S3 custom query parameter optional
DaveCTurner 88c4c77
CI poke
DaveCTurner 81cef8c
Update docs/changelog/128043.yaml
DaveCTurner 3f1a8f4
Revert "Update docs/changelog/128043.yaml"
DaveCTurner 6cca2b3
Update docs/changelog/128043.yaml
DaveCTurner 2512826
Revert "Update docs/changelog/128043.yaml"
DaveCTurner b9da53e
Update docs/changelog/128043.yaml
DaveCTurner 36cb13d
Revert "Update docs/changelog/128043.yaml"
DaveCTurner c148ba1
Merge branch 'main' into 2025/05/12/optional-s3-custom-query-parameter
DaveCTurner 6b91e9b
Rethrow errors properly
DaveCTurner 0e58906
No need to set `repoAnalysisStarted` again
DaveCTurner f38515d
Update docs/changelog/128043.yaml
DaveCTurner 9bfb6f0
Revert "Update docs/changelog/128043.yaml"
DaveCTurner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
pr: 128043 | ||
summary: Make S3 custom query parameter optional | ||
area: Snapshot/Restore | ||
type: breaking | ||
issues: [] | ||
breaking: | ||
title: Make S3 custom query parameter optional | ||
area: Cluster and node setting | ||
details: >- | ||
Earlier versions of Elasticsearch would record the purpose of each S3 API | ||
call using the `?x-purpose=` custom query parameter. This isn't believed to | ||
be necessary outside of the ECH/ECE/ECK/... managed services, and it adds | ||
rather a lot to the request logs, so with this change we make the feature | ||
optional and disabled by default. | ||
impact: >- | ||
If you wish to reinstate the old behaviour on a S3 repository, set | ||
`s3.client.${CLIENT_NAME}.add_purpose_custom_query_parameter` to `true` | ||
for the relevant client. | ||
notable: false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
.../src/test/java/org/elasticsearch/repositories/s3/AddPurposeCustomQueryParameterTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the "Elastic License | ||
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
package org.elasticsearch.repositories.s3; | ||
|
||
import fixture.s3.S3HttpFixture; | ||
import fixture.s3.S3HttpHandler; | ||
|
||
import com.sun.net.httpserver.HttpExchange; | ||
import com.sun.net.httpserver.HttpHandler; | ||
|
||
import org.elasticsearch.ExceptionsHelper; | ||
import org.elasticsearch.action.admin.cluster.repositories.put.PutRepositoryRequest; | ||
import org.elasticsearch.action.admin.cluster.repositories.put.TransportPutRepositoryAction; | ||
import org.elasticsearch.action.admin.cluster.snapshots.create.CreateSnapshotRequest; | ||
import org.elasticsearch.action.admin.cluster.snapshots.create.TransportCreateSnapshotAction; | ||
import org.elasticsearch.common.settings.MockSecureSettings; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.common.util.CollectionUtils; | ||
import org.elasticsearch.core.SuppressForbidden; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.snapshots.SnapshotState; | ||
import org.elasticsearch.test.ESSingleNodeTestCase; | ||
import org.hamcrest.Matcher; | ||
import org.junit.runner.Description; | ||
import org.junit.runners.model.Statement; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
import static org.hamcrest.Matchers.hasItem; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
public class AddPurposeCustomQueryParameterTests extends ESSingleNodeTestCase { | ||
|
||
@Override | ||
protected Collection<Class<? extends Plugin>> getPlugins() { | ||
return CollectionUtils.appendToCopyNoNullElements(super.getPlugins(), S3RepositoryPlugin.class); | ||
} | ||
|
||
@Override | ||
protected Settings nodeSettings() { | ||
final var secureSettings = new MockSecureSettings(); | ||
for (final var clientName : List.of("default", "with_purpose", "without_purpose")) { | ||
secureSettings.setString( | ||
S3ClientSettings.ACCESS_KEY_SETTING.getConcreteSettingForNamespace(clientName).getKey(), | ||
randomIdentifier() | ||
); | ||
secureSettings.setString( | ||
S3ClientSettings.SECRET_KEY_SETTING.getConcreteSettingForNamespace(clientName).getKey(), | ||
randomSecretKey() | ||
); | ||
} | ||
|
||
return Settings.builder() | ||
.put(super.nodeSettings()) | ||
.put(S3ClientSettings.REGION.getConcreteSettingForNamespace("default").getKey(), randomIdentifier()) | ||
.put(S3ClientSettings.ADD_PURPOSE_CUSTOM_QUERY_PARAMETER.getConcreteSettingForNamespace("with_purpose").getKey(), "true") | ||
.put(S3ClientSettings.ADD_PURPOSE_CUSTOM_QUERY_PARAMETER.getConcreteSettingForNamespace("without_purpose").getKey(), "false") | ||
.setSecureSettings(secureSettings) | ||
.build(); | ||
} | ||
|
||
private static final Matcher<Iterable<? super String>> HAS_CUSTOM_QUERY_PARAMETER = hasItem(S3BlobStore.CUSTOM_QUERY_PARAMETER_PURPOSE); | ||
private static final Matcher<Iterable<? super String>> NO_CUSTOM_QUERY_PARAMETER = not(HAS_CUSTOM_QUERY_PARAMETER); | ||
|
||
public void testCustomQueryParameterConfiguration() throws Throwable { | ||
final var indexName = randomIdentifier(); | ||
createIndex(indexName); | ||
prepareIndex(indexName).setSource("foo", "bar").get(); | ||
|
||
final var bucket = randomIdentifier(); | ||
final var basePath = randomIdentifier(); | ||
|
||
runCustomQueryParameterTest(bucket, basePath, null, Settings.EMPTY, NO_CUSTOM_QUERY_PARAMETER); | ||
runCustomQueryParameterTest(bucket, basePath, "default", Settings.EMPTY, NO_CUSTOM_QUERY_PARAMETER); | ||
runCustomQueryParameterTest(bucket, basePath, "without_purpose", Settings.EMPTY, NO_CUSTOM_QUERY_PARAMETER); | ||
runCustomQueryParameterTest(bucket, basePath, "with_purpose", Settings.EMPTY, HAS_CUSTOM_QUERY_PARAMETER); | ||
|
||
final var falseRepositorySetting = Settings.builder().put("add_purpose_custom_query_parameter", false).build(); | ||
final var trueRepositorySetting = Settings.builder().put("add_purpose_custom_query_parameter", true).build(); | ||
for (final var clientName : new String[] { null, "default", "with_purpose", "without_purpose" }) { | ||
// client name doesn't matter if repository setting specified | ||
runCustomQueryParameterTest(bucket, basePath, clientName, falseRepositorySetting, NO_CUSTOM_QUERY_PARAMETER); | ||
runCustomQueryParameterTest(bucket, basePath, clientName, trueRepositorySetting, HAS_CUSTOM_QUERY_PARAMETER); | ||
} | ||
} | ||
|
||
private void runCustomQueryParameterTest( | ||
String bucket, | ||
String basePath, | ||
String clientName, | ||
Settings extraRepositorySettings, | ||
Matcher<Iterable<? super String>> queryParamMatcher | ||
) throws Throwable { | ||
final var httpFixture = new S3HttpFixture(true, bucket, basePath, (key, token) -> true) { | ||
|
||
@SuppressForbidden(reason = "this test uses a HttpServer to emulate an S3 endpoint") | ||
class AssertingHandler extends S3HttpHandler { | ||
AssertingHandler() { | ||
super(bucket, basePath); | ||
} | ||
|
||
@SuppressForbidden(reason = "this test uses a HttpServer to emulate an S3 endpoint") | ||
@Override | ||
public void handle(HttpExchange exchange) throws IOException { | ||
try { | ||
assertThat(parseRequest(exchange).queryParameters().keySet(), queryParamMatcher); | ||
super.handle(exchange); | ||
} catch (Error e) { | ||
// HttpServer catches Throwable, so we must throw errors on another thread | ||
ExceptionsHelper.maybeDieOnAnotherThread(e); | ||
throw e; | ||
} | ||
} | ||
} | ||
|
||
@SuppressForbidden(reason = "this test uses a HttpServer to emulate an S3 endpoint") | ||
@Override | ||
protected HttpHandler createHandler() { | ||
return new AssertingHandler(); | ||
} | ||
}; | ||
httpFixture.apply(new Statement() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to stop the fixture explicitly especially when the test fails? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's handled within |
||
@Override | ||
public void evaluate() { | ||
final var repoName = randomIdentifier(); | ||
assertAcked( | ||
client().execute( | ||
TransportPutRepositoryAction.TYPE, | ||
new PutRepositoryRequest(TEST_REQUEST_TIMEOUT, TEST_REQUEST_TIMEOUT, repoName).type(S3Repository.TYPE) | ||
.settings( | ||
Settings.builder() | ||
.put("bucket", bucket) | ||
.put("base_path", basePath) | ||
.put("endpoint", httpFixture.getAddress()) | ||
.put(clientName == null ? Settings.EMPTY : Settings.builder().put("client", clientName).build()) | ||
.put(extraRepositorySettings) | ||
) | ||
) | ||
); | ||
|
||
assertEquals( | ||
SnapshotState.SUCCESS, | ||
client().execute( | ||
TransportCreateSnapshotAction.TYPE, | ||
new CreateSnapshotRequest(TEST_REQUEST_TIMEOUT, repoName, randomIdentifier()).waitForCompletion(true) | ||
).actionGet(SAFE_AWAIT_TIMEOUT).getSnapshotInfo().state() | ||
); | ||
} | ||
}, Description.EMPTY).evaluate(); | ||
} | ||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make
AssertingHandler
delegate to the handler returned bysuper.createHandler()
so that we don't miss the fix from #102976?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure see 6b91e9b. It doesn't really matter here, the test fails either way.