Skip to content

Change policy runner to use helper method on EnrichPolicy instead of #41839

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -29,6 +29,8 @@
*/
public final class EnrichPolicy implements Writeable, ToXContentFragment {

private static final String ENRICH_INDEX_NAME_BASE = ".enrich-";

public static final String EXACT_MATCH_TYPE = "exact_match";
public static final String[] SUPPORTED_POLICY_TYPES = new String[]{EXACT_MATCH_TYPE};

Expand Down Expand Up @@ -130,9 +132,8 @@ public String getSchedule() {
return schedule;
}

public String getAliasName(String policyName) {
// #41553 (list policy api) will add name to policy, so that we don't have to provide the name via a parameter.
return ".enrich-" + policyName;
public String getBaseName(String policyName) {
return ENRICH_INDEX_NAME_BASE + policyName;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ public class EnrichPolicyRunner implements Runnable {

private static final Logger logger = LogManager.getLogger(EnrichPolicyRunner.class);

private static final String ENRICH_INDEX_NAME_BASE = ".enrich-";

private final String policyName;
private final EnrichPolicy policy;
private final ActionListener<PolicyExecutionResult> listener;
Expand Down Expand Up @@ -121,10 +119,6 @@ private void validateMappings(final GetIndexResponse getIndexResponse) {
}
}

private String getEnrichIndexBase(final String policyName) {
return ENRICH_INDEX_NAME_BASE + policyName;
}

private XContentBuilder resolveEnrichMapping(final EnrichPolicy policy) {
// Currently the only supported policy type is EnrichPolicy.EXACT_MATCH_TYPE, which is a keyword type
String keyType;
Expand Down Expand Up @@ -160,7 +154,7 @@ private XContentBuilder resolveEnrichMapping(final EnrichPolicy policy) {

private void prepareAndCreateEnrichIndex() {
long nowTimestamp = nowSupplier.getAsLong();
String enrichIndexName = getEnrichIndexBase(policyName) + "-" + nowTimestamp;
String enrichIndexName = policy.getBaseName(policyName) + "-" + nowTimestamp;
Settings enrichIndexSettings = Settings.builder()
.put("index.auto_expand_replicas", "0-all")
.build();
Expand Down Expand Up @@ -234,7 +228,7 @@ public void onFailure(Exception e) {
}

private void updateEnrichPolicyAlias(final String destinationIndexName) {
String enrichIndexBase = getEnrichIndexBase(policyName);
String enrichIndexBase = policy.getBaseName(policyName);
logger.debug("Policy [{}]: Promoting new enrich index [{}] to alias [{}]", policyName, destinationIndexName, enrichIndexBase);
GetAliasesRequest aliasRequest = new GetAliasesRequest(enrichIndexBase);
String[] concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterService.state(), aliasRequest);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public IngestDocument execute(IngestDocument ingestDocument) throws Exception {
}

// TODO: re-use the engine searcher between enriching documents from the same write request
try (Engine.Searcher engineSearcher = searchProvider.apply(policy.getAliasName(policyName))) {
try (Engine.Searcher engineSearcher = searchProvider.apply(policy.getBaseName(policyName))) {
if (engineSearcher.getDirectoryReader().leaves().size() == 0) {
return ingestDocument;
} else if (engineSearcher.getDirectoryReader().leaves().size() != 1) {
Expand Down