Skip to content

Commit

Permalink
Bug fix, datasource API should be case sensitive (#2198)
Browse files Browse the repository at this point in the history
* Bug fix, datasource API should be case sensitive

Signed-off-by: Peng Huo <[email protected]>

* fix format

Signed-off-by: Peng Huo <[email protected]>

* fix format

Signed-off-by: Peng Huo <[email protected]>

* fix IT

Signed-off-by: Peng Huo <[email protected]>

---------

Signed-off-by: Peng Huo <[email protected]>
(cherry picked from commit 79cac7d)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Oct 3, 2023
1 parent a88142c commit 786d163
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ public Optional<DataSourceMetadata> 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));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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());
}
}

0 comments on commit 786d163

Please sign in to comment.