Skip to content

Commit

Permalink
Fix tests and add in rst
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed Oct 12, 2023
1 parent e86794a commit 9384f8c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testDoExecute() {
.onResponse(patchDataSourceActionResponseArgumentCaptor.capture());
PatchDataSourceActionResponse patchDataSourceActionResponse =
patchDataSourceActionResponseArgumentCaptor.getValue();
String responseAsJson = "\"Created DataSource with name test_datasource\"";
String responseAsJson = "\"Updated DataSource with name test_datasource\"";
Assertions.assertEquals(responseAsJson, patchDataSourceActionResponse.getResult());
}

Expand Down
11 changes: 11 additions & 0 deletions docs/user/ppl/admin/datasources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,17 @@ we can remove authorization and other details in case of security disabled domai
"allowedRoles" : ["prometheus_access"]
}

* Datasource modification PATCH API ("_plugins/_query/_datasources") ::

PATCH https://localhost:9200/_plugins/_query/_datasources
content-type: application/json
Authorization: Basic {{username}} {{password}}

{
"name" : "my_prometheus",
"allowedRoles" : ["all_access"]
}

* Datasource Read GET API("_plugins/_query/_datasources/{{dataSourceName}}" ::

GET https://localhost:9200/_plugins/_query/_datasources/my_prometheus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,22 +141,22 @@ public void updateDataSourceAPITest() {
Map<String, Object> updateDS =
new HashMap<>(Map.of(NAME_FIELD, "update_prometheus", DESCRIPTION_FIELD, "test"));
Request patchRequest = getPatchDataSourceRequest(updateDS);
Response patchResponse = client().performRequest(updateRequest);
Response patchResponse = client().performRequest(patchRequest);
Assert.assertEquals(200, patchResponse.getStatusLine().getStatusCode());
String patchResponseString = getResponseBody(updateResponse);
Assert.assertEquals("\"Updated DataSource with name update_prometheus\"", updateResponseString);
Assert.assertEquals("\"Updated DataSource with name update_prometheus\"", patchResponseString);

// Datasource is not immediately updated. so introducing a sleep of 2s.
Thread.sleep(2000);

// get datasource to validate the modification.
// get datasource
Request getRequestAfterPatch = getFetchDataSourceRequest("update_prometheus");
Response getResponseAfterPatch = client().performRequest(getRequest);
Assert.assertEquals(200, getResponse.getStatusLine().getStatusCode());
Response getResponseAfterPatch = client().performRequest(getRequestAfterPatch);
Assert.assertEquals(200, getResponseAfterPatch.getStatusLine().getStatusCode());
String getResponseStringAfterPatch = getResponseBody(getResponse);
DataSourceMetadata dataSourceMetadataAfterPatch =
new Gson().fromJson(getResponseString, DataSourceMetadata.class);
new Gson().fromJson(getResponseStringAfterPatch, DataSourceMetadata.class);
Assert.assertEquals(
"https://randomtest.com:9090",
dataSourceMetadataAfterPatch.getProperties().get("prometheus.uri"));
Expand Down

0 comments on commit 9384f8c

Please sign in to comment.