forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into codeowners-for-kibana-rd
- Loading branch information
Showing
11 changed files
with
178 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
.../ent-search/src/main/java/org/elasticsearch/xpack/application/rules/QueryRulesConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.application.rules; | ||
|
||
import org.elasticsearch.common.settings.Setting; | ||
import org.elasticsearch.core.Strings; | ||
|
||
import java.util.List; | ||
|
||
public class QueryRulesConfig { | ||
|
||
static final String SETTING_ROOT_PATH = "xpack.applications.rules"; | ||
|
||
private static final int DEFAULT_RULE_LIMIT = 100; | ||
private static final int MIN_RULE_LIMIT = 1; | ||
private static final int MAX_RULE_LIMIT = 1000; | ||
|
||
/** | ||
* Index setting describing the maximum number of {@link QueryRule}s that can be included | ||
* in a query ruleset. | ||
*/ | ||
public static final Setting<Integer> MAX_RULE_LIMIT_SETTING = Setting.intSetting( | ||
Strings.format("%s.%s", SETTING_ROOT_PATH, "max_rules_per_ruleset"), | ||
DEFAULT_RULE_LIMIT, | ||
MIN_RULE_LIMIT, | ||
MAX_RULE_LIMIT, | ||
Setting.Property.Dynamic, | ||
Setting.Property.NodeScope | ||
); | ||
|
||
public static List<Setting<?>> getSettings() { | ||
return List.of(MAX_RULE_LIMIT_SETTING); | ||
} | ||
|
||
private QueryRulesConfig() {} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...search/src/test/java/org/elasticsearch/xpack/application/rules/QueryRulesConfigTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.application.rules; | ||
|
||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import static org.hamcrest.Matchers.containsString; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class QueryRulesConfigTests extends ESTestCase { | ||
|
||
public void testDefaultConfig() { | ||
int maxRules = QueryRulesConfig.MAX_RULE_LIMIT_SETTING.get(Settings.EMPTY); | ||
assertThat(maxRules, equalTo(100)); | ||
} | ||
|
||
public void testCustomQueryRulesConfigMaxRulesPerRuleset() { | ||
int customMaxRules = randomIntBetween(1, 1000); | ||
Settings settings = createCustomSettings("max_rules_per_ruleset", Integer.toString(customMaxRules)); | ||
int maxRules = QueryRulesConfig.MAX_RULE_LIMIT_SETTING.get(settings); | ||
assertThat(customMaxRules, equalTo(maxRules)); | ||
} | ||
|
||
public void testCustomQueryRulesConfigMaxRulesPerRulesetTooHigh() { | ||
int customMaxRules = randomIntBetween(1001, Integer.MAX_VALUE); | ||
Settings settings = createCustomSettings("max_rules_per_ruleset", Integer.toString(customMaxRules)); | ||
Exception e = expectThrows(IllegalArgumentException.class, () -> QueryRulesConfig.MAX_RULE_LIMIT_SETTING.get(settings)); | ||
assertThat(e.getMessage(), containsString("[xpack.applications.rules.max_rules_per_ruleset] must be <= 1000")); | ||
} | ||
|
||
public void testCustomQueryRulesConfigMaxRulesPerRulesetTooLow() { | ||
int maxRules = randomIntBetween(Integer.MIN_VALUE, 0); | ||
Settings settings = createCustomSettings("max_rules_per_ruleset", Integer.toString(maxRules)); | ||
Exception e = expectThrows(IllegalArgumentException.class, () -> QueryRulesConfig.MAX_RULE_LIMIT_SETTING.get(settings)); | ||
assertThat(e.getMessage(), containsString("[xpack.applications.rules.max_rules_per_ruleset] must be >= 1")); | ||
} | ||
|
||
private static Settings createCustomSettings(String key, String value) { | ||
key = QueryRulesConfig.SETTING_ROOT_PATH + "." + key; | ||
return Settings.builder().put(key, value).build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters