-
Notifications
You must be signed in to change notification settings - Fork 211
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
Select require_alias for OS bulk inserts from ISM Policy #3560
Changes from all commits
b3ed247
d4a2f6a
05fcfe3
7bba080
03fad8b
63d6bbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,8 @@ | |
import org.opensearch.client.opensearch.cluster.GetClusterSettingsRequest; | ||
import org.opensearch.client.opensearch.cluster.GetClusterSettingsResponse; | ||
import org.opensearch.client.opensearch.indices.CreateIndexRequest; | ||
import org.opensearch.client.opensearch.indices.ExistsAliasRequest; | ||
import org.opensearch.client.transport.endpoints.BooleanResponse; | ||
import org.opensearch.dataprepper.model.plugin.InvalidPluginConfigurationException; | ||
import org.opensearch.dataprepper.plugins.sink.opensearch.OpenSearchSinkConfiguration; | ||
import org.slf4j.Logger; | ||
|
@@ -50,6 +52,8 @@ public abstract class AbstractIndexManager implements IndexManager { | |
protected IsmPolicyManagementStrategy ismPolicyManagementStrategy; | ||
private final TemplateStrategy templateStrategy; | ||
protected String indexPrefix; | ||
private Boolean isIndexAlias; | ||
private boolean isIndexAliasChecked; | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(AbstractIndexManager.class); | ||
|
||
|
@@ -112,6 +116,10 @@ public static String getIndexAliasWithDate(final String indexAlias) { | |
return indexAlias.replaceAll(TIME_PATTERN_REGULAR_EXPRESSION, "") + suffix; | ||
} | ||
|
||
private void initalizeIsIndexAlias(final String indexAlias) { | ||
|
||
} | ||
|
||
private void initializeIndexPrefixAndSuffix(final String indexAlias){ | ||
final DateTimeFormatter dateFormatter = getDatePatternFormatter(indexAlias); | ||
if (dateFormatter != null) { | ||
|
@@ -176,6 +184,26 @@ public static ZonedDateTime getCurrentUtcTime() { | |
return LocalDateTime.now().atZone(ZoneId.systemDefault()).withZoneSameInstant(UTC_ZONE_ID); | ||
} | ||
|
||
@Override | ||
public Boolean isIndexAlias(final String dynamicIndexAlias) throws IOException { | ||
if (isIndexAliasChecked == false) { | ||
try { | ||
// Try to get the OpenSearch version. This fails on older OpenDistro versions, that do not support | ||
// `require_alias` as a bulk API parameter. All OpenSearch versions do, as this was introduced in | ||
// ES 7.10. | ||
openSearchClient.info(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dlvenable from this object, you can get the OpenSearch version as a String. For this feature, it is enough to detect OpenSearch. For other use-cases, you might want to extend this detection, so that you can ask for a required minimum version. But this requires parsing the version string. |
||
ExistsAliasRequest request = new ExistsAliasRequest.Builder().name(dynamicIndexAlias).build(); | ||
BooleanResponse response = openSearchClient.indices().existsAlias(request); | ||
isIndexAlias = response.value() && checkISMEnabled(); | ||
} catch (RuntimeException ex) { | ||
isIndexAlias = null; | ||
} finally { | ||
isIndexAliasChecked = true; | ||
} | ||
} | ||
return isIndexAlias; | ||
} | ||
|
||
final boolean checkISMEnabled() throws IOException { | ||
final GetClusterSettingsRequest request = new GetClusterSettingsRequest.Builder() | ||
.includeDefaults(true) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any situations in which the require_alias would vary from document to document? If so, we'd want this on the individual operations. I'm currently not setting any such situations, but I may be missing one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to https://opensearch.org/docs/2.11/api-reference/document-apis/bulk/#url-parameters,
require_alias
is a URL parameter of the bulk request. As such it cannot be changed for each document but only for the entire request.If you wanted this setting to be depending on the document, you would have to group documents with different settings into different bulk requests. In any case, you would need a configuration on event level, that carries the alias configuration. That could either be the event or the record metadata. Both can easily be accessed in the OpenSearchSink#doOutput to create different bulk requests. This would be a much larger change, also requiring a decision on how to set the alias configuration for the event.