Skip to content

Commit

Permalink
Tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkyle committed Oct 2, 2024
1 parent da71d49 commit 7d3116e
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ public record UnparsedModel(
String service,
Map<String, Object> settings,
Map<String, Object> secrets
) {
}
) {}
1 change: 1 addition & 0 deletions x-pack/plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ tasks.named("precommit").configure {
tasks.named("yamlRestCompatTestTransform").configure({ task ->
task.skipTest("security/10_forbidden/Test bulk response with invalid credentials", "warning does not exist for compatibility")
task.skipTest("wildcard/30_ignore_above_synthetic_source/wildcard field type ignore_above", "Temporary until backported")
task.skipTest("inference/inference_crud/Test get all", "Assertions on number of inference models break due to default configs")
})

Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static void assertDefaultElserConfig(Map<String, Object> modelConfig) {
assertThat(
modelConfig.toString(),
adaptiveAllocations,
Matchers.is(Map.of("enabled", true, "min_number_of_allocations", 0, "max_number_of_allocations", 8))
Matchers.is(Map.of("enabled", true, "min_number_of_allocations", 1, "max_number_of_allocations", 8))
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ public ModelRegistry(Client client) {
public void addDefaultConfigurations(List<UnparsedModel> serviceDefaultConfigs) {
for (var conf : serviceDefaultConfigs) {
if (defaultConfigs.containsKey(conf.inferenceEntityId())) {
throw new IllegalStateException("Service [" + conf.service() + "] blah");
throw new IllegalStateException(
"Cannot add default endpoint to the model registry with duplicate inference id ["
+ conf.inferenceEntityId()
+ "] declared by service ["
+ conf.service()
+ "]. The inference Id is already use by ["
+ defaultConfigs.get(conf.inferenceEntityId()).service()
+ "] service."
);
}

defaultConfigs.put(conf.inferenceEntityId(), conf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@
import org.junit.Before;

import java.nio.ByteBuffer;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import static org.elasticsearch.core.Strings.format;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -345,6 +347,28 @@ public void testDeepCopyDefaultConfig() {
}
}

public void testDuplicateDefaultIds() {
var client = mockBulkClient();
var registry = new ModelRegistry(client);

var id = "my-inference";

registry.addDefaultConfigurations(List.of(new UnparsedModel(id, randomFrom(TaskType.values()), "service-a", Map.of(), Map.of())));
var ise = expectThrows(
IllegalStateException.class,
() -> registry.addDefaultConfigurations(
List.of(new UnparsedModel(id, randomFrom(TaskType.values()), "service-b", Map.of(), Map.of()))
)
);
assertThat(
ise.getMessage(),
containsString(
"Cannot add default endpoint to the model registry with duplicate inference id [my-inference] declared by service "
+ "[service-b]. The inference Id is already use by [service-a] service."
)
);
}

private Client mockBulkClient() {
var client = mockClient();
when(client.prepareBulk()).thenReturn(new BulkRequestBuilder(client));
Expand Down

0 comments on commit 7d3116e

Please sign in to comment.