Skip to content

Commit

Permalink
Remove local index custom name setting
Browse files Browse the repository at this point in the history
Signed-off-by: David Zane <davizane@amazon.com>
  • Loading branch information
dzane17 committed Dec 10, 2024
1 parent 8733008 commit 0219542
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0219542

Please sign in to comment.