Skip to content

Commit

Permalink
Fix integration tests
Browse files Browse the repository at this point in the history
The specific user used in some tests of OpenSerachSinkIT
needs get permissions on all aliases to test for their existence.
Another bug with determining the alias name is fixed as well.

As a final result, the DataPrepper OpenSearch user requires
write access to the indices and now additionally read access to
the aliases. This can be a change for self-managed indices.

Signed-off-by: Karsten Schnitter <k.schnitter@sap.com>
  • Loading branch information
KarstenSchnitter committed Nov 7, 2023
1 parent 05fcfe3 commit 7bba080
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ private void createRole(final String role, final String indexPattern, final Stri
.array("index_patterns", new String[]{indexPattern})
.array("allowed_actions", allowedActions)
.endObject()
.startObject()
.array("index_patterns", new String[]{"*"})
.array("allowed_actions", "indices:admin/aliases/get")
.endObject()
.endArray()
.endObject()
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private void doInitializeInternal() throws IOException {
}
indexManager.setupIndex();

boolean requireAlias = indexManager.isIndexAlias();
boolean requireAlias = indexManager.isIndexAlias(configuredIndexAlias);
final boolean isEstimateBulkSizeUsingCompression = openSearchSinkConfig.getIndexConfiguration().isEstimateBulkSizeUsingCompression();
final boolean isRequestCompressionEnabled = openSearchSinkConfig.getConnectionConfiguration().isRequestCompressionEnabled();
if (isEstimateBulkSizeUsingCompression && isRequestCompressionEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,9 @@ public static ZonedDateTime getCurrentUtcTime() {
}

@Override
public boolean isIndexAlias() throws IOException {
public boolean isIndexAlias(final String dynamicIndexAlias) throws IOException {
if (isIndexAlias == null) {
String indexAlias = getIndexName(null);
ExistsAliasRequest request = new ExistsAliasRequest.Builder().name(indexAlias).build();
ExistsAliasRequest request = new ExistsAliasRequest.Builder().name(dynamicIndexAlias).build();
BooleanResponse response = openSearchClient.indices().existsAlias(request);
isIndexAlias = response.value() && checkISMEnabled();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ public interface IndexManager{

void setupIndex() throws IOException;
String getIndexName(final String indexAlias) throws IOException;
boolean isIndexAlias() throws IOException;
boolean isIndexAlias(final String indexAlias) throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void isIndexAlias_True() throws IOException {
IndexType.CUSTOM, openSearchClient, restHighLevelClient, openSearchSinkConfiguration, templateStrategy);
when(openSearchIndicesClient.existsAlias(any(ExistsAliasRequest.class))).thenReturn(new BooleanResponse(true));
when(clusterSettingsParser.getStringValueClusterSetting(any(GetClusterSettingsResponse.class), anyString())).thenReturn("true");
assertEquals(true, defaultIndexManager.isIndexAlias());
assertEquals(true, defaultIndexManager.isIndexAlias(INDEX_ALIAS));
verify(openSearchSinkConfiguration, times(2)).getIndexConfiguration();
verify(indexConfiguration).getIsmPolicyFile();
verify(indexConfiguration).getIndexAlias();
Expand All @@ -335,7 +335,7 @@ void isIndexAlias_False_NoAlias() throws IOException {
defaultIndexManager = indexManagerFactory.getIndexManager(
IndexType.CUSTOM, openSearchClient, restHighLevelClient, openSearchSinkConfiguration, templateStrategy);
when(openSearchIndicesClient.existsAlias(any(ExistsAliasRequest.class))).thenReturn(new BooleanResponse(false));
assertEquals(false, defaultIndexManager.isIndexAlias());
assertEquals(false, defaultIndexManager.isIndexAlias(INDEX_ALIAS));
verify(openSearchSinkConfiguration, times(2)).getIndexConfiguration();
verify(indexConfiguration).getIsmPolicyFile();
verify(indexConfiguration).getIndexAlias();
Expand All @@ -349,7 +349,7 @@ void isIndexAlias_False_NoISM() throws IOException {
IndexType.CUSTOM, openSearchClient, restHighLevelClient, openSearchSinkConfiguration, templateStrategy);
when(openSearchIndicesClient.existsAlias(any(ExistsAliasRequest.class))).thenReturn(new BooleanResponse(true));
when(clusterSettingsParser.getStringValueClusterSetting(any(GetClusterSettingsResponse.class), anyString())).thenReturn("false");
assertEquals(false, defaultIndexManager.isIndexAlias());
assertEquals(false, defaultIndexManager.isIndexAlias(INDEX_ALIAS));
verify(openSearchSinkConfiguration, times(2)).getIndexConfiguration();
verify(indexConfiguration).getIsmPolicyFile();
verify(indexConfiguration).getIndexAlias();
Expand Down

0 comments on commit 7bba080

Please sign in to comment.