Skip to content

Write deprecation logs to a data stream #61484

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
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion x-pack/plugin/deprecation/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'elasticsearch.internal-cluster-test'

esplugin {
name 'x-pack-deprecation'
Expand All @@ -9,6 +8,15 @@ esplugin {
}
archivesBaseName = 'x-pack-deprecation'

// add all sub-projects of the qa sub-project
gradle.projectsEvaluated {
project.subprojects
.find { it.path == project.path + ":qa" }
.subprojects
.findAll { it.path.startsWith(project.path + ":qa") }
.each { check.dependsOn it.check }
}

dependencies {
compileOnly project(":x-pack:plugin:core")
}
Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugin/deprecation/qa/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.elasticsearch.gradle.test.RestIntegTestTask

apply plugin: 'elasticsearch.build'
test.enabled = false

dependencies {
api project(':test:framework')
}
37 changes: 37 additions & 0 deletions x-pack/plugin/deprecation/qa/rest/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import org.elasticsearch.gradle.info.BuildParams

apply plugin: 'elasticsearch.testclusters'
apply plugin: 'elasticsearch.esplugin'
apply plugin: 'elasticsearch.rest-resources'

esplugin {
description 'Deprecated query plugin'
classname 'org.elasticsearch.xpack.deprecation.TestDeprecationPlugin'
}

dependencies {
api("com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}")
api("com.fasterxml.jackson.core:jackson-databind:${versions.jackson}")
}

restResources {
restApi {
includeCore '_common', 'indices', 'index'
}
}

testClusters.integTest {
testDistribution = 'DEFAULT'
// add the deprecated query plugin
plugin file(project(':x-pack:plugin:deprecation:qa:rest').tasks.bundlePlugin.archiveFile)
setting 'xpack.security.enabled', 'false'
}

test.enabled = false

check.dependsOn integTest

tasks.named("dependencyLicenses").configure {
mapping from: /jackson-.*/, to: 'jackson'
}

8 changes: 8 additions & 0 deletions x-pack/plugin/deprecation/qa/rest/licenses/jackson-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
This copy of Jackson JSON processor streaming parser/generator is licensed under the
Apache (Software) License, version 2.0 ("the License").
See the License for details about distribution rights, and the
specific rights regarding derivate works.

You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0
20 changes: 20 additions & 0 deletions x-pack/plugin/deprecation/qa/rest/licenses/jackson-NOTICE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Jackson JSON processor

Jackson is a high-performance, Free/Open Source JSON processing library.
It was originally written by Tatu Saloranta ([email protected]), and has
been in development since 2007.
It is currently developed by a community of developers, as well as supported
commercially by FasterXML.com.

## Licensing

Jackson core and extension components may licensed under different licenses.
To find the details that apply to this artifact see the accompanying LICENSE file.
For more information, including possible other licensing options, contact
FasterXML.com (http://fasterxml.com).

## Credits

A list of contributors may be found from CREDITS file, which is included
in some artifacts (usually source distributions); but is always available
from the source code management (SCM) system project uses.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6ae6028aff033f194c9710ad87c224ccaadeed6c
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
76e9152e93d4cf052f93a64596f633ba5b1c8ed9
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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

Expand All @@ -33,20 +34,35 @@
public class TestDeprecationHeaderRestAction extends BaseRestHandler {
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(TestDeprecationHeaderRestAction.class);

public static final Setting<Boolean> TEST_DEPRECATED_SETTING_TRUE1 =
Setting.boolSetting("test.setting.deprecated.true1", true,
Setting.Property.NodeScope, Setting.Property.Deprecated, Setting.Property.Dynamic);
public static final Setting<Boolean> TEST_DEPRECATED_SETTING_TRUE2 =
Setting.boolSetting("test.setting.deprecated.true2", true,
Setting.Property.NodeScope, Setting.Property.Deprecated, Setting.Property.Dynamic);
public static final Setting<Boolean> TEST_NOT_DEPRECATED_SETTING =
Setting.boolSetting("test.setting.not_deprecated", false,
Setting.Property.NodeScope, Setting.Property.Dynamic);
public static final Setting<Boolean> TEST_DEPRECATED_SETTING_TRUE1 = Setting.boolSetting(
"test.setting.deprecated.true1",
true,
Setting.Property.NodeScope,
Setting.Property.Deprecated,
Setting.Property.Dynamic
);
public static final Setting<Boolean> TEST_DEPRECATED_SETTING_TRUE2 = Setting.boolSetting(
"test.setting.deprecated.true2",
true,
Setting.Property.NodeScope,
Setting.Property.Deprecated,
Setting.Property.Dynamic
);
public static final Setting<Boolean> TEST_NOT_DEPRECATED_SETTING = Setting.boolSetting(
"test.setting.not_deprecated",
false,
Setting.Property.NodeScope,
Setting.Property.Dynamic
);

private static final Map<String, Setting<?>> SETTINGS_MAP = Map.of(
TEST_DEPRECATED_SETTING_TRUE1.getKey(), TEST_DEPRECATED_SETTING_TRUE1,
TEST_DEPRECATED_SETTING_TRUE2.getKey(), TEST_DEPRECATED_SETTING_TRUE2,
TEST_NOT_DEPRECATED_SETTING.getKey(), TEST_NOT_DEPRECATED_SETTING);
TEST_DEPRECATED_SETTING_TRUE1.getKey(),
TEST_DEPRECATED_SETTING_TRUE1,
TEST_DEPRECATED_SETTING_TRUE2.getKey(),
TEST_DEPRECATED_SETTING_TRUE2,
TEST_NOT_DEPRECATED_SETTING.getKey(),
TEST_NOT_DEPRECATED_SETTING
);

public static final String DEPRECATED_ENDPOINT = "[/_test_cluster/deprecated_settings] exists for deprecated tests";
public static final String DEPRECATED_USAGE = "[deprecated_settings] usage is deprecated. use [settings] instead";
Expand All @@ -59,8 +75,7 @@ public TestDeprecationHeaderRestAction(Settings settings) {

@Override
public List<DeprecatedRoute> deprecatedRoutes() {
return singletonList(
new DeprecatedRoute(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT));
return singletonList(new DeprecatedRoute(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT));
}

@Override
Expand All @@ -84,18 +99,25 @@ public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client
if (source.containsKey("deprecated_settings")) {
deprecationLogger.deprecate("deprecated_settings", DEPRECATED_USAGE);

settings = (List<String>)source.get("deprecated_settings");
settings = (List<String>) source.get("deprecated_settings");
} else {
settings = (List<String>)source.get("settings");
settings = (List<String>) source.get("settings");
}
}

// Pull out the settings values here in order to guarantee that any deprecation messages are triggered
// in the same thread context.
final Map<String, Object> settingsMap = new HashMap<>();
for (String setting : settings) {
settingsMap.put(setting, SETTINGS_MAP.get(setting).get(this.settings));
}

return channel -> {
final XContentBuilder builder = channel.newBuilder();

builder.startObject().startArray("settings");
for (String setting : settings) {
builder.startObject().field(setting, SETTINGS_MAP.get(setting).get(this.settings)).endObject();
for (Map.Entry<String, Object> entry : settingsMap.entrySet()) {
builder.startObject().field(entry.getKey(), entry.getValue()).endObject();
}
builder.endArray().endObject();
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@
public class TestDeprecationPlugin extends Plugin implements ActionPlugin, SearchPlugin {

@Override
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster) {
public List<RestHandler> getRestHandlers(
Settings settings,
RestController restController,
ClusterSettings clusterSettings,
IndexScopedSettings indexScopedSettings,
SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver,
Supplier<DiscoveryNodes> nodesInCluster
) {
return Collections.singletonList(new TestDeprecationHeaderRestAction(settings));
}

Expand All @@ -42,13 +48,15 @@ public List<Setting<?>> getSettings() {
return Arrays.asList(
TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1,
TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE2,
TestDeprecationHeaderRestAction.TEST_NOT_DEPRECATED_SETTING);
TestDeprecationHeaderRestAction.TEST_NOT_DEPRECATED_SETTING
);
}

@Override
public List<QuerySpec<?>> getQueries() {
return singletonList(new QuerySpec<>(TestDeprecatedQueryBuilder.NAME, TestDeprecatedQueryBuilder::new,
TestDeprecatedQueryBuilder::fromXContent));
return singletonList(
new QuerySpec<>(TestDeprecatedQueryBuilder.NAME, TestDeprecatedQueryBuilder::new, TestDeprecatedQueryBuilder::fromXContent)
);
}

}
Loading