95
95
import org .opensearch .ml .common .MLTask ;
96
96
import org .opensearch .ml .common .connector .Connector ;
97
97
import org .opensearch .ml .common .exception .MLException ;
98
+ import org .opensearch .ml .common .exception .MLLimitExceededException ;
98
99
import org .opensearch .ml .common .exception .MLResourceNotFoundException ;
99
100
import org .opensearch .ml .common .exception .MLValidationException ;
100
101
import org .opensearch .ml .common .model .MLModelState ;
@@ -318,9 +319,10 @@ private void uploadMLModelMeta(MLRegisterModelMetaInput mlRegisterModelMetaInput
318
319
* @param mlTask ML task
319
320
*/
320
321
public void registerMLModel (MLRegisterModelInput registerModelInput , MLTask mlTask ) {
321
- mlStats . getStat ( MLNodeLevelStat . ML_NODE_TOTAL_REQUEST_COUNT ). increment ();
322
+
322
323
checkAndAddRunningTask (mlTask , maxRegisterTasksPerNode );
323
324
try {
325
+ mlStats .getStat (MLNodeLevelStat .ML_NODE_TOTAL_REQUEST_COUNT ).increment ();
324
326
mlStats .getStat (MLNodeLevelStat .ML_NODE_EXECUTING_TASK_COUNT ).increment ();
325
327
mlStats .createCounterStatIfAbsent (mlTask .getFunctionName (), REGISTER , ML_ACTION_REQUEST_COUNT ).increment ();
326
328
@@ -380,7 +382,6 @@ public void registerMLModel(MLRegisterModelInput registerModelInput, MLTask mlTa
380
382
handleException (registerModelInput .getFunctionName (), mlTask .getTaskId (), e );
381
383
}
382
384
} catch (Exception e ) {
383
- mlStats .createCounterStatIfAbsent (mlTask .getFunctionName (), REGISTER , MLActionLevelStat .ML_ACTION_FAILURE_COUNT ).increment ();
384
385
handleException (registerModelInput .getFunctionName (), mlTask .getTaskId (), e );
385
386
} finally {
386
387
mlStats .getStat (MLNodeLevelStat .ML_NODE_EXECUTING_TASK_COUNT ).increment ();
@@ -392,9 +393,9 @@ private void indexRemoteModel(MLRegisterModelInput registerModelInput, MLTask ml
392
393
FunctionName functionName = mlTask .getFunctionName ();
393
394
try (ThreadContext .StoredContext context = client .threadPool ().getThreadContext ().stashContext ()) {
394
395
mlStats .getStat (MLNodeLevelStat .ML_NODE_TOTAL_REQUEST_COUNT ).increment ();
395
-
396
396
mlStats .createCounterStatIfAbsent (functionName , REGISTER , ML_ACTION_REQUEST_COUNT ).increment ();
397
397
mlStats .getStat (MLNodeLevelStat .ML_NODE_EXECUTING_TASK_COUNT ).increment ();
398
+
398
399
String modelName = registerModelInput .getModelName ();
399
400
String version = modelVersion == null ? registerModelInput .getVersion () : modelVersion ;
400
401
Instant now = Instant .now ();
@@ -462,7 +463,6 @@ private void registerModelFromUrl(MLRegisterModelInput registerModelInput, MLTas
462
463
FunctionName functionName = mlTask .getFunctionName ();
463
464
try (ThreadContext .StoredContext context = client .threadPool ().getThreadContext ().stashContext ()) {
464
465
mlStats .getStat (MLNodeLevelStat .ML_NODE_TOTAL_REQUEST_COUNT ).increment ();
465
-
466
466
mlStats .createCounterStatIfAbsent (functionName , REGISTER , ML_ACTION_REQUEST_COUNT ).increment ();
467
467
mlStats .getStat (MLNodeLevelStat .ML_NODE_EXECUTING_TASK_COUNT ).increment ();
468
468
String modelName = registerModelInput .getModelName ();
@@ -689,7 +689,12 @@ private void deleteModel(String modelId) {
689
689
}
690
690
691
691
private void handleException (FunctionName functionName , String taskId , Exception e ) {
692
- mlStats .createCounterStatIfAbsent (functionName , REGISTER , MLActionLevelStat .ML_ACTION_FAILURE_COUNT ).increment ();
692
+ if (!(e instanceof MLLimitExceededException )
693
+ && !(e instanceof MLResourceNotFoundException )
694
+ && !(e instanceof IllegalArgumentException )) {
695
+ mlStats .createCounterStatIfAbsent (functionName , REGISTER , MLActionLevelStat .ML_ACTION_FAILURE_COUNT ).increment ();
696
+ mlStats .getStat (MLNodeLevelStat .ML_NODE_TOTAL_FAILURE_COUNT ).increment ();
697
+ }
693
698
Map <String , Object > updated = ImmutableMap .of (ERROR_FIELD , MLExceptionUtils .getRootCauseMessage (e ), STATE_FIELD , FAILED );
694
699
mlTaskManager .updateMLTask (taskId , updated , TIMEOUT_IN_MILLIS , true );
695
700
}
@@ -713,6 +718,7 @@ public void deployModel(
713
718
ActionListener <String > listener
714
719
) {
715
720
mlStats .createCounterStatIfAbsent (functionName , ActionName .DEPLOY , ML_ACTION_REQUEST_COUNT ).increment ();
721
+ mlStats .getStat (MLNodeLevelStat .ML_NODE_TOTAL_REQUEST_COUNT ).increment ();
716
722
List <String > workerNodes = mlTask .getWorkerNodes ();
717
723
if (modelCacheHelper .isModelDeployed (modelId )) {
718
724
if (workerNodes != null && workerNodes .size () > 0 ) {
@@ -835,7 +841,13 @@ public void deployModel(
835
841
}
836
842
837
843
private void handleDeployModelException (String modelId , FunctionName functionName , ActionListener <String > listener , Exception e ) {
838
- mlStats .createCounterStatIfAbsent (functionName , ActionName .DEPLOY , MLActionLevelStat .ML_ACTION_FAILURE_COUNT ).increment ();
844
+
845
+ if (!(e instanceof MLLimitExceededException )
846
+ && !(e instanceof MLResourceNotFoundException )
847
+ && !(e instanceof IllegalArgumentException )) {
848
+ mlStats .createCounterStatIfAbsent (functionName , ActionName .DEPLOY , MLActionLevelStat .ML_ACTION_FAILURE_COUNT ).increment ();
849
+ mlStats .getStat (MLNodeLevelStat .ML_NODE_TOTAL_FAILURE_COUNT ).increment ();
850
+ }
839
851
removeModel (modelId );
840
852
listener .onFailure (e );
841
853
}
@@ -858,7 +870,7 @@ public void getModel(String modelId, ActionListener<MLModel> listener) {
858
870
}
859
871
860
872
/**
861
- * Get model from model index with includes/exludes filter.
873
+ * Get model from model index with includes/excludes filter.
862
874
*
863
875
* @param modelId model id
864
876
* @param includes fields included
@@ -1045,6 +1057,7 @@ public synchronized Map<String, String> undeployModel(String[] modelIds) {
1045
1057
if (modelCacheHelper .isModelDeployed (modelId )) {
1046
1058
modelUndeployStatus .put (modelId , UNDEPLOYED );
1047
1059
mlStats .getStat (MLNodeLevelStat .ML_NODE_TOTAL_MODEL_COUNT ).decrement ();
1060
+ mlStats .getStat (MLNodeLevelStat .ML_NODE_TOTAL_REQUEST_COUNT ).increment ();
1048
1061
mlStats
1049
1062
.createCounterStatIfAbsent (getModelFunctionName (modelId ), ActionName .UNDEPLOY , ML_ACTION_REQUEST_COUNT )
1050
1063
.increment ();
0 commit comments