Skip to content

Commit

Permalink
Register mustache size limit setting (elastic#119291)
Browse files Browse the repository at this point in the history
In elastic#114002 the maximum size of a mustache script output was made
configurable. However, the setting was not registered. This commit
registers the setting so that it can be set in elasticsearch.yml.
  • Loading branch information
rjernst committed Dec 26, 2024
1 parent 8d741da commit 3707647
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/changelog/119291.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 119291
summary: Register mustache size limit setting
area: Infra/Scripting
type: bug
issues: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the "Elastic License
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
* Public License v 1"; you may not use this file except in compliance with, at
* your election, the "Elastic License 2.0", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

package org.elasticsearch.script.mustache;

import org.elasticsearch.ElasticsearchParseException;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.test.ESSingleNodeTestCase;

import java.util.Collection;
import java.util.Collections;
import java.util.List;

import static org.elasticsearch.xcontent.XContentFactory.jsonBuilder;
import static org.hamcrest.Matchers.equalTo;

public class MustacheSettingsIT extends ESSingleNodeTestCase {
@Override
protected Collection<Class<? extends Plugin>> getPlugins() {
return List.of(MustachePlugin.class);
}

@Override
protected Settings nodeSettings() {
return Settings.builder().put(MustacheScriptEngine.MUSTACHE_RESULT_SIZE_LIMIT.getKey(), "10b").build();
}

public void testResultSizeLimit() throws Exception {
createIndex("test");
prepareIndex("test").setId("1").setSource(jsonBuilder().startObject().field("text", "value1").endObject()).get();
indicesAdmin().prepareRefresh().get();

String query = """
{ "query": {"match_all": {}}, "size" : "{{my_size}}" }""";
SearchRequest searchRequest = new SearchRequest();
searchRequest.indices("test");
var e = expectThrows(
ElasticsearchParseException.class,
() -> new SearchTemplateRequestBuilder(client()).setRequest(searchRequest)
.setScript(query)
.setScriptType(ScriptType.INLINE)
.setScriptParams(Collections.singletonMap("my_size", 1))
.get()
);
assertThat(e.getMessage(), equalTo("Mustache script result size limit exceeded"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.settings.ClusterSettings;
import org.elasticsearch.common.settings.IndexScopedSettings;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.settings.SettingsFilter;
import org.elasticsearch.features.NodeFeature;
Expand Down Expand Up @@ -73,4 +74,9 @@ public List<RestHandler> getRestHandlers(
new RestRenderSearchTemplateAction()
);
}

@Override
public List<Setting<?>> getSettings() {
return List.of(MustacheScriptEngine.MUSTACHE_RESULT_SIZE_LIMIT);
}
}

0 comments on commit 3707647

Please sign in to comment.