Skip to content

Commit 126f0ca

Browse files
committed
Allow deprecation logs to be indexed
1 parent f0aa24e commit 126f0ca

File tree

17 files changed

+815
-303
lines changed

17 files changed

+815
-303
lines changed

x-pack/plugin/deprecation/build.gradle

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
apply plugin: 'elasticsearch.esplugin'
2-
apply plugin: 'elasticsearch.internal-cluster-test'
32

43
esplugin {
54
name 'x-pack-deprecation'
@@ -9,6 +8,15 @@ esplugin {
98
}
109
archivesBaseName = 'x-pack-deprecation'
1110

11+
// add all sub-projects of the qa sub-project
12+
gradle.projectsEvaluated {
13+
project.subprojects
14+
.find { it.path == project.path + ":qa" }
15+
.subprojects
16+
.findAll { it.path.startsWith(project.path + ":qa") }
17+
.each { check.dependsOn it.check }
18+
}
19+
1220
dependencies {
1321
compileOnly project(":x-pack:plugin:core")
1422
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import org.elasticsearch.gradle.test.RestIntegTestTask
2+
3+
apply plugin: 'elasticsearch.build'
4+
test.enabled = false
5+
6+
dependencies {
7+
api project(':test:framework')
8+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import org.elasticsearch.gradle.info.BuildParams
2+
3+
apply plugin: 'elasticsearch.testclusters'
4+
apply plugin: 'elasticsearch.esplugin'
5+
apply plugin: 'elasticsearch.rest-resources'
6+
7+
esplugin {
8+
description 'Deprecated query plugin'
9+
classname 'org.elasticsearch.xpack.deprecation.TestDeprecationPlugin'
10+
}
11+
12+
dependencies {
13+
api("com.fasterxml.jackson.core:jackson-annotations:${versions.jackson}")
14+
api("com.fasterxml.jackson.core:jackson-databind:${versions.jackson}")
15+
}
16+
17+
restResources {
18+
restApi {
19+
includeCore '_common', 'indices', 'index'
20+
}
21+
}
22+
23+
testClusters.integTest {
24+
testDistribution = 'DEFAULT'
25+
// add the deprecated query plugin
26+
plugin file(project(':x-pack:plugin:deprecation:qa:rest').tasks.bundlePlugin.archiveFile)
27+
setting 'xpack.security.enabled', 'false'
28+
}
29+
30+
test.enabled = false
31+
32+
check.dependsOn integTest
33+
34+
tasks.named("dependencyLicenses").configure {
35+
mapping from: /jackson-.*/, to: 'jackson'
36+
}
37+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
This copy of Jackson JSON processor streaming parser/generator is licensed under the
2+
Apache (Software) License, version 2.0 ("the License").
3+
See the License for details about distribution rights, and the
4+
specific rights regarding derivate works.
5+
6+
You may obtain a copy of the License at:
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Jackson JSON processor
2+
3+
Jackson is a high-performance, Free/Open Source JSON processing library.
4+
It was originally written by Tatu Saloranta ([email protected]), and has
5+
been in development since 2007.
6+
It is currently developed by a community of developers, as well as supported
7+
commercially by FasterXML.com.
8+
9+
## Licensing
10+
11+
Jackson core and extension components may licensed under different licenses.
12+
To find the details that apply to this artifact see the accompanying LICENSE file.
13+
For more information, including possible other licensing options, contact
14+
FasterXML.com (http://fasterxml.com).
15+
16+
## Credits
17+
18+
A list of contributors may be found from CREDITS file, which is included
19+
in some artifacts (usually source distributions); but is always available
20+
from the source code management (SCM) system project uses.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6ae6028aff033f194c9710ad87c224ccaadeed6c
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
76e9152e93d4cf052f93a64596f633ba5b1c8ed9
Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.IOException;
2020
import java.util.Collections;
21+
import java.util.HashMap;
2122
import java.util.List;
2223
import java.util.Map;
2324

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

36-
public static final Setting<Boolean> TEST_DEPRECATED_SETTING_TRUE1 =
37-
Setting.boolSetting("test.setting.deprecated.true1", true,
38-
Setting.Property.NodeScope, Setting.Property.Deprecated, Setting.Property.Dynamic);
39-
public static final Setting<Boolean> TEST_DEPRECATED_SETTING_TRUE2 =
40-
Setting.boolSetting("test.setting.deprecated.true2", true,
41-
Setting.Property.NodeScope, Setting.Property.Deprecated, Setting.Property.Dynamic);
42-
public static final Setting<Boolean> TEST_NOT_DEPRECATED_SETTING =
43-
Setting.boolSetting("test.setting.not_deprecated", false,
44-
Setting.Property.NodeScope, Setting.Property.Dynamic);
37+
public static final Setting<Boolean> TEST_DEPRECATED_SETTING_TRUE1 = Setting.boolSetting(
38+
"test.setting.deprecated.true1",
39+
true,
40+
Setting.Property.NodeScope,
41+
Setting.Property.Deprecated,
42+
Setting.Property.Dynamic
43+
);
44+
public static final Setting<Boolean> TEST_DEPRECATED_SETTING_TRUE2 = Setting.boolSetting(
45+
"test.setting.deprecated.true2",
46+
true,
47+
Setting.Property.NodeScope,
48+
Setting.Property.Deprecated,
49+
Setting.Property.Dynamic
50+
);
51+
public static final Setting<Boolean> TEST_NOT_DEPRECATED_SETTING = Setting.boolSetting(
52+
"test.setting.not_deprecated",
53+
false,
54+
Setting.Property.NodeScope,
55+
Setting.Property.Dynamic
56+
);
4557

4658
private static final Map<String, Setting<?>> SETTINGS_MAP = Map.of(
47-
TEST_DEPRECATED_SETTING_TRUE1.getKey(), TEST_DEPRECATED_SETTING_TRUE1,
48-
TEST_DEPRECATED_SETTING_TRUE2.getKey(), TEST_DEPRECATED_SETTING_TRUE2,
49-
TEST_NOT_DEPRECATED_SETTING.getKey(), TEST_NOT_DEPRECATED_SETTING);
59+
TEST_DEPRECATED_SETTING_TRUE1.getKey(),
60+
TEST_DEPRECATED_SETTING_TRUE1,
61+
TEST_DEPRECATED_SETTING_TRUE2.getKey(),
62+
TEST_DEPRECATED_SETTING_TRUE2,
63+
TEST_NOT_DEPRECATED_SETTING.getKey(),
64+
TEST_NOT_DEPRECATED_SETTING
65+
);
5066

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

6076
@Override
6177
public List<DeprecatedRoute> deprecatedRoutes() {
62-
return singletonList(
63-
new DeprecatedRoute(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT));
78+
return singletonList(new DeprecatedRoute(GET, "/_test_cluster/deprecated_settings", DEPRECATED_ENDPOINT));
6479
}
6580

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

87-
settings = (List<String>)source.get("deprecated_settings");
102+
settings = (List<String>) source.get("deprecated_settings");
88103
} else {
89-
settings = (List<String>)source.get("settings");
104+
settings = (List<String>) source.get("settings");
90105
}
91106
}
92107

108+
// Pull out the settings values here in order to guarantee that any deprecation messages are triggered
109+
// in the same thread context.
110+
final Map<String, Object> settingsMap = new HashMap<>();
111+
for (String setting : settings) {
112+
settingsMap.put(setting, SETTINGS_MAP.get(setting).get(this.settings));
113+
}
114+
93115
return channel -> {
94116
final XContentBuilder builder = channel.newBuilder();
95117

96118
builder.startObject().startArray("settings");
97-
for (String setting : settings) {
98-
builder.startObject().field(setting, SETTINGS_MAP.get(setting).get(this.settings)).endObject();
119+
for (Map.Entry<String, Object> entry : settingsMap.entrySet()) {
120+
builder.startObject().field(entry.getKey(), entry.getValue()).endObject();
99121
}
100122
builder.endArray().endObject();
101123
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,15 @@
3131
public class TestDeprecationPlugin extends Plugin implements ActionPlugin, SearchPlugin {
3232

3333
@Override
34-
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
35-
IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter, IndexNameExpressionResolver indexNameExpressionResolver,
36-
Supplier<DiscoveryNodes> nodesInCluster) {
34+
public List<RestHandler> getRestHandlers(
35+
Settings settings,
36+
RestController restController,
37+
ClusterSettings clusterSettings,
38+
IndexScopedSettings indexScopedSettings,
39+
SettingsFilter settingsFilter,
40+
IndexNameExpressionResolver indexNameExpressionResolver,
41+
Supplier<DiscoveryNodes> nodesInCluster
42+
) {
3743
return Collections.singletonList(new TestDeprecationHeaderRestAction(settings));
3844
}
3945

@@ -42,13 +48,15 @@ public List<Setting<?>> getSettings() {
4248
return Arrays.asList(
4349
TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1,
4450
TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE2,
45-
TestDeprecationHeaderRestAction.TEST_NOT_DEPRECATED_SETTING);
51+
TestDeprecationHeaderRestAction.TEST_NOT_DEPRECATED_SETTING
52+
);
4653
}
4754

4855
@Override
4956
public List<QuerySpec<?>> getQueries() {
50-
return singletonList(new QuerySpec<>(TestDeprecatedQueryBuilder.NAME, TestDeprecatedQueryBuilder::new,
51-
TestDeprecatedQueryBuilder::fromXContent));
57+
return singletonList(
58+
new QuerySpec<>(TestDeprecatedQueryBuilder.NAME, TestDeprecatedQueryBuilder::new, TestDeprecatedQueryBuilder::fromXContent)
59+
);
5260
}
5361

5462
}

0 commit comments

Comments
 (0)