Skip to content

Commit a611740

Browse files
authored
fix: error syntax in log-standard-template (#6647)
fix: error syntax in template (logs-otel-v1-index-standard-template) Signed-off-by: Jongmin Chung <chungjm0711@gmail.com>
1 parent c95a9e3 commit a611740

2 files changed

Lines changed: 68 additions & 3 deletions

File tree

data-prepper-plugins/opensearch/src/integrationTest/java/org/opensearch/dataprepper/plugins/sink/opensearch/OpenSearchSinkIT.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.opensearch.dataprepper.plugins.sink.opensearch.index.IndexConfiguration;
5858
import org.opensearch.dataprepper.plugins.sink.opensearch.index.IndexConstants;
5959
import org.opensearch.dataprepper.plugins.sink.opensearch.index.IndexType;
60+
import org.opensearch.dataprepper.plugins.sink.opensearch.index.TemplateType;
6061

6162
import javax.ws.rs.HttpMethod;
6263
import java.io.BufferedReader;
@@ -339,6 +340,71 @@ void testInstantiateSinkLogsDefaultLogSink() throws IOException {
339340
}
340341
}
341342

343+
@Test
344+
@DisabledIf(value = "isES6", disabledReason = LOG_INGESTION_TEST_DISABLED_REASON)
345+
@Timeout(value = 50, unit = TimeUnit.SECONDS)
346+
void testInstantiateSinkLogsPlainWithTemplateTypeUsesIndexType() throws IOException {
347+
final OpenSearchSinkConfig openSearchSinkConfig = generateOpenSearchSinkConfig(
348+
IndexType.LOG_ANALYTICS_PLAIN.getValue(),
349+
null,
350+
TemplateType.INDEX_TEMPLATE.getTypeName(),
351+
null);
352+
OpenSearchSink sink = createObjectUnderTest(openSearchSinkConfig, true);
353+
354+
final String indexAlias = IndexConstants.TYPE_TO_DEFAULT_ALIAS.get(IndexType.LOG_ANALYTICS_PLAIN);
355+
final String expectedIndexTemplateName = indexAlias + "-index-template";
356+
357+
// Verify composable index template is created
358+
Request getTemplateRequest = new Request(HttpMethod.GET, "/_index_template/" + expectedIndexTemplateName);
359+
Response getTemplateResponse = client.performRequest(getTemplateRequest);
360+
assertThat(getTemplateResponse.getStatusLine().getStatusCode(), equalTo(SC_OK));
361+
String getTemplateResponseBody = EntityUtils.toString(getTemplateResponse.getEntity());
362+
@SuppressWarnings("unchecked") final List<Map<String, Map<String, Object>>> indexTemplates =
363+
(List<Map<String, Map<String, Object>>>) createContentParser(XContentType.JSON.xContent(), getTemplateResponseBody)
364+
.map().get("index_templates");
365+
assertThat(indexTemplates, notNullValue());
366+
assertThat(indexTemplates.isEmpty(), equalTo(false));
367+
@SuppressWarnings("unchecked") final List<String> indexPatterns =
368+
(List<String>) indexTemplates.get(0).get("index_template").get("index_patterns");
369+
assertThat(indexPatterns, hasItem(indexAlias + "-*"));
370+
371+
Request request = new Request(HttpMethod.HEAD, indexAlias);
372+
Response response = client.performRequest(request);
373+
assertThat(response.getStatusLine().getStatusCode(), equalTo(SC_OK));
374+
375+
final String index = String.format("%s-000001", indexAlias);
376+
final Map<String, Object> mappings = getIndexMappings(index);
377+
assertThat(mappings, notNullValue());
378+
assertThat((boolean) mappings.get("date_detection"), equalTo(false));
379+
380+
if (isOSBundle()) {
381+
await().atMost(2, TimeUnit.SECONDS).untilAsserted(() -> {
382+
assertThat(getIndexPolicyId(index), equalTo(IndexConstants.LOGS_ISM_POLICY));
383+
}
384+
);
385+
}
386+
387+
// roll over initial index
388+
request = new Request(HttpMethod.POST, String.format("%s/_rollover", indexAlias));
389+
request.setJsonEntity("{ \"conditions\" : { } }\n");
390+
response = client.performRequest(request);
391+
assertThat(response.getStatusLine().getStatusCode(), equalTo(SC_OK));
392+
393+
// Instantiate sink again
394+
sink = createObjectUnderTest(openSearchSinkConfig, true);
395+
// Make sure no new write index *-000001 is created under alias
396+
final String rolloverIndexName = String.format("%s-000002", indexAlias);
397+
request = new Request(HttpMethod.GET, rolloverIndexName + "/_alias");
398+
response = client.performRequest(request);
399+
assertThat(checkIsWriteIndex(EntityUtils.toString(response.getEntity()), indexAlias, rolloverIndexName), equalTo(true));
400+
401+
if (isOSBundle()) {
402+
await().atMost(1, TimeUnit.SECONDS).untilAsserted(() ->
403+
assertThat(getIndexPolicyId(rolloverIndexName), equalTo(IndexConstants.LOGS_ISM_POLICY))
404+
);
405+
}
406+
}
407+
342408
@Test
343409
@DisabledIf(value = "isES6", disabledReason = METRIC_INGESTION_TEST_DISABLED_REASON)
344410
@Timeout(value = 50, unit = TimeUnit.SECONDS)

data-prepper-plugins/opensearch/src/main/resources/index-template/logs-otel-v1-index-standard-template.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
},
134134
"text": {
135135
"type": "keyword",
136-
"ignore_above": "32"
136+
"ignore_above": 32
137137
}
138138
}
139139
},
@@ -147,7 +147,7 @@
147147
"type": "date_nanos"
148148
},
149149
"observedTime": {
150-
"path": "date_nanos"
150+
"type": "date_nanos"
151151
},
152152
"traceId": {
153153
"type": "keyword",
@@ -164,4 +164,3 @@
164164
}
165165
}
166166
}
167-

0 commit comments

Comments
 (0)