Skip to content

Commit d12da81

Browse files
committed
feat: add test cases
Signed-off-by: Pavan Yekbote <[email protected]>
1 parent 62cf474 commit d12da81

24 files changed

+1090
-346
lines changed

common/src/main/java/org/opensearch/ml/common/MLModel.java

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import org.opensearch.ml.common.model.TextEmbeddingModelConfig;
5151
import org.opensearch.telemetry.metrics.tags.Tags;
5252

53+
import com.google.common.annotations.VisibleForTesting;
54+
5355
import lombok.Builder;
5456
import lombok.Getter;
5557
import 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();

common/src/main/java/org/opensearch/ml/common/settings/MLFeatureEnabledSetting.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ public class MLFeatureEnabledSetting {
4545

4646
private volatile Boolean isRagSearchPipelineEnabled;
4747

48-
// block any push
4948
private volatile Boolean isMetricCollectionEnabled;
50-
// block static push
5149
private volatile Boolean isStaticMetricCollectionEnabled;
5250

5351
private final List<SettingsChangeListener> listeners = new ArrayList<>();

0 commit comments

Comments
 (0)