|
6 | 6 | package org.elasticsearch.xpack.deprecation;
|
7 | 7 |
|
8 | 8 | import org.elasticsearch.Version;
|
| 9 | +import org.elasticsearch.action.ingest.PutPipelineRequest; |
9 | 10 | import org.elasticsearch.cluster.ClusterName;
|
10 | 11 | import org.elasticsearch.cluster.ClusterState;
|
11 | 12 | import org.elasticsearch.cluster.metadata.IndexMetaData;
|
12 | 13 | import org.elasticsearch.cluster.metadata.MetaData;
|
13 | 14 | import org.elasticsearch.cluster.node.DiscoveryNode;
|
14 | 15 | import org.elasticsearch.cluster.node.DiscoveryNodes;
|
| 16 | +import org.elasticsearch.common.bytes.BytesArray; |
15 | 17 | import org.elasticsearch.common.settings.Settings;
|
16 | 18 | import org.elasticsearch.common.transport.TransportAddress;
|
| 19 | +import org.elasticsearch.common.xcontent.XContentType; |
| 20 | +import org.elasticsearch.ingest.IngestService; |
17 | 21 | import org.elasticsearch.test.ESTestCase;
|
18 | 22 | import org.elasticsearch.xpack.core.deprecation.DeprecationIssue;
|
19 | 23 |
|
@@ -83,4 +87,57 @@ public void testCheckShardLimit() {
|
83 | 87 | issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(goodState));
|
84 | 88 | assertTrue(issues.isEmpty());
|
85 | 89 | }
|
| 90 | + |
| 91 | + public void testUserAgentEcsCheck() { |
| 92 | + PutPipelineRequest ecsFalseRequest = new PutPipelineRequest("ecs_false", |
| 93 | + new BytesArray("{\n" + |
| 94 | + " \"description\" : \"This has ecs set to false\",\n" + |
| 95 | + " \"processors\" : [\n" + |
| 96 | + " {\n" + |
| 97 | + " \"user_agent\" : {\n" + |
| 98 | + " \"field\" : \"agent\",\n" + |
| 99 | + " \"ecs\" : false\n" + |
| 100 | + " }\n" + |
| 101 | + " }\n" + |
| 102 | + " ]\n" + |
| 103 | + "}"), XContentType.JSON); |
| 104 | + PutPipelineRequest ecsNullRequest = new PutPipelineRequest("ecs_null", |
| 105 | + new BytesArray("{\n" + |
| 106 | + " \"description\" : \"This has ecs set to false\",\n" + |
| 107 | + " \"processors\" : [\n" + |
| 108 | + " {\n" + |
| 109 | + " \"user_agent\" : {\n" + |
| 110 | + " \"field\" : \"agent\"\n" + |
| 111 | + " }\n" + |
| 112 | + " }\n" + |
| 113 | + " ]\n" + |
| 114 | + "}"), XContentType.JSON); |
| 115 | + PutPipelineRequest ecsTrueRequest = new PutPipelineRequest("ecs_true", |
| 116 | + new BytesArray("{\n" + |
| 117 | + " \"description\" : \"This has ecs set to false\",\n" + |
| 118 | + " \"processors\" : [\n" + |
| 119 | + " {\n" + |
| 120 | + " \"user_agent\" : {\n" + |
| 121 | + " \"field\" : \"agent\",\n" + |
| 122 | + " \"ecs\" : true\n" + |
| 123 | + " }\n" + |
| 124 | + " }\n" + |
| 125 | + " ]\n" + |
| 126 | + "}"), XContentType.JSON); |
| 127 | + |
| 128 | + ClusterState state = ClusterState.builder(new ClusterName("test")).build(); |
| 129 | + state = IngestService.innerPut(ecsTrueRequest, state); |
| 130 | + state = IngestService.innerPut(ecsFalseRequest, state); |
| 131 | + state = IngestService.innerPut(ecsNullRequest, state); |
| 132 | + |
| 133 | + final ClusterState finalState = state; |
| 134 | + List<DeprecationIssue> issues = DeprecationChecks.filterChecks(CLUSTER_SETTINGS_CHECKS, c -> c.apply(finalState)); |
| 135 | + |
| 136 | + DeprecationIssue expected = new DeprecationIssue(DeprecationIssue.Level.WARNING, |
| 137 | + "User-Agent ingest plugin will use ECS-formatted output", |
| 138 | + "https://www.elastic.co/guide/en/elasticsearch/reference/master/breaking-changes-7.0.html" + |
| 139 | + "#ingest-user-agent-ecs-always", |
| 140 | + "Ingest pipelines [ecs_false, ecs_null] will change to using ECS output format in 7.0"); |
| 141 | + assertEquals(singletonList(expected), issues); |
| 142 | + } |
86 | 143 | }
|
0 commit comments