diff --git a/README.md b/README.md index 93cd476..82228d7 100644 --- a/README.md +++ b/README.md @@ -141,12 +141,13 @@ prometheus.nodes.filter: "_all" #### Indices filter -Prometheus exporter can be configured to filter indices statistics with indices starting with prefixes. +Prometheus exporter can be configured to filter indices statistics from selected indices. +To target all indices, use '' or * or _all Default value: `""`. -For example to filter indices statistics with indices starting with prefixes such as logs, alarms: +For example to filter indices statistics: ``` -prometheus.indices_filter: "logs-*,alarms*" +prometheus.indices_filter: "log-*,*log,*log*,log*-test" ``` ## Usage diff --git a/build.gradle b/build.gradle index 99a8bd2..481cca0 100644 --- a/build.gradle +++ b/build.gradle @@ -3,39 +3,8 @@ import org.opensearch.gradle.test.RestIntegTestTask import java.util.regex.Matcher import java.util.regex.Pattern -apply plugin: 'java' -apply plugin: 'idea' -apply plugin: 'opensearch.opensearchplugin' -apply plugin: 'opensearch.yaml-rest-test' - -def pluginName = pluginName -def pluginDescription = pluginDescription -//def projectPath = 'org.opensearch' -//def pathToPlugin = 'path.to.plugin' -def pluginClassName = pluginClassname - -opensearchplugin { - name pluginName - description pluginDescription -// classname "${projectPath}.${pathToPlugin}.${pluginClassName}" - classname pluginClassName - licenseFile rootProject.file('LICENSE.txt') - noticeFile rootProject.file('NOTICE.txt') -} - -// thirdparty audit needs can be enabled -thirdPartyAudit.enabled = false - -// This requires an additional Jar not published as part of build-tools -loggerUsageCheck.enabled = false - -// No need to validate pom, as we do not upload to maven/sonatype -validateNebulaPom.enabled = false - buildscript { - ext { - // Four {digit(s)} concatenated with a "." followed by -rc{digit(s)} // Examples: 1.0.0.1-rc2, 2.10.4.0-rc5 // Group (3) refers to the last .{digit{(s)} pattern (this is what we want to remove for OpS version) @@ -49,7 +18,6 @@ buildscript { String opensearch_version String plugin_version = version - Matcher rc_matcher = RC_pattern.matcher(plugin_version) Matcher other_matcher = OTHER_pattern.matcher(plugin_version) @@ -83,6 +51,36 @@ buildscript { } } +apply plugin: 'java' +apply plugin: 'idea' +apply plugin: 'opensearch.opensearchplugin' +apply plugin: 'opensearch.yaml-rest-test' +//apply plugin: 'checkstyle' + +def pluginName = pluginName +def pluginDescription = pluginDescription +//def projectPath = 'org.opensearch' +//def pathToPlugin = 'path.to.plugin' +def pluginClassName = pluginClassname + +opensearchplugin { + name pluginName + description pluginDescription +// classname "${projectPath}.${pathToPlugin}.${pluginClassName}" + classname pluginClassName + licenseFile rootProject.file('LICENSE.txt') + noticeFile rootProject.file('NOTICE.txt') +} + +// thirdparty audit needs can be enabled +thirdPartyAudit.enabled = false + +// This requires an additional Jar not published as part of build-tools +loggerUsageCheck.enabled = false + +// No need to validate pom, as we do not upload to maven/sonatype +validateNebulaPom.enabled = false + repositories { mavenLocal() maven { url "https://aws.oss.sonatype.org/content/repositories/releases" } diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 0000000..188c119 --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,298 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/yamlRestTest/resources/rest-api-spec/test/50_10_nodes_filter.yml b/src/yamlRestTest/resources/rest-api-spec/test/50_10_nodes_filter.yml index 84a58c4..2cbc82d 100644 --- a/src/yamlRestTest/resources/rest-api-spec/test/50_10_nodes_filter.yml +++ b/src/yamlRestTest/resources/rest-api-spec/test/50_10_nodes_filter.yml @@ -17,7 +17,6 @@ - match: {defaults.prometheus.cluster.settings: "true"} - match: {defaults.prometheus.indices: "true"} - match: {defaults.prometheus.nodes.filter: "_local"} - - match: {defaults.prometheus.indices_filter: ""} - match: {defaults.prometheus.metric_name.prefix: "opensearch_"} @@ -45,16 +44,6 @@ - match: {persistent: {prometheus.nodes.filter: "_all"}} - # Change indices filter to "logs*" - - do: - cluster.put_settings: - body: - persistent: - prometheus.indices_filter: "logs*" - flat_settings: true - - - match: {persistent: {prometheus.indices_filter: "logs*"}} - # Verify in Prometheus metrics: - do: prometheus.metrics: {} @@ -75,27 +64,3 @@ persistent: prometheus.nodes.filter: null flat_settings: true - - # Remove persistent settings - - do: - cluster.put_settings: - body: - persistent: - prometheus.indices_filter: null - flat_settings: true - - # Remove persistent settings - - do: - cluster.put_settings: - body: - persistent: - prometheus.indices_filter: null - flat_settings: true - - # Remove persistent settings - - do: - cluster.put_settings: - body: - persistent: - prometheus.indices_filter: null - flat_settings: true diff --git a/src/yamlRestTest/resources/rest-api-spec/test/60_10_indices_filter.yml b/src/yamlRestTest/resources/rest-api-spec/test/60_10_indices_filter.yml new file mode 100644 index 0000000..ce0e2d1 --- /dev/null +++ b/src/yamlRestTest/resources/rest-api-spec/test/60_10_indices_filter.yml @@ -0,0 +1,157 @@ +--- +"Indices filter": + + # Make sure indices filter setting is in the default state + - do: + cluster.get_settings: + include_defaults: false + + - match: {persistent: {}} + - match: {transient: {}} + + - do: + cluster.get_settings: + include_defaults: true + filter_path: defaults.prometheus + + - match: {defaults.prometheus.indices_filter: ""} + + # Create 3 indices + - do: + index: + index: log-a-test + id: 1 + body: { foo: bar } + + - do: + index: + index: log-b-test + id: 1 + body: { foo: bar } + + - do: + index: + index: log-c-test + id: 1 + body: { foo: bar } + + # Should have metrics for all indices + - do: + prometheus.metrics: {} + + - match: + $body: | + /.* + (opensearch_index_status\{ + cluster="yamlRestTest", + index="(log-a-test|log-b-test|log-c-test)", + \} \s+ \d+\.\d+ \n?){3} + .*/ + + # Change indices filter to "log-a-*" + - do: + cluster.put_settings: + body: + persistent: + prometheus.indices_filter: "log-a-*" + flat_settings: true + + - match: {persistent: {prometheus.indices_filter: "log-a-*"}} + + # Should have metrics for index log-a-test only, no metrics for others + - do: + prometheus.metrics: {} + + - match: + $body: | + /.* + opensearch_index_status\{ + cluster="yamlRestTest", + index="(?=log-a-test)(?!(log-b-test|log-c-test))(.*)", + \} \s+ \d+\.\d+ \n? + .*/ + + # Change indices filter to "*b-*,log*c-test" + - do: + cluster.put_settings: + body: + persistent: + prometheus.indices_filter: "*b-*,log*c-test" + flat_settings: true + + - match: {persistent: {prometheus.indices_filter: "*b-*,log*c-test"}} + + # Should have metrics for indices log-b-test and log-c-test, no metrics for index log-a-test + - do: + prometheus.metrics: {} + + - match: + $body: | + /.* + (opensearch_index_status\{ + cluster="yamlRestTest", + index="(?=(log-b-test|log-c-test))(?!log-a-test)(.*)", + \} \s+ \d+\.\d+ \n?){2} + .*/ + + # Change indices filter to "*" + - do: + cluster.put_settings: + body: + persistent: + prometheus.indices_filter: "*" + flat_settings: true + + - match: {persistent: {prometheus.indices_filter: "*"}} + + # Should have metrics for all indices + - do: + prometheus.metrics: {} + + - match: + $body: | + /.* + (opensearch_index_status\{ + cluster="yamlRestTest", + index="(log-a-test|log-b-test|log-c-test)", + \} \s+ \d+\.\d+ \n?){3} + .*/ + + # Change indices filter to "_all" + - do: + cluster.put_settings: + body: + persistent: + prometheus.indices_filter: "_all" + flat_settings: true + + - match: {persistent: {prometheus.indices_filter: "_all"}} + + # Should have metrics for all indices + - do: + prometheus.metrics: {} + + - match: + $body: | + /.* + (opensearch_index_status\{ + cluster="yamlRestTest", + index="(log-a-test|log-b-test|log-c-test)", + \} \s+ \d+\.\d+ \n?){3} + .*/ + + + # Unexpected input values + - do: + catch: request + cluster.put_settings: + body: + persistent: + prometheus.indices_filter: [ "", null, 10 ] + flat_settings: true + + - match: {status: 500} + - match: {error.type: "settings_exception"} + - match: {error.reason: "Failed to load settings from [{\"prometheus.indices_filter\":[\"\",null,10]}]"} + - match: {error.caused_by.type: "illegal_state_exception"} + - match: {error.caused_by.reason: "only value lists are allowed in serialized settings"}