Skip to content

Commit 7cdbd3f

Browse files
authored
Refactored logging for consistency (#524)
* Remove stack traces and exception causes from logs Signed-off-by: Daniel Widdis <[email protected]> * Logs no longer reveal transport action names Signed-off-by: Daniel Widdis <[email protected]> * Rebase, remove unused param and logger, typo fix Signed-off-by: Daniel Widdis <[email protected]> * Add logging for all client Transport calls Signed-off-by: Daniel Widdis <[email protected]> * Add back stack traces in error logging for failed transport queries Signed-off-by: Daniel Widdis <[email protected]> * Add back in stack traces for other error messages outside transport Signed-off-by: Daniel Widdis <[email protected]> * Add id and other details to workflow step error messages Signed-off-by: Daniel Widdis <[email protected]> --------- Signed-off-by: Daniel Widdis <[email protected]>
1 parent 37a2869 commit 7cdbd3f

File tree

51 files changed

+495
-429
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+495
-429
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
2020
- Substitute REST path or body parameters in Workflow Steps ([#525](https://github.com/opensearch-project/flow-framework/pull/525))
2121
- Added an optional workflow_step param to the get workflow steps API ([#538](https://github.com/opensearch-project/flow-framework/pull/538))
2222

23+
### Enhancements
2324
### Bug Fixes
2425
### Infrastructure
2526
### Documentation
2627
### Maintenance
2728
### Refactoring
2829
- Moved workflow-steps.json to Enum ([#523](https://github.com/opensearch-project/flow-framework/pull/523))
30+
- Refactored logging for consistency ([#524](https://github.com/opensearch-project/flow-framework/pull/524))

src/main/java/org/opensearch/flowframework/indices/FlowFrameworkIndicesHandler.java

+43-52
Original file line numberDiff line numberDiff line change
@@ -180,19 +180,20 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe
180180
@SuppressWarnings("deprecation")
181181
ActionListener<CreateIndexResponse> actionListener = ActionListener.wrap(r -> {
182182
if (r.isAcknowledged()) {
183-
logger.info("create index:{}", indexName);
183+
logger.info("create index: {}", indexName);
184184
internalListener.onResponse(true);
185185
} else {
186186
internalListener.onResponse(false);
187187
}
188188
}, e -> {
189-
logger.error("Failed to create index {}", indexName, e);
190-
internalListener.onFailure(new FlowFrameworkException(e.getMessage(), ExceptionsHelper.status(e)));
189+
String errorMessage = "Failed to create index " + indexName;
190+
logger.error(errorMessage, e);
191+
internalListener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
191192
});
192193
CreateIndexRequest request = new CreateIndexRequest(indexName).mapping(mapping).settings(indexSettings);
193194
client.admin().indices().create(request, actionListener);
194195
} else {
195-
logger.debug("index:{} is already created", indexName);
196+
logger.debug("index: {} is already created", indexName);
196197
if (indexMappingUpdated.containsKey(indexName) && !indexMappingUpdated.get(indexName).get()) {
197198
shouldUpdateIndex(indexName, index.getVersion(), ActionListener.wrap(r -> {
198199
if (r) {
@@ -223,10 +224,7 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe
223224
String errorMessage = "Failed to update index setting for: " + indexName;
224225
logger.error(errorMessage, exception);
225226
internalListener.onFailure(
226-
new FlowFrameworkException(
227-
errorMessage + " : " + exception.getMessage(),
228-
ExceptionsHelper.status(exception)
229-
)
227+
new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))
230228
);
231229
}));
232230
} else {
@@ -238,10 +236,7 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe
238236
String errorMessage = "Failed to update index " + indexName;
239237
logger.error(errorMessage, exception);
240238
internalListener.onFailure(
241-
new FlowFrameworkException(
242-
errorMessage + " : " + exception.getMessage(),
243-
ExceptionsHelper.status(exception)
244-
)
239+
new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception))
245240
);
246241
})
247242
);
@@ -251,11 +246,9 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe
251246
internalListener.onResponse(true);
252247
}
253248
}, e -> {
254-
String errorMessage = "Failed to update index mapping";
249+
String errorMessage = "Failed to update index mapping for " + indexName;
255250
logger.error(errorMessage, e);
256-
internalListener.onFailure(
257-
new FlowFrameworkException(errorMessage + " : " + e.getMessage(), ExceptionsHelper.status(e))
258-
);
251+
internalListener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
259252
}));
260253
} else {
261254
// No need to update index if it's already updated.
@@ -265,7 +258,7 @@ public void initFlowFrameworkIndexIfAbsent(FlowFrameworkIndex index, ActionListe
265258
} catch (Exception e) {
266259
String errorMessage = "Failed to init index " + indexName;
267260
logger.error(errorMessage, e);
268-
listener.onFailure(new FlowFrameworkException(errorMessage + " : " + e.getMessage(), ExceptionsHelper.status(e)));
261+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
269262
}
270263
}
271264

@@ -328,11 +321,11 @@ public void putTemplateToGlobalContext(Template template, ActionListener<IndexRe
328321
client.index(request, ActionListener.runBefore(listener, context::restore));
329322
} catch (Exception e) {
330323
String errorMessage = "Failed to index global_context index";
331-
logger.error(errorMessage);
332-
listener.onFailure(new FlowFrameworkException(errorMessage + " : " + e.getMessage(), ExceptionsHelper.status(e)));
324+
logger.error(errorMessage, e);
325+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
333326
}
334327
}, e -> {
335-
logger.error("Failed to create global_context index", e);
328+
logger.error("Failed to create global_context index");
336329
listener.onFailure(e);
337330
}));
338331
}
@@ -349,7 +342,7 @@ public void initializeConfigIndex(ActionListener<Boolean> listener) {
349342
}
350343
encryptorUtils.initializeMasterKey(listener);
351344
}, createIndexException -> {
352-
logger.error("Failed to create config index", createIndexException);
345+
logger.error("Failed to create config index");
353346
listener.onFailure(createIndexException);
354347
}));
355348
}
@@ -385,13 +378,13 @@ public void putInitialStateToWorkflowState(String workflowId, User user, ActionL
385378
} catch (Exception e) {
386379
String errorMessage = "Failed to put state index document";
387380
logger.error(errorMessage, e);
388-
listener.onFailure(new FlowFrameworkException(errorMessage + " : " + e.getMessage(), ExceptionsHelper.status(e)));
381+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
389382
}
390383

391384
}, e -> {
392385
String errorMessage = "Failed to create workflow_state index";
393386
logger.error(errorMessage, e);
394-
listener.onFailure(new FlowFrameworkException(errorMessage + " : " + e.getMessage(), ExceptionsHelper.status(e)));
387+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
395388
}));
396389
}
397390

@@ -403,11 +396,9 @@ public void putInitialStateToWorkflowState(String workflowId, User user, ActionL
403396
*/
404397
public void updateTemplateInGlobalContext(String documentId, Template template, ActionListener<IndexResponse> listener) {
405398
if (!doesIndexExist(GLOBAL_CONTEXT_INDEX)) {
406-
String exceptionMessage = "Failed to update template for workflow_id : "
407-
+ documentId
408-
+ ", global_context index does not exist.";
409-
logger.error(exceptionMessage);
410-
listener.onFailure(new FlowFrameworkException(exceptionMessage, RestStatus.BAD_REQUEST));
399+
String errorMessage = "Failed to update template for workflow_id : " + documentId + ", global_context index does not exist.";
400+
logger.error(errorMessage);
401+
listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST));
411402
return;
412403
}
413404
doesTemplateExist(documentId, templateExists -> {
@@ -426,9 +417,7 @@ public void updateTemplateInGlobalContext(String documentId, Template template,
426417
} catch (Exception e) {
427418
String errorMessage = "Failed to update global_context entry : " + documentId;
428419
logger.error(errorMessage, e);
429-
listener.onFailure(
430-
new FlowFrameworkException(errorMessage + " : " + e.getMessage(), ExceptionsHelper.status(e))
431-
);
420+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
432421
}
433422
} else {
434423
String errorMessage = "The template has already been provisioned so it can't be updated: " + documentId;
@@ -457,12 +446,14 @@ public <T> void doesTemplateExist(String documentId, Consumer<Boolean> booleanRe
457446
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
458447
client.get(getRequest, ActionListener.wrap(response -> { booleanResultConsumer.accept(response.isExists()); }, exception -> {
459448
context.restore();
460-
logger.error("Failed to get template " + documentId, exception);
461-
listener.onFailure(new FlowFrameworkException(exception.getMessage(), ExceptionsHelper.status(exception)));
449+
String errorMessage = "Failed to get template " + documentId;
450+
logger.error(errorMessage);
451+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(exception)));
462452
}));
463453
} catch (Exception e) {
464-
logger.error("Failed to retrieve template from global context.", e);
465-
listener.onFailure(new FlowFrameworkException(e.getMessage(), ExceptionsHelper.status(e)));
454+
String errorMessage = "Failed to retrieve template from global context: " + documentId;
455+
logger.error(errorMessage, e);
456+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
466457
}
467458
}
468459

@@ -490,17 +481,18 @@ public <T> void isWorkflowNotStarted(String documentId, Consumer<Boolean> boolea
490481
WorkflowState workflowState = WorkflowState.parse(parser);
491482
booleanResultConsumer.accept(workflowState.getProvisioningProgress().equals(ProvisioningProgress.NOT_STARTED.name()));
492483
} catch (Exception e) {
493-
String message = "Failed to parse workflow state " + documentId;
494-
logger.error(message, e);
495-
listener.onFailure(new FlowFrameworkException(message, RestStatus.INTERNAL_SERVER_ERROR));
484+
String errorMessage = "Failed to parse workflow state " + documentId;
485+
logger.error(errorMessage, e);
486+
listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.INTERNAL_SERVER_ERROR));
496487
}
497488
}, exception -> {
498-
logger.error("Failed to get workflow state " + documentId, exception);
489+
logger.error("Failed to get workflow state for {} ", documentId);
499490
booleanResultConsumer.accept(false);
500491
}));
501492
} catch (Exception e) {
502-
logger.error("Failed to retrieve workflow state to check provisioning status", e);
503-
listener.onFailure(new FlowFrameworkException(e.getMessage(), ExceptionsHelper.status(e)));
493+
String errorMessage = "Failed to retrieve workflow state to check provisioning status";
494+
logger.error(errorMessage, e);
495+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
504496
}
505497
}
506498

@@ -516,9 +508,9 @@ public void updateFlowFrameworkSystemIndexDoc(
516508
ActionListener<UpdateResponse> listener
517509
) {
518510
if (!doesIndexExist(WORKFLOW_STATE_INDEX)) {
519-
String exceptionMessage = "Failed to update document for given workflow due to missing " + WORKFLOW_STATE_INDEX + " index";
520-
logger.error(exceptionMessage);
521-
listener.onFailure(new FlowFrameworkException(exceptionMessage, RestStatus.BAD_REQUEST));
511+
String errorMessage = "Failed to update document for given workflow due to missing " + WORKFLOW_STATE_INDEX + " index";
512+
logger.error(errorMessage);
513+
listener.onFailure(new FlowFrameworkException(errorMessage, RestStatus.BAD_REQUEST));
522514
} else {
523515
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
524516
UpdateRequest updateRequest = new UpdateRequest(WORKFLOW_STATE_INDEX, documentId);
@@ -531,7 +523,7 @@ public void updateFlowFrameworkSystemIndexDoc(
531523
} catch (Exception e) {
532524
String errorMessage = "Failed to update " + WORKFLOW_STATE_INDEX + " entry : " + documentId;
533525
logger.error(errorMessage, e);
534-
listener.onFailure(new FlowFrameworkException(errorMessage + " : " + e.getMessage(), ExceptionsHelper.status(e)));
526+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
535527
}
536528
}
537529
}
@@ -550,9 +542,9 @@ public void updateFlowFrameworkSystemIndexDocWithScript(
550542
ActionListener<UpdateResponse> listener
551543
) {
552544
if (!doesIndexExist(indexName)) {
553-
String exceptionMessage = "Failed to update document for given workflow due to missing " + indexName + " index";
554-
logger.error(exceptionMessage);
555-
listener.onFailure(new Exception(exceptionMessage));
545+
String errorMessage = "Failed to update document for given workflow due to missing " + indexName + " index";
546+
logger.error(errorMessage);
547+
listener.onFailure(new Exception(errorMessage));
556548
} else {
557549
try (ThreadContext.StoredContext context = client.threadPool().getThreadContext().stashContext()) {
558550
UpdateRequest updateRequest = new UpdateRequest(indexName, documentId);
@@ -563,10 +555,9 @@ public void updateFlowFrameworkSystemIndexDocWithScript(
563555
// TODO: Implement our own concurrency control to improve on retry mechanism
564556
client.update(updateRequest, ActionListener.runBefore(listener, context::restore));
565557
} catch (Exception e) {
566-
logger.error("Failed to update {} entry : {}. {}", indexName, documentId, e.getMessage());
567-
listener.onFailure(
568-
new FlowFrameworkException("Failed to update " + indexName + "entry: " + documentId, ExceptionsHelper.status(e))
569-
);
558+
String errorMessage = "Failed to update " + indexName + " entry : " + documentId;
559+
logger.error(errorMessage, e);
560+
listener.onFailure(new FlowFrameworkException(errorMessage, ExceptionsHelper.status(e)));
570561
}
571562
}
572563
}

src/main/java/org/opensearch/flowframework/model/Template.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ public String toJson() {
367367
XContentBuilder builder = JsonXContent.contentBuilder();
368368
return this.toXContent(builder, EMPTY_PARAMS).toString();
369369
} catch (IOException e) {
370-
return "{\"error\": \"couldn't create JSON: " + e.getMessage() + "\"}";
370+
return "{\"error\": \"couldn't create JSON from XContent\"}";
371371
}
372372
}
373373

@@ -381,7 +381,7 @@ public String toYaml() {
381381
XContentBuilder builder = YamlXContent.contentBuilder();
382382
return this.toXContent(builder, EMPTY_PARAMS).toString();
383383
} catch (IOException e) {
384-
return "error: couldn't create YAML: " + e.getMessage();
384+
return "error: couldn't create YAML from XContent";
385385
}
386386
}
387387

src/main/java/org/opensearch/flowframework/model/WorkflowStepValidator.java

+1-14
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
*/
99
package org.opensearch.flowframework.model;
1010

11-
import org.apache.logging.log4j.LogManager;
12-
import org.apache.logging.log4j.Logger;
1311
import org.opensearch.common.unit.TimeValue;
1412
import org.opensearch.core.xcontent.ToXContentObject;
1513
import org.opensearch.core.xcontent.XContentBuilder;
@@ -22,8 +20,6 @@
2220
*/
2321
public class WorkflowStepValidator implements ToXContentObject {
2422

25-
private static final Logger logger = LogManager.getLogger(WorkflowStepValidator.class);
26-
2723
/** Inputs field name */
2824
private static final String INPUTS_FIELD = "inputs";
2925
/** Outputs field name */
@@ -33,28 +29,19 @@ public class WorkflowStepValidator implements ToXContentObject {
3329
/** Timeout field name */
3430
private static final String TIMEOUT = "timeout";
3531

36-
private String workflowStep;
3732
private List<String> inputs;
3833
private List<String> outputs;
3934
private List<String> requiredPlugins;
4035
private TimeValue timeout;
4136

4237
/**
4338
* Instantiate the object representing a Workflow Step validator
44-
* @param workflowStep name of the workflow step
4539
* @param inputs the workflow step inputs
4640
* @param outputs the workflow step outputs
4741
* @param requiredPlugins the required plugins for this workflow step
4842
* @param timeout the timeout for this workflow step
4943
*/
50-
public WorkflowStepValidator(
51-
String workflowStep,
52-
List<String> inputs,
53-
List<String> outputs,
54-
List<String> requiredPlugins,
55-
TimeValue timeout
56-
) {
57-
this.workflowStep = workflowStep;
44+
public WorkflowStepValidator(List<String> inputs, List<String> outputs, List<String> requiredPlugins, TimeValue timeout) {
5845
this.inputs = inputs;
5946
this.outputs = outputs;
6047
this.requiredPlugins = requiredPlugins;

src/main/java/org/opensearch/flowframework/model/WorkflowValidator.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public String toJson() {
4040
XContentBuilder builder = JsonXContent.contentBuilder();
4141
return this.toXContent(builder, EMPTY_PARAMS).toString();
4242
} catch (IOException e) {
43-
return "{\"error\": \"couldn't create JSON: " + e.getMessage() + "\"}";
43+
return "{\"error\": \"couldn't create JSON from XContent\"}";
4444
}
4545
}
4646

0 commit comments

Comments
 (0)