Skip to content

Commit cb6e0c8

Browse files
Also exclude hidden indices
1 parent bf5492b commit cb6e0c8

File tree

2 files changed

+49
-5
lines changed

2 files changed

+49
-5
lines changed

x-pack/plugin/inference/src/main/java/org/elasticsearch/xpack/inference/action/TransportInferenceUsageAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ private static Map<ServiceAndTaskType, Map<String, List<InferenceFieldMetadata>>
108108
.collect(Collectors.toMap(ModelConfigurations::getInferenceEntityId, Function.identity()));
109109
Map<ServiceAndTaskType, Map<String, List<InferenceFieldMetadata>>> inferenceFieldByIndexServiceAndTask = new HashMap<>();
110110
for (IndexMetadata indexMetadata : indicesMetadata) {
111-
if (indexMetadata.isSystem()) {
112-
// Usage for system indices should be reported through the corresponding application usage
111+
if (indexMetadata.isSystem() || indexMetadata.isHidden()) {
112+
// Usage for system or hidden indices should be reported through the corresponding application usage
113113
continue;
114114
}
115115
indexMetadata.getInferenceFields()

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/action/TransportInferenceUsageActionTests.java

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import java.util.Set;
5454
import java.util.concurrent.ExecutionException;
5555

56+
import static org.elasticsearch.cluster.metadata.IndexMetadata.INDEX_HIDDEN_SETTING;
5657
import static org.elasticsearch.xpack.inference.Utils.TIMEOUT;
5758
import static org.hamcrest.Matchers.equalTo;
5859
import static org.hamcrest.Matchers.hasSize;
@@ -373,6 +374,42 @@ public void testShouldExcludeSystemIndexFields() throws Exception {
373374
new InferenceFieldMetadata("semantic-3", "endpoint-002", new String[0], null)
374375
)
375376
),
377+
Set.of("index_2"),
378+
Set.of()
379+
);
380+
381+
XContentSource response = executeAction();
382+
383+
assertThat(response.getValue("models"), hasSize(7));
384+
assertStats(response, 0, new ModelStats("_all", TaskType.CHAT_COMPLETION, 0, new SemanticTextStats()));
385+
assertStats(response, 1, new ModelStats("_all", TaskType.COMPLETION, 0, new SemanticTextStats()));
386+
assertStats(response, 2, new ModelStats("_all", TaskType.RERANK, 0, new SemanticTextStats()));
387+
assertStats(response, 3, new ModelStats("_all", TaskType.SPARSE_EMBEDDING, 0, new SemanticTextStats()));
388+
assertStats(response, 4, new ModelStats("_all", TaskType.TEXT_EMBEDDING, 2, new SemanticTextStats(2, 1, 2)));
389+
assertStats(response, 5, new ModelStats("eis", TaskType.TEXT_EMBEDDING, 1, new SemanticTextStats(1, 1, 1)));
390+
assertStats(response, 6, new ModelStats("openai", TaskType.TEXT_EMBEDDING, 1, new SemanticTextStats(1, 1, 1)));
391+
}
392+
393+
public void testShouldExcludeHiddenIndexFields() throws Exception {
394+
givenInferenceEndpoints(
395+
new ModelConfigurations("endpoint-001", TaskType.TEXT_EMBEDDING, "eis", mockServiceSettings("some-model")),
396+
new ModelConfigurations("endpoint-002", TaskType.TEXT_EMBEDDING, "openai", mockServiceSettings("some-model"))
397+
);
398+
givenInferenceFields(
399+
Map.of(
400+
"index_1",
401+
List.of(
402+
new InferenceFieldMetadata("semantic-1", "endpoint-001", new String[0], null),
403+
new InferenceFieldMetadata("semantic-2", "endpoint-002", new String[0], null)
404+
),
405+
"index_2",
406+
List.of(
407+
new InferenceFieldMetadata("semantic-1", "endpoint-001", new String[0], null),
408+
new InferenceFieldMetadata("semantic-2", "endpoint-002", new String[0], null),
409+
new InferenceFieldMetadata("semantic-3", "endpoint-002", new String[0], null)
410+
)
411+
),
412+
Set.of(),
376413
Set.of("index_2")
377414
);
378415

@@ -425,15 +462,22 @@ private void givenInferenceEndpoints(ModelConfigurations... endpoints) {
425462
}
426463

427464
private void givenInferenceFields(Map<String, List<InferenceFieldMetadata>> inferenceFieldsByIndex) {
428-
givenInferenceFields(inferenceFieldsByIndex, Set.of());
465+
givenInferenceFields(inferenceFieldsByIndex, Set.of(), Set.of());
429466
}
430467

431-
private void givenInferenceFields(Map<String, List<InferenceFieldMetadata>> inferenceFieldsByIndex, Set<String> systemIndices) {
468+
private void givenInferenceFields(
469+
Map<String, List<InferenceFieldMetadata>> inferenceFieldsByIndex,
470+
Set<String> systemIndices,
471+
Set<String> hiddenIndices
472+
) {
432473
Map<String, IndexMetadata> indices = new HashMap<>();
433474
for (Map.Entry<String, List<InferenceFieldMetadata>> entry : inferenceFieldsByIndex.entrySet()) {
434475
String index = entry.getKey();
435476
IndexMetadata.Builder indexMetadata = IndexMetadata.builder(index)
436-
.settings(ESTestCase.settings(IndexVersion.current()))
477+
.settings(
478+
ESTestCase.settings(IndexVersion.current())
479+
.put(INDEX_HIDDEN_SETTING.getKey(), hiddenIndices.contains(index) ? "true" : "false")
480+
)
437481
.numberOfShards(randomIntBetween(1, 5))
438482
.system(systemIndices.contains(index))
439483
.numberOfReplicas(1);

0 commit comments

Comments
 (0)