Skip to content

Commit

Permalink
Fixed review comments for index filter options
Browse files Browse the repository at this point in the history
Signed-off-by: nhuttran <truong.nhut_tran.ext@nokia.com>
  • Loading branch information
nhuttran authored and lukas-vlcek committed May 10, 2023
1 parent 30b4035 commit 7e3434f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 33 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,28 @@ For example to filter indices statistics:
prometheus.indices_filter.selected_indices: "log-*,*log,*log*,log*-test"
```

Users can select which option for filtering indices statistics
Users can select which option for filtering indices statistics.
Default value: `"STRICT_EXPAND_OPEN_FORBID_CLOSED"`.

For example to select an option:
```
prometheus.indices_filter.selected_option: "LENIENT_EXPAND_OPEN"
```
Here is a list of indices options available for selection
```
STRICT_EXPAND_OPEN: indices options that requires every specified index to exist, expands wildcards only to open indices and allows that no indices are resolved from wildcard expressions (not returning an error).
STRICT_EXPAND_OPEN_HIDDEN: indices options that requires every specified index to exist, expands wildcards only to open indices, includes hidden indices, and allows that no indices are resolved from wildcard expressions (not returning an error).
STRICT_EXPAND_OPEN_FORBID_CLOSED: indices options that requires every specified index to exist, expands wildcards only to open indices, allows that no indices are resolved from wildcard expressions (not returning an error) and forbids the use of closed indices by throwing an error.
STRICT_EXPAND_OPEN_HIDDEN_FORBID_CLOSED: indices options that requires every specified index to exist, expands wildcards only to open indices, includes hidden indices, and allows that no indices are resolved from wildcard expressions (not returning an error) and forbids the use of closed indices by throwing an error.
STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED: indices options that requires every specified index to exist, expands wildcards only to open indices, allows that no indices are resolved from wildcard expressions (not returning an error), forbids the use of closed indices by throwing an error and ignores indices that are throttled.
STRICT_EXPAND_OPEN_CLOSED: indices option that requires every specified index to exist, expands wildcards to both open and closed indices and allows that no indices are resolved from wildcard expressions (not returning an error).
STRICT_EXPAND_OPEN_CLOSED_HIDDEN: indices option that requires every specified index to exist, expands wildcards to both open and closed indices, includes hidden indices, and allows that no indices are resolved from wildcard expressions (not returning an error).
STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED: indices option that requires each specified index or alias to exist, doesn't expand wildcards and throws error if any of the aliases resolves to multiple indices.
LENIENT_EXPAND_OPEN: indices options that ignores unavailable indices, expands wildcards only to open indices and allows that no indices are resolved from wildcard expressions (not returning an error).
LENIENT_EXPAND_OPEN_HIDDEN: indices options that ignores unavailable indices, expands wildcards to open and hidden indices, and allows that no indices are resolved from wildcard expressions (not returning an error).
LENIENT_EXPAND_OPEN_CLOSED: indices options that ignores unavailable indices, expands wildcards to both open and closed indices and allows that no indices are resolved from wildcard expressions (not returning an error).
LENIENT_EXPAND_OPEN_CLOSED_HIDDEN: indices options that ignores unavailable indices, expands wildcards to all open and closed indices and allows that no indices are resolved from wildcard expressions (not returning an error).
```

## Usage

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
import org.opensearch.common.settings.Setting;
import org.opensearch.common.settings.Settings;

import java.util.Arrays;
import java.util.List;
import java.util.function.Function;

/**
* Dynamically updatable Prometheus exporter settings.
*
Expand All @@ -40,6 +36,7 @@ public enum INDEX_FILTER_OPTIONS {
STRICT_EXPAND_OPEN,
STRICT_EXPAND_OPEN_HIDDEN,
STRICT_EXPAND_OPEN_FORBID_CLOSED,
STRICT_EXPAND_OPEN_HIDDEN_FORBID_CLOSED,
STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED,
STRICT_EXPAND_OPEN_CLOSED,
STRICT_EXPAND_OPEN_CLOSED_HIDDEN,
Expand All @@ -55,7 +52,6 @@ public enum INDEX_FILTER_OPTIONS {
static String PROMETHEUS_NODES_FILTER_KEY = "prometheus.nodes.filter";
static String PROMETHEUS_SELECTED_INDICES_KEY = "prometheus.indices_filter.selected_indices";
static String PROMETHEUS_SELECTED_OPTION_KEY = "prometheus.indices_filter.selected_option";
static String PROMETHEUS_OPTIONS_DESCRIPTION_KEY = "prometheus.indices_filter.options_description";

/**
* This setting is used configure weather to expose cluster settings metrics or not. The default value is true.
Expand Down Expand Up @@ -99,32 +95,11 @@ public enum INDEX_FILTER_OPTIONS {
String.valueOf(INDEX_FILTER_OPTIONS.STRICT_EXPAND_OPEN_FORBID_CLOSED),
INDEX_FILTER_OPTIONS::valueOf, Setting.Property.Dynamic, Setting.Property.NodeScope);

/**
* This setting is used to display options description
*/
public static final Setting<List<String>> PROMETHEUS_OPTIONS_DESCRIPTION =
Setting.listSetting(PROMETHEUS_OPTIONS_DESCRIPTION_KEY,
Arrays.asList(
"STRICT_EXPAND_OPEN: indices options that requires every specified index to exist, expands wildcards only to open indices and allows that no indices are resolved from wildcard expressions (not returning an error).",
"STRICT_EXPAND_OPEN_HIDDEN: indices options that requires every specified index to exist, expands wildcards only to open indices, includes hidden indices, and allows that no indices are resolved from wildcard expressions (not returning an error).",
"STRICT_EXPAND_OPEN_FORBID_CLOSED: indices options that requires every specified index to exist, expands wildcards only to open indices, allows that no indices are resolved from wildcard expressions (not returning an error) and forbids the use of closed indices by throwing an error.",
"STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED: indices options that requires every specified index to exist, expands wildcards only to open indices, allows that no indices are resolved from wildcard expressions (not returning an error), forbids the use of closed indices by throwing an error and ignores indices that are throttled.",
"STRICT_EXPAND_OPEN_CLOSED: indices option that requires every specified index to exist, expands wildcards to both open and closed indices and allows that no indices are resolved from wildcard expressions (not returning an error).",
"STRICT_EXPAND_OPEN_CLOSED_HIDDEN: indices option that requires every specified index to exist, expands wildcards to both open and closed indices, includes hidden indices, and allows that no indices are resolved from wildcard expressions (not returning an error).",
"STRICT_SINGLE_INDEX_NO_EXPAND_FORBID_CLOSED: indices option that requires each specified index or alias to exist, doesn't expand wildcards and throws error if any of the aliases resolves to multiple indices.",
"LENIENT_EXPAND_OPEN: indices options that ignores unavailable indices, expands wildcards only to open indices and allows that no indices are resolved from wildcard expressions (not returning an error).",
"LENIENT_EXPAND_OPEN_HIDDEN: indices options that ignores unavailable indices, expands wildcards to open and hidden indices, and allows that no indices are resolved from wildcard expressions (not returning an error).",
"LENIENT_EXPAND_OPEN_CLOSED: indices options that ignores unavailable indices, expands wildcards to both open and closed indices and allows that no indices are resolved from wildcard expressions (not returning an error).",
"LENIENT_EXPAND_OPEN_CLOSED_HIDDEN: indices options that ignores unavailable indices, expands wildcards to all open and closed indices and allows that no indices are resolved from wildcard expressions (not returning an error)."
),
Function.identity(), Setting.Property.NodeScope);

private volatile boolean clusterSettings;
private volatile boolean indices;
private volatile String nodesFilter;
private volatile String selectedIndices;
private volatile INDEX_FILTER_OPTIONS selectedOption;
private volatile List<String> optionsDescription;

/**
* A constructor.
Expand All @@ -137,7 +112,6 @@ public PrometheusSettings(Settings settings, ClusterSettings clusterSettings) {
setPrometheusNodesFilter(PROMETHEUS_NODES_FILTER.get(settings));
setPrometheusSelectedIndices(PROMETHEUS_SELECTED_INDICES.get(settings));
setPrometheusSelectedOption(PROMETHEUS_SELECTED_OPTION.get(settings));
setPrometheusOptionsDescription(PROMETHEUS_OPTIONS_DESCRIPTION.get(settings));
clusterSettings.addSettingsUpdateConsumer(PROMETHEUS_CLUSTER_SETTINGS, this::setPrometheusClusterSettings);
clusterSettings.addSettingsUpdateConsumer(PROMETHEUS_INDICES, this::setPrometheusIndices);
clusterSettings.addSettingsUpdateConsumer(PROMETHEUS_NODES_FILTER, this::setPrometheusNodesFilter);
Expand All @@ -163,10 +137,6 @@ private void setPrometheusSelectedOption(INDEX_FILTER_OPTIONS selectedOption) {
this.selectedOption = selectedOption;
}

private void setPrometheusOptionsDescription(List<String> optionsDescription) {
this.optionsDescription = optionsDescription;
}

/**
* Get value of settings key {@link #PROMETHEUS_CLUSTER_SETTINGS_KEY}.
* @return boolean value of the key
Expand Down Expand Up @@ -213,6 +183,9 @@ public IndicesOptions getIndicesOptions() {
case STRICT_EXPAND_OPEN_FORBID_CLOSED:
indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosed();
break;
case STRICT_EXPAND_OPEN_HIDDEN_FORBID_CLOSED:
indicesOptions = IndicesOptions.STRICT_EXPAND_OPEN_HIDDEN_FORBID_CLOSED;
break;
case STRICT_EXPAND_OPEN_FORBID_CLOSED_IGNORE_THROTTLED:
indicesOptions = IndicesOptions.strictExpandOpenAndForbidClosedIgnoreThrottled();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public List<Setting<?>> getSettings() {
PrometheusSettings.PROMETHEUS_NODES_FILTER,
PrometheusSettings.PROMETHEUS_SELECTED_INDICES,
PrometheusSettings.PROMETHEUS_SELECTED_OPTION,
PrometheusSettings.PROMETHEUS_OPTIONS_DESCRIPTION,
RestPrometheusMetricsAction.METRIC_PREFIX
);
return Collections.unmodifiableList(settings);
Expand Down

0 comments on commit 7e3434f

Please sign in to comment.