Skip to content

Commit

Permalink
[Backport 2.x] Fix CreateAnomalyDetectorTool doesn't support data str…
Browse files Browse the repository at this point in the history
…eams and alias (#425)

* Fix CreateAnomalyDetectorTool doesn't support data streams and alias (#423)

* Fix CreateAnomalyDetectorTool doesn't support data streams and alias

Signed-off-by: gaobinlong <[email protected]>

* Refine the code comment

Signed-off-by: gaobinlong <[email protected]>

---------

Signed-off-by: gaobinlong <[email protected]>
(cherry picked from commit 988a68a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

* Backport/backport 423 to 2.x (#428)

* Fix test failure due to external change (#427)

Signed-off-by: gaobinlong <[email protected]>

* Fix CreateAnomalyDetectorTool doesn't support data streams and alias (#423)

* Fix CreateAnomalyDetectorTool doesn't support data streams and alias

Signed-off-by: gaobinlong <[email protected]>

* Refine the code comment

Signed-off-by: gaobinlong <[email protected]>

---------

Signed-off-by: gaobinlong <[email protected]>
(cherry picked from commit 988a68a)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Signed-off-by: gaobinlong <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: gaobinlong <[email protected]>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>

---------

Signed-off-by: gaobinlong <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: zane-neo <[email protected]>
Co-authored-by: gaobinlong <[email protected]>
  • Loading branch information
4 people authored Oct 11, 2024
1 parent 8b94c60 commit 4c6934b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,9 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
throw new IllegalArgumentException("No mapping found for the index: " + indexName);
}

MappingMetadata mappingMetadata;
// when the index name is wildcard pattern, we fetch the mappings of the first index
if (indexName.contains("*")) {
mappingMetadata = mappings.get((String) mappings.keySet().toArray()[0]);
} else {
mappingMetadata = mappings.get(indexName);
}
// when the index name is a wildcard pattern, a data stream, or an alias, we fetch the mappings of the first index
String firstIndexName = (String) mappings.keySet().toArray()[0];
MappingMetadata mappingMetadata = mappings.get(firstIndexName);

Map<String, Object> mappingSource = (Map<String, Object>) mappingMetadata.getSourceAsMap().get("properties");
if (Objects.isNull(mappingSource)) {
Expand Down Expand Up @@ -224,7 +220,7 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
.collect(Collectors.toUnmodifiableMap(Map.Entry::getKey, Map.Entry::getValue));

// construct the prompt
String prompt = constructPrompt(filteredMapping, indexName);
String prompt = constructPrompt(filteredMapping, firstIndexName);
RemoteInferenceInputDataSet inputDataSet = RemoteInferenceInputDataSet
.builder()
.parameters(Collections.singletonMap("prompt", prompt))
Expand Down Expand Up @@ -278,7 +274,7 @@ public <T> void run(Map<String, String> parameters, ActionListener<T> listener)
Map<String, String> result = ImmutableMap
.of(
OUTPUT_KEY_INDEX,
indexName,
firstIndexName,
OUTPUT_KEY_CATEGORY_FIELD,
categoryField,
OUTPUT_KEY_AGGREGATION_FIELD,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class CreateAnomalyDetectorToolTests {
"{\"index\":\"http_logs\",\"categoryField\":\"\",\"aggregationField\":\"response,responseLatency\",\"aggregationMethod\":\"count,avg\",\"dateFields\":\"date\"}";

private String mockedResultForIndexPattern =
"{\"index\":\"http_logs*\",\"categoryField\":\"\",\"aggregationField\":\"response,responseLatency\",\"aggregationMethod\":\"count,avg\",\"dateFields\":\"date\"}";
"{\"index\":\"http_logs\",\"categoryField\":\"\",\"aggregationField\":\"response,responseLatency\",\"aggregationMethod\":\"count,avg\",\"dateFields\":\"date\"}";

@Before
public void setup() {
Expand Down

0 comments on commit 4c6934b

Please sign in to comment.