Skip to content

Commit c1385fb

Browse files
authored
Change deprecation logs data stream name (elastic#71642)
Backport of elastic#68737. More fixes to deprecation log indexing so that the data stream name and document contents are more ECS-compatible.
1 parent 08f81d5 commit c1385fb

File tree

12 files changed

+149
-33
lines changed

12 files changed

+149
-33
lines changed

distribution/src/config/log4j2.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ appender.deprecation_rolling.type = RollingFile
6262
appender.deprecation_rolling.name = deprecation_rolling
6363
appender.deprecation_rolling.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecation.json
6464
appender.deprecation_rolling.layout.type = ESJsonLayout
65-
appender.deprecation_rolling.layout.type_name = deprecation
65+
appender.deprecation_rolling.layout.type_name = deprecation.elasticsearch
6666
appender.deprecation_rolling.layout.esmessagefields=x-opaque-id
6767
appender.deprecation_rolling.filter.rate_limit.type = RateLimitingFilter
6868

modules/transport-netty4/src/javaRestTest/java/org/elasticsearch/rest/Netty4HeadBodyIsEmptyIT.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ public void testTemplateExists() throws IOException {
134134
request.setOptions(expectWarnings(
135135
"legacy template [template] has index patterns [*] matching patterns from existing composable templates " +
136136
"[.deprecation-indexing-template,.slm-history,.watch-history-13,ilm-history,logs," +
137-
"metrics,synthetics] with patterns (.deprecation-indexing-template => [.logs-deprecation-elasticsearch]," +
137+
"metrics,synthetics] with patterns (.deprecation-indexing-template => [.logs-deprecation.elasticsearch-default]," +
138138
".slm-history => [.slm-history-5*]," +
139139
".watch-history-13 => [.watcher-history-13*],ilm-history => [ilm-history-5*]," +
140140
"logs => [logs-*-*],metrics => [metrics-*-*],synthetics => [synthetics-*-*]" +

qa/logging-config/src/test/java/org/elasticsearch/common/logging/JsonLoggerTests.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void testParseFieldEmittingLogs() throws Exception {
9696
contains(
9797
// deprecation log for field deprecated_name
9898
allOf(
99-
hasEntry("type", "deprecation"),
99+
hasEntry("type", "deprecation.elasticsearch"),
100100
hasEntry("level", "DEPRECATION"),
101101
hasEntry("component", "o.e.d.c.ParseField"),
102102
hasEntry("cluster.name", "elasticsearch"),
@@ -105,7 +105,7 @@ public void testParseFieldEmittingLogs() throws Exception {
105105
hasEntry("x-opaque-id", "someId")
106106
),
107107
allOf(
108-
hasEntry("type", "deprecation"),
108+
hasEntry("type", "deprecation.elasticsearch"),
109109
hasEntry("level", "DEPRECATION"),
110110
hasEntry("component", "o.e.d.c.ParseField"),
111111
hasEntry("cluster.name", "elasticsearch"),
@@ -141,7 +141,7 @@ public void testDeprecatedMessage() throws Exception {
141141
jsonLogs,
142142
contains(
143143
allOf(
144-
hasEntry("type", "deprecation"),
144+
hasEntry("type", "deprecation.elasticsearch"),
145145
hasEntry("level", "DEPRECATION"),
146146
hasEntry("component", "o.e.d.test"),
147147
hasEntry("cluster.name", "elasticsearch"),
@@ -170,7 +170,7 @@ public void testDeprecatedMessageWithoutXOpaqueId() throws IOException {
170170

171171
assertThat(jsonLogs, contains(
172172
allOf(
173-
hasEntry("type", "deprecation"),
173+
hasEntry("type", "deprecation.elasticsearch"),
174174
hasEntry("level", "DEPRECATION"),
175175
hasEntry("component", "o.e.d.test"),
176176
hasEntry("cluster.name", "elasticsearch"),
@@ -314,7 +314,7 @@ public void testDuplicateLogMessages() throws Exception {
314314

315315
assertThat(jsonLogs, contains(
316316
allOf(
317-
hasEntry("type", "deprecation"),
317+
hasEntry("type", "deprecation.elasticsearch"),
318318
hasEntry("level", "DEPRECATION"),
319319
hasEntry("component", "o.e.d.test"),
320320
hasEntry("cluster.name", "elasticsearch"),
@@ -348,7 +348,7 @@ public void testDuplicateLogMessages() throws Exception {
348348
jsonLogs,
349349
contains(
350350
allOf(
351-
hasEntry("type", "deprecation"),
351+
hasEntry("type", "deprecation.elasticsearch"),
352352
hasEntry("level", "DEPRECATION"),
353353
hasEntry("component", "o.e.d.test"),
354354
hasEntry("cluster.name", "elasticsearch"),
@@ -357,7 +357,7 @@ public void testDuplicateLogMessages() throws Exception {
357357
hasEntry("x-opaque-id", "ID1")
358358
),
359359
allOf(
360-
hasEntry("type", "deprecation"),
360+
hasEntry("type", "deprecation.elasticsearch"),
361361
hasEntry("level", "DEPRECATION"),
362362
hasEntry("component", "o.e.d.test"),
363363
hasEntry("cluster.name", "elasticsearch"),

qa/logging-config/src/test/resources/org/elasticsearch/common/logging/json_layout/log4j2.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ appender.deprecated.type = File
1313
appender.deprecated.name = deprecated
1414
appender.deprecated.fileName = ${sys:es.logs.base_path}${sys:file.separator}${sys:es.logs.cluster_name}_deprecated.json
1515
appender.deprecated.layout.type = ESJsonLayout
16-
appender.deprecated.layout.type_name = deprecation
16+
appender.deprecated.layout.type_name = deprecation.elasticsearch
1717
appender.deprecated.layout.esmessagefields = x-opaque-id
1818
appender.deprecated.filter.rate_limit.type = RateLimitingFilter
1919

@@ -27,7 +27,7 @@ appender.deprecation_rolling_old.filter.rate_limit.type = RateLimitingFilter
2727
appender.deprecatedconsole.type = Console
2828
appender.deprecatedconsole.name = deprecatedconsole
2929
appender.deprecatedconsole.layout.type = ESJsonLayout
30-
appender.deprecatedconsole.layout.type_name = deprecation
30+
appender.deprecatedconsole.layout.type_name = deprecation.elasticsearch
3131
appender.deprecatedconsole.layout.esmessagefields = x-opaque-id
3232
appender.deprecatedconsole.filter.rate_limit.type = RateLimitingFilter
3333

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/deprecation/deprecation-indexing-ilm-policy.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"hot": {
44
"actions": {
55
"rollover": {
6-
"max_primary_shard_size": "50gb",
7-
"max_age": "30d"
6+
"max_primary_shard_size": "10gb",
7+
"max_age": "14d"
88
}
99
}
1010
}

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/deprecation/deprecation-indexing-mappings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
}
5454
},
5555
"_meta": {
56-
"description": "default mappings for ES deprecation logs index template installed by x-pack",
56+
"description": "default mappings for Stack deprecation logs index template installed by x-pack",
5757
"managed": true
5858
},
5959
"version": ${xpack.deprecation.indexing.template.version}

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/deprecation/deprecation-indexing-settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
},
1515
"_meta": {
16-
"description": "default settings for ES deprecation logs index template installed by x-pack",
16+
"description": "default settings for Stack deprecation logs index template installed by x-pack",
1717
"managed": true
1818
},
1919
"version": ${xpack.deprecation.indexing.template.version}

x-pack/plugin/core/src/main/resources/org/elasticsearch/xpack/deprecation/deprecation-indexing-template.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"index_patterns": [".logs-deprecation-elasticsearch"],
2+
"index_patterns": [".logs-deprecation.*"],
33
"priority": 1000,
44
"data_stream": {
55
"hidden": true
@@ -10,7 +10,7 @@
1010
],
1111
"allow_auto_create": true,
1212
"_meta": {
13-
"description": "default template for ES deprecation logs index template installed by x-pack",
13+
"description": "default template for Stack deprecation logs index template installed by x-pack",
1414
"managed": true
1515
},
1616
"version": ${xpack.deprecation.indexing.template.version}

x-pack/plugin/deprecation/qa/rest/src/javaRestTest/java/org/elasticsearch/xpack/deprecation/DeprecationHttpIT.java

Lines changed: 128 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,15 @@
3232
import java.util.ArrayList;
3333
import java.util.Arrays;
3434
import java.util.Collections;
35-
import java.util.HashMap;
35+
import java.util.TreeMap;
3636
import java.util.List;
3737
import java.util.Map;
3838
import java.util.concurrent.TimeUnit;
3939
import java.util.stream.Collectors;
4040

4141
import static org.elasticsearch.test.hamcrest.RegexMatcher.matches;
4242
import static org.hamcrest.Matchers.allOf;
43+
import static org.hamcrest.Matchers.containsInAnyOrder;
4344
import static org.hamcrest.Matchers.containsString;
4445
import static org.hamcrest.Matchers.equalTo;
4546
import static org.hamcrest.Matchers.greaterThan;
@@ -50,10 +51,15 @@
5051
import static org.hamcrest.Matchers.hasSize;
5152

5253
/**
53-
* Tests {@code DeprecationLogger} uses the {@code ThreadContext} to add response headers.
54+
* Tests that deprecation message are returned via response headers, and can be indexed into a data stream.
5455
*/
5556
public class DeprecationHttpIT extends ESRestTestCase {
5657

58+
/**
59+
* Same as <code>DeprecationIndexingAppender#DEPRECATION_MESSAGES_DATA_STREAM</code>, but that class isn't visible from here.
60+
*/
61+
private static final String DATA_STREAM_NAME = ".logs-deprecation.elasticsearch-default";
62+
5763
/**
5864
* Check that configuring deprecation settings causes a warning to be added to the
5965
* response headers.
@@ -93,8 +99,7 @@ public void testDeprecatedSettingsReturnWarnings() throws IOException {
9399
equalTo(
94100
"["
95101
+ setting.getKey()
96-
+ "] setting was deprecated in Elasticsearch and will be removed in a "
97-
+ "future release! "
102+
+ "] setting was deprecated in Elasticsearch and will be removed in a future release! "
98103
+ "See the breaking changes documentation for the next major version."
99104
)
100105
);
@@ -242,8 +247,117 @@ public void testDeprecationMessagesCanBeIndexed() throws Exception {
242247
assertBusy(() -> {
243248
Response response;
244249
try {
245-
client().performRequest(new Request("POST", "/.logs-deprecation-elasticsearch/_refresh?ignore_unavailable=true"));
246-
response = client().performRequest(new Request("GET", "/.logs-deprecation-elasticsearch/_search"));
250+
client().performRequest(new Request("POST", "/" + DATA_STREAM_NAME + "/_refresh?ignore_unavailable=true"));
251+
response = client().performRequest(new Request("GET", "/" + DATA_STREAM_NAME + "/_search"));
252+
} catch (Exception e) {
253+
// It can take a moment for the index to be created. If it doesn't exist then the client
254+
// throws an exception. Translate it into an assertion error so that assertBusy() will
255+
// continue trying.
256+
throw new AssertionError(e);
257+
}
258+
assertOK(response);
259+
260+
ObjectMapper mapper = new ObjectMapper();
261+
final JsonNode jsonNode = mapper.readTree(response.getEntity().getContent());
262+
263+
final int hits = jsonNode.at("/hits/total/value").intValue();
264+
assertThat(hits, greaterThan(0));
265+
266+
List<Map<String, Object>> documents = new ArrayList<>();
267+
268+
for (int i = 0; i < hits; i++) {
269+
final JsonNode hit = jsonNode.at("/hits/hits/" + i + "/_source");
270+
271+
final Map<String, Object> document = new TreeMap<>();
272+
hit.fields().forEachRemaining(entry -> document.put(entry.getKey(), entry.getValue().textValue()));
273+
274+
documents.add(document);
275+
}
276+
277+
logger.warn(documents);
278+
assertThat(documents, hasSize(2));
279+
280+
assertThat(
281+
documents,
282+
hasItems(
283+
allOf(
284+
hasKey("@timestamp"),
285+
hasKey("elasticsearch.cluster.name"),
286+
hasKey("elasticsearch.cluster.uuid"),
287+
hasEntry("elasticsearch.http.request.x_opaque_id", "some xid"),
288+
hasEntry("elasticsearch.event.category", "other"),
289+
hasKey("elasticsearch.node.id"),
290+
hasKey("elasticsearch.node.name"),
291+
hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
292+
hasEntry("data_stream.namespace", "default"),
293+
hasEntry("data_stream.type", "logs"),
294+
hasEntry("ecs.version", "1.7"),
295+
hasEntry("event.code", "deprecated_settings"),
296+
hasEntry("event.dataset", "deprecation.elasticsearch"),
297+
hasEntry("log.level", "DEPRECATION"),
298+
hasKey("log.logger"),
299+
hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
300+
),
301+
allOf(
302+
hasKey("@timestamp"),
303+
hasKey("elasticsearch.cluster.name"),
304+
hasKey("elasticsearch.cluster.uuid"),
305+
hasEntry("elasticsearch.http.request.x_opaque_id", "some xid"),
306+
hasEntry("elasticsearch.event.category", "api"),
307+
hasKey("elasticsearch.node.id"),
308+
hasKey("elasticsearch.node.name"),
309+
hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
310+
hasEntry("data_stream.namespace", "default"),
311+
hasEntry("data_stream.type", "logs"),
312+
hasEntry("ecs.version", "1.7"),
313+
hasEntry("event.code", "deprecated_route"),
314+
hasEntry("event.dataset", "deprecation.elasticsearch"),
315+
hasEntry("log.level", "DEPRECATION"),
316+
hasKey("log.logger"),
317+
hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
318+
)
319+
)
320+
);
321+
}, 30, TimeUnit.SECONDS);
322+
} finally {
323+
configureWriteDeprecationLogsToIndex(null);
324+
client().performRequest(new Request("DELETE", "_data_stream/" + DATA_STREAM_NAME));
325+
}
326+
}
327+
328+
/**
329+
* Check that log messages about REST API compatibility are recorded to an index
330+
*/
331+
public void testCompatibleMessagesCanBeIndexed() throws Exception {
332+
try {
333+
configureWriteDeprecationLogsToIndex(true);
334+
335+
final Request compatibleRequest = new Request("GET", "/_test_cluster/deprecated_settings");
336+
final RequestOptions compatibleOptions = compatibleRequest.getOptions()
337+
.toBuilder()
338+
.addHeader("X-Opaque-Id", "some xid")
339+
.build();
340+
compatibleRequest.setOptions(compatibleOptions);
341+
compatibleRequest.setEntity(
342+
buildSettingsRequest(Collections.singletonList(TestDeprecationHeaderRestAction.TEST_DEPRECATED_SETTING_TRUE1), true)
343+
);
344+
Response deprecatedApiResponse = client().performRequest(compatibleRequest);
345+
assertOK(deprecatedApiResponse);
346+
347+
final List<String> deprecatedWarnings = getWarningHeaders(deprecatedApiResponse.getHeaders());
348+
final List<String> actualWarningValues = deprecatedWarnings.stream()
349+
.map(s -> HeaderWarning.extractWarningValueFromWarningHeader(s, true))
350+
.collect(Collectors.toList());
351+
assertThat(
352+
actualWarningValues,
353+
containsInAnyOrder(TestDeprecationHeaderRestAction.DEPRECATED_ENDPOINT, TestDeprecationHeaderRestAction.DEPRECATED_USAGE)
354+
);
355+
356+
assertBusy(() -> {
357+
Response response;
358+
try {
359+
client().performRequest(new Request("POST", "/" + DATA_STREAM_NAME + "/_refresh?ignore_unavailable=true"));
360+
response = client().performRequest(new Request("GET", "/" + DATA_STREAM_NAME + "/_search"));
247361
} catch (Exception e) {
248362
// It can take a moment for the index to be created. If it doesn't exist then the client
249363
// throws an exception. Translate it into an assertion error so that assertBusy() will
@@ -263,7 +377,7 @@ public void testDeprecationMessagesCanBeIndexed() throws Exception {
263377
for (int i = 0; i < hits; i++) {
264378
final JsonNode hit = jsonNode.at("/hits/hits/" + i + "/_source");
265379

266-
final Map<String, Object> document = new HashMap<>();
380+
final Map<String, Object> document = new TreeMap<>();
267381
hit.fields().forEachRemaining(entry -> document.put(entry.getKey(), entry.getValue().textValue()));
268382

269383
documents.add(document);
@@ -280,14 +394,15 @@ public void testDeprecationMessagesCanBeIndexed() throws Exception {
280394
hasKey("elasticsearch.cluster.name"),
281395
hasKey("elasticsearch.cluster.uuid"),
282396
hasEntry("elasticsearch.http.request.x_opaque_id", "some xid"),
397+
hasEntry("elasticsearch.event.category", "other"),
283398
hasKey("elasticsearch.node.id"),
284399
hasKey("elasticsearch.node.name"),
285-
hasEntry("data_stream.dataset", "elasticsearch.deprecation"),
400+
hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
286401
hasEntry("data_stream.namespace", "default"),
287402
hasEntry("data_stream.type", "logs"),
288403
hasEntry("ecs.version", "1.7"),
289404
hasEntry("event.code", "deprecated_settings"),
290-
hasEntry("event.dataset", "elasticsearch.deprecation"),
405+
hasEntry("event.dataset", "deprecation.elasticsearch"),
291406
hasEntry("log.level", "DEPRECATION"),
292407
hasKey("log.logger"),
293408
hasEntry("message", "[deprecated_settings] usage is deprecated. use [settings] instead")
@@ -297,14 +412,15 @@ public void testDeprecationMessagesCanBeIndexed() throws Exception {
297412
hasKey("elasticsearch.cluster.name"),
298413
hasKey("elasticsearch.cluster.uuid"),
299414
hasEntry("elasticsearch.http.request.x_opaque_id", "some xid"),
415+
hasEntry("elasticsearch.event.category", "api"),
300416
hasKey("elasticsearch.node.id"),
301417
hasKey("elasticsearch.node.name"),
302-
hasEntry("data_stream.dataset", "elasticsearch.deprecation"),
418+
hasEntry("data_stream.dataset", "deprecation.elasticsearch"),
303419
hasEntry("data_stream.namespace", "default"),
304420
hasEntry("data_stream.type", "logs"),
305421
hasEntry("ecs.version", "1.7"),
306422
hasEntry("event.code", "deprecated_route"),
307-
hasEntry("event.dataset", "elasticsearch.deprecation"),
423+
hasEntry("event.dataset", "deprecation.elasticsearch"),
308424
hasEntry("log.level", "DEPRECATION"),
309425
hasKey("log.logger"),
310426
hasEntry("message", "[/_test_cluster/deprecated_settings] exists for deprecated tests")
@@ -314,7 +430,7 @@ public void testDeprecationMessagesCanBeIndexed() throws Exception {
314430
}, 30, TimeUnit.SECONDS);
315431
} finally {
316432
configureWriteDeprecationLogsToIndex(null);
317-
client().performRequest(new Request("DELETE", "/_data_stream/.logs-deprecation-elasticsearch?expand_wildcards=hidden"));
433+
client().performRequest(new Request("DELETE", "_data_stream/" + DATA_STREAM_NAME + "?expand_wildcards=hidden"));
318434
}
319435
}
320436

0 commit comments

Comments
 (0)