@@ -21,6 +21,7 @@ import org.opensearch.common.Strings
21
21
import org .opensearch .flint .app .{FlintCommand , FlintInstance }
22
22
import org .opensearch .flint .app .FlintInstance .formats
23
23
import org .opensearch .flint .core .FlintOptions
24
+ import org .opensearch .flint .core .logging .CustomLogging
24
25
import org .opensearch .flint .core .metrics .MetricConstants
25
26
import org .opensearch .flint .core .metrics .MetricsUtil .{getTimerContext , incrementCounter , registerGauge , stopTimer }
26
27
import org .opensearch .flint .core .storage .{FlintReader , OpenSearchUpdater }
@@ -67,7 +68,7 @@ object FlintREPL extends Logging with FlintJobExecutor {
67
68
val (queryOption, resultIndex) = parseArgs(args)
68
69
69
70
if (Strings .isNullOrEmpty(resultIndex)) {
70
- throw new IllegalArgumentException (" resultIndex is not set" )
71
+ logAndThrow (" resultIndex is not set" )
71
72
}
72
73
73
74
// init SparkContext
@@ -84,7 +85,7 @@ object FlintREPL extends Logging with FlintJobExecutor {
84
85
conf.set(" spark.sql.defaultCatalog" , dataSource)
85
86
86
87
val jobType = conf.get(FlintSparkConf .JOB_TYPE .key, FlintSparkConf .JOB_TYPE .defaultValue.get)
87
- logInfo(s """ Job type is: ${FlintSparkConf .JOB_TYPE .defaultValue.get}""" )
88
+ CustomLogging . logInfo(s """ Job type is: ${FlintSparkConf .JOB_TYPE .defaultValue.get}""" )
88
89
conf.set(FlintSparkConf .JOB_TYPE .key, jobType)
89
90
90
91
val query = getQuery(queryOption, jobType, conf)
@@ -109,10 +110,10 @@ object FlintREPL extends Logging with FlintJobExecutor {
109
110
val sessionId : Option [String ] = Option (conf.get(FlintSparkConf .SESSION_ID .key, null ))
110
111
111
112
if (sessionIndex.isEmpty) {
112
- throw new IllegalArgumentException (FlintSparkConf .REQUEST_INDEX .key + " is not set" )
113
+ logAndThrow (FlintSparkConf .REQUEST_INDEX .key + " is not set" )
113
114
}
114
115
if (sessionId.isEmpty) {
115
- throw new IllegalArgumentException (FlintSparkConf .SESSION_ID .key + " is not set" )
116
+ logAndThrow (FlintSparkConf .SESSION_ID .key + " is not set" )
116
117
}
117
118
118
119
val spark = createSparkSession(conf)
@@ -238,27 +239,12 @@ object FlintREPL extends Logging with FlintJobExecutor {
238
239
}
239
240
}
240
241
241
- def parseArgs (args : Array [String ]): (Option [String ], String ) = {
242
- args.length match {
243
- case 1 =>
244
- (None , args(0 )) // Starting from OS 2.13, resultIndex is the only argument
245
- case 2 =>
246
- (
247
- Some (args(0 )),
248
- args(1 )
249
- ) // Before OS 2.13, there are two arguments, the second one is resultIndex
250
- case _ =>
251
- throw new IllegalArgumentException (
252
- " Unsupported number of arguments. Expected 1 or 2 arguments." )
253
- }
254
- }
255
-
256
242
def getQuery (queryOption : Option [String ], jobType : String , conf : SparkConf ): String = {
257
243
queryOption.getOrElse {
258
244
if (jobType.equalsIgnoreCase(" streaming" )) {
259
245
val defaultQuery = conf.get(FlintSparkConf .QUERY .key, " " )
260
246
if (defaultQuery.isEmpty) {
261
- throw new IllegalArgumentException (" Query undefined for the streaming job." )
247
+ logAndThrow (" Query undefined for the streaming job." )
262
248
}
263
249
unescapeQuery(defaultQuery)
264
250
} else " "
@@ -456,7 +442,7 @@ object FlintREPL extends Logging with FlintJobExecutor {
456
442
sessionIndex : String ,
457
443
sessionTimerContext : Timer .Context ): Unit = {
458
444
val error = s " Session error: ${e.getMessage}"
459
- logError(error, e)
445
+ CustomLogging . logError(error, e)
460
446
461
447
val flintInstance = getExistingFlintInstance(osClient, sessionIndex, sessionId)
462
448
.getOrElse(createFailedFlintInstance(applicationId, jobId, sessionId, jobStartTime, error))
@@ -476,7 +462,9 @@ object FlintREPL extends Logging with FlintJobExecutor {
476
462
Option (getResponse.getSourceAsMap)
477
463
.map(FlintInstance .deserializeFromMap)
478
464
case Failure (exception) =>
479
- logError(s " Failed to retrieve existing FlintInstance: ${exception.getMessage}" , exception)
465
+ CustomLogging .logError(
466
+ s " Failed to retrieve existing FlintInstance: ${exception.getMessage}" ,
467
+ exception)
480
468
None
481
469
case _ => None
482
470
}
@@ -645,7 +633,7 @@ object FlintREPL extends Logging with FlintJobExecutor {
645
633
// or invalid catalog (e.g., we are operating on data not defined in provided data source)
646
634
case e : Exception =>
647
635
val error = s """ Fail to write result of ${flintCommand}, cause: ${e.getMessage}"""
648
- logError(error, e)
636
+ CustomLogging . logError(error, e)
649
637
flintCommand.fail()
650
638
updateSessionIndex(flintCommand, flintSessionIndexUpdater)
651
639
recordStatementStateChange(flintCommand, statementTimerContext)
@@ -672,7 +660,6 @@ object FlintREPL extends Logging with FlintJobExecutor {
672
660
* actions that require the computation of results that need to be collected or stored.
673
661
*/
674
662
spark.sparkContext.cancelJobGroup(flintCommand.queryId)
675
- logError(error)
676
663
Some (
677
664
handleCommandFailureAndGetFailedData(
678
665
spark,
@@ -705,13 +692,9 @@ object FlintREPL extends Logging with FlintJobExecutor {
705
692
queryWaitTimeMillis))
706
693
} catch {
707
694
case e : TimeoutException =>
708
- handleCommandTimeout(
709
- spark,
710
- dataSource,
711
- s " Executing ${flintCommand.query} timed out " ,
712
- flintCommand,
713
- sessionId,
714
- startTime)
695
+ val error = s " Executing ${flintCommand.query} timed out "
696
+ CustomLogging .logError(error, e)
697
+ handleCommandTimeout(spark, dataSource, error, flintCommand, sessionId, startTime)
715
698
case e : Exception =>
716
699
val error = processQueryException(e, flintCommand)
717
700
Some (
@@ -769,10 +752,12 @@ object FlintREPL extends Logging with FlintJobExecutor {
769
752
} catch {
770
753
case e : TimeoutException =>
771
754
val error = s " Getting the mapping of index $resultIndex timed out "
755
+ CustomLogging .logError(error, e)
772
756
dataToWrite =
773
757
handleCommandTimeout(spark, dataSource, error, flintCommand, sessionId, startTime)
774
758
case NonFatal (e) =>
775
759
val error = s " An unexpected error occurred: ${e.getMessage}"
760
+ CustomLogging .logError(error, e)
776
761
dataToWrite = Some (
777
762
handleCommandFailureAndGetFailedData(
778
763
spark,
@@ -1003,13 +988,13 @@ object FlintREPL extends Logging with FlintJobExecutor {
1003
988
case ie : InterruptedException =>
1004
989
// Preserve the interrupt status
1005
990
Thread .currentThread().interrupt()
1006
- logError(" HeartBeatUpdater task was interrupted" , ie)
991
+ CustomLogging . logError(" HeartBeatUpdater task was interrupted" , ie)
1007
992
incrementCounter(
1008
993
MetricConstants .REQUEST_METADATA_HEARTBEAT_FAILED_METRIC
1009
994
) // Record heartbeat failure metric
1010
995
// maybe due to invalid sequence number or primary term
1011
996
case e : Exception =>
1012
- logWarning(
997
+ CustomLogging . logWarning(
1013
998
s """ Fail to update the last update time of the flint instance ${sessionId}""" ,
1014
999
e)
1015
1000
incrementCounter(
@@ -1069,7 +1054,7 @@ object FlintREPL extends Logging with FlintJobExecutor {
1069
1054
} catch {
1070
1055
// still proceed since we are not sure what happened (e.g., OpenSearch cluster may be unresponsive)
1071
1056
case e : Exception =>
1072
- logError(s """ Fail to find id ${sessionId} from session index. """ , e)
1057
+ CustomLogging . logError(s """ Fail to find id ${sessionId} from session index. """ , e)
1073
1058
true
1074
1059
}
1075
1060
}
@@ -1114,10 +1099,13 @@ object FlintREPL extends Logging with FlintJobExecutor {
1114
1099
if e.getCause != null && e.getCause.isInstanceOf [ConnectException ] =>
1115
1100
retries += 1
1116
1101
val delay = initialDelay * math.pow(2 , retries - 1 ).toLong
1117
- logError(s " Fail to connect to OpenSearch cluster. Retrying in $delay... " , e)
1102
+ CustomLogging .logError(
1103
+ s " Fail to connect to OpenSearch cluster. Retrying in $delay... " ,
1104
+ e)
1118
1105
Thread .sleep(delay.toMillis)
1119
1106
1120
1107
case e : Exception =>
1108
+ CustomLogging .logError(e)
1121
1109
throw e
1122
1110
}
1123
1111
}
0 commit comments