5050import org .opensearch .ml .common .model .TextEmbeddingModelConfig ;
5151import org .opensearch .telemetry .metrics .tags .Tags ;
5252
53+ import com .google .common .annotations .VisibleForTesting ;
54+
5355import lombok .Builder ;
5456import lombok .Getter ;
5557import lombok .Setter ;
@@ -862,7 +864,8 @@ public Tags getTags(Connector connector) {
862864 return getCustomModelTags ();
863865 }
864866
865- private Tags getRemoteModelTags (Connector connector ) {
867+ @ VisibleForTesting
868+ Tags getRemoteModelTags (Connector connector ) {
866869 String serviceProvider = TAG_VALUE_UNKNOWN ;
867870 String model = TAG_VALUE_UNKNOWN ;
868871 String modelType = TAG_VALUE_UNKNOWN ;
@@ -907,11 +910,8 @@ private Tags getRemoteModelTags(Connector connector) {
907910 return tags ;
908911 }
909912
910- /**
911- * Identifies the service provider from the connector URL
912- * Matches keywords in `MODEL_SERVICE_PROVIDER_KEYWORDS`
913- */
914- private String identifyServiceProvider (String url ) {
913+ @ VisibleForTesting
914+ String identifyServiceProvider (String url ) {
915915 for (String provider : MODEL_SERVICE_PROVIDER_KEYWORDS ) {
916916 if (url .contains (provider )) {
917917 return provider ;
@@ -921,10 +921,8 @@ private String identifyServiceProvider(String url) {
921921 return TAG_VALUE_UNKNOWN ;
922922 }
923923
924- /**
925- * Extracts model information based on the identified provider and URL/body patterns
926- */
927- private String identifyModel (String provider , String url , JSONObject requestBody , Connector connector ) {
924+ @ VisibleForTesting
925+ String identifyModel (String provider , String url , JSONObject requestBody , Connector connector ) {
928926 try {
929927 // bedrock expects model in the url after `/model/`
930928 if (provider .equals (BEDROCK )) {
@@ -950,16 +948,13 @@ private String identifyModel(String provider, String url, JSONObject requestBody
950948 }
951949
952950 // check if parameters has `model` -- recommended via blueprints
953- if (connector .getParameters ().containsKey ("model" )) {
951+ if (connector .getParameters () != null && connector . getParameters () .containsKey ("model" )) {
954952 return connector .getParameters ().get ("model" );
955953 }
956954
957955 return TAG_VALUE_UNKNOWN ;
958956 }
959957
960- /**
961- * Utility to check if the target string contains any of the keywords.
962- */
963958 private static boolean containsAny (String target , List <String > keywords ) {
964959 for (String key : keywords ) {
965960 if (target .contains (key )) {
@@ -969,10 +964,8 @@ private static boolean containsAny(String target, List<String> keywords) {
969964 return false ;
970965 }
971966
972- /**
973- * Determines the model type based on the model name
974- */
975- private String identifyModelType (String model ) {
967+ @ VisibleForTesting
968+ String identifyModelType (String model ) {
976969 if (model == null || TAG_VALUE_UNKNOWN .equals (model )) {
977970 return TAG_VALUE_UNKNOWN ;
978971 }
@@ -998,12 +991,11 @@ private String identifyModelType(String model) {
998991 return TAG_VALUE_UNKNOWN ;
999992 }
1000993
1001- private Tags getPreTrainedModelTags () {
994+ @ VisibleForTesting
995+ Tags getPreTrainedModelTags () {
1002996 String modelType = TAG_VALUE_UNKNOWN ;
1003- if (this .modelConfig != null ) {
1004- if (this .modelConfig .getModelType () != null ) {
1005- modelType = this .modelConfig .getModelType ();
1006- }
997+ if (this .modelConfig != null && this .modelConfig .getModelType () != null ) {
998+ modelType = this .modelConfig .getModelType ();
1007999 }
10081000
10091001 String [] nameParts = this .name .split ("/" );
@@ -1022,7 +1014,8 @@ private Tags getPreTrainedModelTags() {
10221014 return tags ;
10231015 }
10241016
1025- private Tags getCustomModelTags () {
1017+ @ VisibleForTesting
1018+ Tags getCustomModelTags () {
10261019 String modelType = TAG_VALUE_UNKNOWN ;
10271020 if (this .modelConfig != null && this .modelConfig .getModelType () != null ) {
10281021 modelType = this .modelConfig .getModelType ();
0 commit comments