From 02195425564c22eb21f645a06d677ec6179f4797 Mon Sep 17 00:00:00 2001 From: David Zane Date: Tue, 10 Dec 2024 14:44:41 -0800 Subject: [PATCH] Remove local index custom name setting Signed-off-by: David Zane --- .../exporter/QueryInsightsExporterFactory.java | 13 ++++++------- .../core/reader/QueryInsightsReaderFactory.java | 9 ++------- .../insights/core/service/TopQueriesService.java | 12 ++++-------- .../insights/settings/QueryInsightsSettings.java | 4 ---- .../QueryInsightsExporterFactoryTests.java | 16 ---------------- .../reader/QueryInsightsReaderFactoryTests.java | 7 ------- 6 files changed, 12 insertions(+), 49 deletions(-) diff --git a/src/main/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporterFactory.java b/src/main/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporterFactory.java index fee5224..1aee01d 100644 --- a/src/main/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporterFactory.java +++ b/src/main/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporterFactory.java @@ -11,7 +11,6 @@ import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.DEFAULT_TOP_N_QUERIES_INDEX_PATTERN; import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.DEFAULT_TOP_QUERIES_EXPORTER_TYPE; import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.EXPORTER_TYPE; -import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.EXPORT_INDEX; import java.io.IOException; import java.util.HashSet; @@ -73,16 +72,16 @@ public void validateExporterConfig(final Settings settings) throws IllegalArgume } switch (type) { case LOCAL_INDEX: - final String indexPattern = settings.get(EXPORT_INDEX, DEFAULT_TOP_N_QUERIES_INDEX_PATTERN); - if (indexPattern.length() == 0) { - throw new IllegalArgumentException("Empty index pattern configured for the exporter"); - } try { - DateTimeFormat.forPattern(indexPattern); + DateTimeFormat.forPattern(DEFAULT_TOP_N_QUERIES_INDEX_PATTERN); } catch (Exception e) { OperationalMetricsCounter.getInstance().incrementCounter(OperationalMetric.INVALID_INDEX_PATTERN_EXCEPTIONS); throw new IllegalArgumentException( - String.format(Locale.ROOT, "Invalid index pattern [%s] configured for the exporter", indexPattern) + String.format( + Locale.ROOT, + "Invalid index pattern [%s] configured for the exporter", + DEFAULT_TOP_N_QUERIES_INDEX_PATTERN + ) ); } } diff --git a/src/main/java/org/opensearch/plugin/insights/core/reader/QueryInsightsReaderFactory.java b/src/main/java/org/opensearch/plugin/insights/core/reader/QueryInsightsReaderFactory.java index af9630d..ee0e40b 100644 --- a/src/main/java/org/opensearch/plugin/insights/core/reader/QueryInsightsReaderFactory.java +++ b/src/main/java/org/opensearch/plugin/insights/core/reader/QueryInsightsReaderFactory.java @@ -9,7 +9,6 @@ package org.opensearch.plugin.insights.core.reader; import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.DEFAULT_TOP_N_QUERIES_INDEX_PATTERN; -import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.EXPORT_INDEX; import java.io.IOException; import java.util.HashSet; @@ -52,16 +51,12 @@ public QueryInsightsReaderFactory(final Client client) { * @throws IllegalArgumentException if provided Reader sink config settings are invalid */ public void validateReaderConfig(final Settings settings) throws IllegalArgumentException { - final String indexPattern = settings.get(EXPORT_INDEX, DEFAULT_TOP_N_QUERIES_INDEX_PATTERN); - if (indexPattern.isEmpty()) { - throw new IllegalArgumentException("Empty index pattern configured for the Reader"); - } try { - DateTimeFormat.forPattern(indexPattern); + DateTimeFormat.forPattern(DEFAULT_TOP_N_QUERIES_INDEX_PATTERN); } catch (Exception e) { OperationalMetricsCounter.getInstance().incrementCounter(OperationalMetric.INVALID_INDEX_PATTERN_EXCEPTIONS); throw new IllegalArgumentException( - String.format(Locale.ROOT, "Invalid index pattern [%s] configured for the Reader", indexPattern) + String.format(Locale.ROOT, "Invalid index pattern [%s] configured for the Reader", DEFAULT_TOP_N_QUERIES_INDEX_PATTERN) ); } } diff --git a/src/main/java/org/opensearch/plugin/insights/core/service/TopQueriesService.java b/src/main/java/org/opensearch/plugin/insights/core/service/TopQueriesService.java index fd90ed5..24062f8 100644 --- a/src/main/java/org/opensearch/plugin/insights/core/service/TopQueriesService.java +++ b/src/main/java/org/opensearch/plugin/insights/core/service/TopQueriesService.java @@ -11,7 +11,6 @@ import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.DEFAULT_TOP_N_QUERIES_INDEX_PATTERN; import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.DEFAULT_TOP_QUERIES_EXPORTER_TYPE; import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.EXPORTER_TYPE; -import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.EXPORT_INDEX; import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.QUERY_INSIGHTS_EXECUTOR; import java.io.IOException; @@ -266,7 +265,7 @@ public void setExporter(final Settings settings) { if (settings.get(EXPORTER_TYPE) != null) { SinkType expectedType = SinkType.parse(settings.get(EXPORTER_TYPE, DEFAULT_TOP_QUERIES_EXPORTER_TYPE)); if (exporter != null && expectedType == SinkType.getSinkTypeFromExporter(exporter)) { - queryInsightsExporterFactory.updateExporter(exporter, settings.get(EXPORT_INDEX, DEFAULT_TOP_N_QUERIES_INDEX_PATTERN)); + queryInsightsExporterFactory.updateExporter(exporter, DEFAULT_TOP_N_QUERIES_INDEX_PATTERN); } else { try { queryInsightsExporterFactory.closeExporter(this.exporter); @@ -276,7 +275,7 @@ public void setExporter(final Settings settings) { } this.exporter = queryInsightsExporterFactory.createExporter( SinkType.parse(settings.get(EXPORTER_TYPE, DEFAULT_TOP_QUERIES_EXPORTER_TYPE)), - settings.get(EXPORT_INDEX, DEFAULT_TOP_N_QUERIES_INDEX_PATTERN) + DEFAULT_TOP_N_QUERIES_INDEX_PATTERN ); } } else { @@ -298,11 +297,8 @@ public void setExporter(final Settings settings) { * @param namedXContentRegistry NamedXContentRegistry for parsing purposes */ public void setReader(final Settings settings, final NamedXContentRegistry namedXContentRegistry) { - this.reader = queryInsightsReaderFactory.createReader( - settings.get(EXPORT_INDEX, DEFAULT_TOP_N_QUERIES_INDEX_PATTERN), - namedXContentRegistry - ); - queryInsightsReaderFactory.updateReader(reader, settings.get(EXPORT_INDEX, DEFAULT_TOP_N_QUERIES_INDEX_PATTERN)); + this.reader = queryInsightsReaderFactory.createReader(DEFAULT_TOP_N_QUERIES_INDEX_PATTERN, namedXContentRegistry); + queryInsightsReaderFactory.updateReader(reader, DEFAULT_TOP_N_QUERIES_INDEX_PATTERN); } /** diff --git a/src/main/java/org/opensearch/plugin/insights/settings/QueryInsightsSettings.java b/src/main/java/org/opensearch/plugin/insights/settings/QueryInsightsSettings.java index 316699c..b7ffefb 100644 --- a/src/main/java/org/opensearch/plugin/insights/settings/QueryInsightsSettings.java +++ b/src/main/java/org/opensearch/plugin/insights/settings/QueryInsightsSettings.java @@ -219,10 +219,6 @@ public class QueryInsightsSettings { * Config key for exporter type */ public static final String EXPORTER_TYPE = "type"; - /** - * Config key for export index - */ - public static final String EXPORT_INDEX = "config.index"; /** * Settings and defaults for top queries exporters */ diff --git a/src/test/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporterFactoryTests.java b/src/test/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporterFactoryTests.java index 579cbcd..9a52ab0 100644 --- a/src/test/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporterFactoryTests.java +++ b/src/test/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporterFactoryTests.java @@ -11,9 +11,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.DEFAULT_TOP_QUERIES_EXPORTER_TYPE; import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.EXPORTER_TYPE; -import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.EXPORT_INDEX; import org.joda.time.format.DateTimeFormat; import org.junit.Before; @@ -61,20 +59,6 @@ public void testInvalidExporterTypeConfig() { assertThrows(IllegalArgumentException.class, () -> { queryInsightsExporterFactory.validateExporterConfig(settings); }); } - public void testInvalidLocalIndexConfig() { - Settings.Builder settingsBuilder = Settings.builder(); - assertThrows(IllegalArgumentException.class, () -> { - queryInsightsExporterFactory.validateExporterConfig( - settingsBuilder.put(EXPORTER_TYPE, DEFAULT_TOP_QUERIES_EXPORTER_TYPE).put(EXPORT_INDEX, "").build() - ); - }); - assertThrows(IllegalArgumentException.class, () -> { - queryInsightsExporterFactory.validateExporterConfig( - settingsBuilder.put(EXPORTER_TYPE, DEFAULT_TOP_QUERIES_EXPORTER_TYPE).put(EXPORT_INDEX, "some_invalid_pattern").build() - ); - }); - } - public void testCreateAndCloseExporter() { QueryInsightsExporter exporter1 = queryInsightsExporterFactory.createExporter(SinkType.LOCAL_INDEX, format); assertTrue(exporter1 instanceof LocalIndexExporter); diff --git a/src/test/java/org/opensearch/plugin/insights/core/reader/QueryInsightsReaderFactoryTests.java b/src/test/java/org/opensearch/plugin/insights/core/reader/QueryInsightsReaderFactoryTests.java index 0453190..d9e86ae 100644 --- a/src/test/java/org/opensearch/plugin/insights/core/reader/QueryInsightsReaderFactoryTests.java +++ b/src/test/java/org/opensearch/plugin/insights/core/reader/QueryInsightsReaderFactoryTests.java @@ -12,7 +12,6 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.DEFAULT_TOP_N_QUERIES_INDEX_PATTERN; -import static org.opensearch.plugin.insights.settings.QueryInsightsSettings.EXPORT_INDEX; import org.joda.time.format.DateTimeFormat; import org.junit.Before; @@ -55,12 +54,6 @@ public void testValidateConfigWhenResetReader() { } } - public void testInvalidReaderTypeConfig() { - Settings.Builder settingsBuilder = Settings.builder(); - Settings settings = settingsBuilder.put(EXPORT_INDEX, "some_invalid_type").build(); - assertThrows(IllegalArgumentException.class, () -> { queryInsightsReaderFactory.validateReaderConfig(settings); }); - } - public void testCreateAndCloseReader() { QueryInsightsReader reader1 = queryInsightsReaderFactory.createReader(format, namedXContentRegistry); assertTrue(reader1 instanceof LocalIndexReader);