From 786d1638c88cee9f6ce417fb295d7d5abfec2f7d Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 3 Oct 2023 22:59:17 +0000 Subject: [PATCH] Bug fix, datasource API should be case sensitive (#2198) * Bug fix, datasource API should be case sensitive Signed-off-by: Peng Huo * fix format Signed-off-by: Peng Huo * fix format Signed-off-by: Peng Huo * fix IT Signed-off-by: Peng Huo --------- Signed-off-by: Peng Huo (cherry picked from commit 79cac7dd6a9d0c6abdc3d29ebc959ef68dcae8f3) Signed-off-by: github-actions[bot] --- .../OpenSearchDataSourceMetadataStorage.java | 4 +- .../sql/datasource/DataSourceAPIsIT.java | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java index 5f5e087ce0..6d75c2367f 100644 --- a/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java +++ b/datasources/src/main/java/org/opensearch/sql/datasources/storage/OpenSearchDataSourceMetadataStorage.java @@ -93,7 +93,9 @@ public Optional getDataSourceMetadata(String datasourceName) createDataSourcesIndex(); return Optional.empty(); } - return searchInDataSourcesIndex(QueryBuilders.termQuery("name", datasourceName)).stream() + // todo, in case docId == datasourceName, could read doc directly. + return searchInDataSourcesIndex(QueryBuilders.termQuery("name.keyword", datasourceName)) + .stream() .findFirst() .map(x -> this.encryptDecryptAuthenticationData(x, false)); } diff --git a/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java index b5f7fb0e54..0635c6581b 100644 --- a/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java +++ b/integ-test/src/test/java/org/opensearch/sql/datasource/DataSourceAPIsIT.java @@ -42,6 +42,10 @@ protected static void deleteDataSourcesCreated() throws IOException { deleteRequest = getDeleteDataSourceRequest("get_all_prometheus"); deleteResponse = client().performRequest(deleteRequest); Assert.assertEquals(204, deleteResponse.getStatusLine().getStatusCode()); + + deleteRequest = getDeleteDataSourceRequest("Create_Prometheus"); + deleteResponse = client().performRequest(deleteRequest); + Assert.assertEquals(204, deleteResponse.getStatusLine().getStatusCode()); } @SneakyThrows @@ -191,4 +195,44 @@ public void getAllDataSourceTest() { Assert.assertTrue( dataSourceMetadataList.stream().anyMatch(ds -> ds.getName().equals("get_all_prometheus"))); } + + /** https://github.com/opensearch-project/sql/issues/2196 */ + @SneakyThrows + @Test + public void issue2196() { + // create datasource + DataSourceMetadata createDSM = + new DataSourceMetadata( + "Create_Prometheus", + "Prometheus Creation for Integ test", + DataSourceType.PROMETHEUS, + ImmutableList.of(), + ImmutableMap.of( + "prometheus.uri", + "https://localhost:9090", + "prometheus.auth.type", + "basicauth", + "prometheus.auth.username", + "username", + "prometheus.auth.password", + "password")); + Request createRequest = getCreateDataSourceRequest(createDSM); + Response response = client().performRequest(createRequest); + Assert.assertEquals(201, response.getStatusLine().getStatusCode()); + String createResponseString = getResponseBody(response); + Assert.assertEquals("\"Created DataSource with name Create_Prometheus\"", createResponseString); + // Datasource is not immediately created. so introducing a sleep of 2s. + Thread.sleep(2000); + + // get datasource to validate the creation. + Request getRequest = getFetchDataSourceRequest("Create_Prometheus"); + Response getResponse = client().performRequest(getRequest); + Assert.assertEquals(200, getResponse.getStatusLine().getStatusCode()); + String getResponseString = getResponseBody(getResponse); + DataSourceMetadata dataSourceMetadata = + new Gson().fromJson(getResponseString, DataSourceMetadata.class); + Assert.assertEquals( + "https://localhost:9090", dataSourceMetadata.getProperties().get("prometheus.uri")); + Assert.assertEquals("Prometheus Creation for Integ test", dataSourceMetadata.getDescription()); + } }