diff --git a/zipkin-storage/elasticsearch/src/test/java/zipkin2/elasticsearch/VersionSpecificTemplatesTest.java b/zipkin-storage/elasticsearch/src/test/java/zipkin2/elasticsearch/ElasticsearchSpecificTemplatesTest.java similarity index 87% rename from zipkin-storage/elasticsearch/src/test/java/zipkin2/elasticsearch/VersionSpecificTemplatesTest.java rename to zipkin-storage/elasticsearch/src/test/java/zipkin2/elasticsearch/ElasticsearchSpecificTemplatesTest.java index 13d925eb77..df784d3ca5 100644 --- a/zipkin-storage/elasticsearch/src/test/java/zipkin2/elasticsearch/VersionSpecificTemplatesTest.java +++ b/zipkin-storage/elasticsearch/src/test/java/zipkin2/elasticsearch/ElasticsearchSpecificTemplatesTest.java @@ -14,7 +14,7 @@ import static zipkin2.elasticsearch.ElasticsearchVersion.V7_0; import static zipkin2.elasticsearch.ElasticsearchVersion.V7_8; -class VersionSpecificTemplatesTest { +class ElasticsearchSpecificTemplatesTest { static final ElasticsearchVersion V2_4 = new ElasticsearchVersion(2, 4); static final ElasticsearchVersion V6_7 = new ElasticsearchVersion(6, 7); static final ElasticsearchVersion V7_9 = new ElasticsearchVersion(7, 9); @@ -243,4 +243,34 @@ class VersionSpecificTemplatesTest { assertThat(template.span()).contains("analysis"); } + + @Test void indexTemplatesUrl_6x() { + assertThat(VersionSpecificTemplates.forVersion(V6_7).indexTemplatesUrl("idx", "_doc", null)) + .isEqualTo("/_template/idx_doc_template?include_type_name=true"); + } + + @Test void indexTemplatesUrl_6x_withPriority() { + assertThat(VersionSpecificTemplates.forVersion(V6_7).indexTemplatesUrl("idx", "_doc", 1)) + .isEqualTo("/_template/idx_doc_template?include_type_name=true"); + } + + @Test void indexTemplatesUrl_78() { + assertThat(VersionSpecificTemplates.forVersion(V7_8).indexTemplatesUrl("idx", "_doc", null)) + .isEqualTo("/_template/idx_doc_template"); + } + + @Test void indexTemplatesUrl_78_withPriority() { + assertThat(VersionSpecificTemplates.forVersion(V7_8).indexTemplatesUrl("idx", "_doc", 1)) + .isEqualTo("/_index_template/idx_doc_template"); + } + + @Test void indexTemplatesUrl_79() { + assertThat(VersionSpecificTemplates.forVersion(V7_9).indexTemplatesUrl("idx", "_doc", null)) + .isEqualTo("/_template/idx_doc_template"); + } + + @Test void indexTemplatesUrl_79_withPriority() { + assertThat(VersionSpecificTemplates.forVersion(V7_9).indexTemplatesUrl("idx", "_doc", 1)) + .isEqualTo("/_index_template/idx_doc_template"); + } } diff --git a/zipkin-storage/elasticsearch/src/test/java/zipkin2/elasticsearch/OpensearchSpecificTemplatesTest.java b/zipkin-storage/elasticsearch/src/test/java/zipkin2/elasticsearch/OpensearchSpecificTemplatesTest.java new file mode 100644 index 0000000000..bd30af1c97 --- /dev/null +++ b/zipkin-storage/elasticsearch/src/test/java/zipkin2/elasticsearch/OpensearchSpecificTemplatesTest.java @@ -0,0 +1,116 @@ +/* + * Copyright The OpenZipkin Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package zipkin2.elasticsearch; + +import com.linecorp.armeria.client.WebClient; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; + +class OpensearchSpecificTemplatesTest { + static final OpensearchVersion V0_3 = new OpensearchVersion(0, 3); + static final OpensearchVersion V1_3 = new OpensearchVersion(1, 3); + static final OpensearchVersion V2_0 = new OpensearchVersion(2, 0); + + ElasticsearchStorage storage = + ElasticsearchStorage.newBuilder(() -> mock(WebClient.class)).build(); + + /** Unsupported, but we should test that parsing works */ + @Test void version_unsupported() { + assertThatThrownBy(() -> storage.versionSpecificTemplates(V0_3)) + .hasMessage("OpenSearch versions 1-3.x are supported, was: 0.3"); + } + + @Test void version2() { + IndexTemplates template = storage.versionSpecificTemplates(V2_0); + + assertThat(template.version()).isEqualTo(V2_0); + assertThat(template.autocomplete()) + .withFailMessage("Starting at v7.x, we delimit index and type with hyphen") + .contains("\"index_patterns\": \"zipkin-autocomplete-*\""); + assertThat(template.autocomplete()) + .withFailMessage("7.x does not support the key index.mapper.dynamic") + .doesNotContain("\"index.mapper.dynamic\": false"); + } + + @Test void version2_doesntWrapPropertiesWithType() { + IndexTemplates template = storage.versionSpecificTemplates(V2_0); + + assertThat(template.dependency()).contains(""" + "mappings": { + "enabled": false + }\ + """); + + assertThat(template.autocomplete()).contains(""" + "mappings": { + "enabled": true, + "properties": { + "tagKey": { "type": "keyword", "norms": false }, + "tagValue": { "type": "keyword", "norms": false } + } + }\ + """); + } + + @Test void searchEnabled_minimalSpanIndexing_1x() { + storage = ElasticsearchStorage.newBuilder(() -> mock(WebClient.class)) + .searchEnabled(false) + .build(); + + IndexTemplates template = storage.versionSpecificTemplates(V1_3); + + // doesn't wrap in a type name + assertThat(template.span()) + .contains(""" + "mappings": { + "properties": { + "traceId": { "type": "keyword", "norms": false }, + "annotations": { "enabled": false }, + "tags": { "enabled": false } + } + }\ + """); + } + + @Test void strictTraceId_doesNotIncludeAnalysisSection() { + IndexTemplates template = storage.versionSpecificTemplates(V1_3); + + assertThat(template.span()).doesNotContain("analysis"); + } + + @Test void strictTraceId_false_includesAnalysisForMixedLengthTraceId() { + storage.close(); + storage = ElasticsearchStorage.newBuilder(() -> mock(WebClient.class)) + .strictTraceId(false) + .build(); + + IndexTemplates template = storage.versionSpecificTemplates(V1_3); + + assertThat(template.span()).contains("analysis"); + } + + @Test void indexTemplatesUrl_1x() { + assertThat(VersionSpecificTemplates.forVersion(V1_3).indexTemplatesUrl("idx", "_doc", null)) + .isEqualTo("/_template/idx_doc_template"); + } + + @Test void indexTemplatesUrl_1x_withPriority() { + assertThat(VersionSpecificTemplates.forVersion(V1_3).indexTemplatesUrl("idx", "_doc", 1)) + .isEqualTo("/_index_template/idx_doc_template"); + } + + @Test void indexTemplatesUrl_2x() { + assertThat(VersionSpecificTemplates.forVersion(V2_0).indexTemplatesUrl("idx", "_doc", null)) + .isEqualTo("/_template/idx_doc_template"); + } + + @Test void indexTemplatesUrl_2x_withPriority() { + assertThat(VersionSpecificTemplates.forVersion(V2_0).indexTemplatesUrl("idx", "_doc", 1)) + .isEqualTo("/_index_template/idx_doc_template"); + } +}