Skip to content

Commit 4456c0c

Browse files
author
Hendrik Muhs
authored
audit index creation after it the index has been created (#51479)
moves audit message for index creation after the index has been successfully created. This has been confusing for a user where index creation failed but audit reported index creation.
1 parent e5dd459 commit 4456c0c

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/action/TransportStartTransformAction.java

+14-17
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ protected void masterOperation(
183183
}, listener::onFailure);
184184

185185
// <4> Create the task in cluster state so that it will start executing on the node
186-
ActionListener<Void> createOrGetIndexListener = ActionListener.wrap(unused -> {
186+
ActionListener<Boolean> createOrGetIndexListener = ActionListener.wrap(unused -> {
187187
TransformTaskParams transformTask = transformTaskHolder.get();
188188
assert transformTask != null;
189189
PersistentTasksCustomMetaData.PersistentTask<TransformTaskParams> existingTask = getExistingTask(transformTask.getId(), state);
@@ -224,8 +224,10 @@ protected void masterOperation(
224224
String[] dest = indexNameExpressionResolver.concreteIndexNames(state, IndicesOptions.lenientExpandOpen(), destinationIndex);
225225

226226
if (dest.length == 0) {
227-
auditor.info(request.getId(), "Creating destination index [" + destinationIndex + "] with deduced mappings.");
228-
createDestinationIndex(transformConfigHolder.get(), createOrGetIndexListener);
227+
createDestinationIndex(transformConfigHolder.get(), ActionListener.wrap(r -> {
228+
auditor.info(request.getId(), "Created destination index [" + destinationIndex + "] with deduced mappings.");
229+
createOrGetIndexListener.onResponse(r);
230+
}, createOrGetIndexListener::onFailure));
229231
} else {
230232
auditor.info(request.getId(), "Using existing destination index [" + destinationIndex + "].");
231233
ClientHelper.executeAsyncWithOrigin(
@@ -240,12 +242,12 @@ protected void masterOperation(
240242
"Non-empty destination index [" + destinationIndex + "]. " + "Contains [" + docTotal + "] total documents."
241243
);
242244
}
243-
createOrGetIndexListener.onResponse(null);
245+
createOrGetIndexListener.onResponse(true);
244246
}, e -> {
245247
String msg = "Unable to determine destination index stats, error: " + e.getMessage();
246-
logger.error(msg, e);
248+
logger.warn(msg, e);
247249
auditor.warning(request.getId(), msg);
248-
createOrGetIndexListener.onResponse(null);
250+
createOrGetIndexListener.onResponse(true);
249251
}),
250252
client.admin().indices()::stats
251253
);
@@ -267,9 +269,10 @@ protected void masterOperation(
267269
transformConfigHolder.set(config);
268270
if (config.getDestination().getPipeline() != null) {
269271
if (ingestService.getPipeline(config.getDestination().getPipeline()) == null) {
270-
listener.onFailure(new ElasticsearchStatusException(
271-
TransformMessages.getMessage(TransformMessages.PIPELINE_MISSING, config.getDestination().getPipeline()),
272-
RestStatus.BAD_REQUEST
272+
listener.onFailure(
273+
new ElasticsearchStatusException(
274+
TransformMessages.getMessage(TransformMessages.PIPELINE_MISSING, config.getDestination().getPipeline()),
275+
RestStatus.BAD_REQUEST
273276
)
274277
);
275278
return;
@@ -289,18 +292,12 @@ protected void masterOperation(
289292
transformConfigManager.getTransformConfiguration(request.getId(), getTransformListener);
290293
}
291294

292-
private void createDestinationIndex(final TransformConfig config, final ActionListener<Void> listener) {
295+
private void createDestinationIndex(final TransformConfig config, final ActionListener<Boolean> listener) {
293296

294297
final Pivot pivot = new Pivot(config.getPivotConfig());
295298

296299
ActionListener<Map<String, String>> deduceMappingsListener = ActionListener.wrap(
297-
mappings -> TransformIndex.createDestinationIndex(
298-
client,
299-
Clock.systemUTC(),
300-
config,
301-
mappings,
302-
ActionListener.wrap(r -> listener.onResponse(null), listener::onFailure)
303-
),
300+
mappings -> TransformIndex.createDestinationIndex(client, Clock.systemUTC(), config, mappings, listener),
304301
deduceTargetMappingsException -> listener.onFailure(
305302
new RuntimeException(TransformMessages.REST_PUT_TRANSFORM_FAILED_TO_DEDUCE_DEST_MAPPINGS, deduceTargetMappingsException)
306303
)

0 commit comments

Comments
 (0)