Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fix, datasource API should be case sensitive #2198

Merged
merged 5 commits into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ 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,46 @@ 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());
}
}
Loading