-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 gagan_gauge
Signed-off-by: Gagan Juneja <[email protected]>
- Loading branch information
Showing
131 changed files
with
7,120 additions
and
916 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 was deleted.
Oops, something went wrong.
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
61 changes: 61 additions & 0 deletions
61
...ry-insights/src/main/java/org/opensearch/plugin/insights/core/exporter/DebugExporter.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,61 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.core.exporter; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.plugin.insights.rules.model.SearchQueryRecord; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Debug exporter for development purpose | ||
*/ | ||
public final class DebugExporter implements QueryInsightsExporter { | ||
/** | ||
* Logger of the debug exporter | ||
*/ | ||
private final Logger logger = LogManager.getLogger(); | ||
|
||
/** | ||
* Constructor of DebugExporter | ||
*/ | ||
private DebugExporter() {} | ||
|
||
private static class InstanceHolder { | ||
private static final DebugExporter INSTANCE = new DebugExporter(); | ||
} | ||
|
||
/** | ||
Get the singleton instance of DebugExporter | ||
* | ||
@return DebugExporter instance | ||
*/ | ||
public static DebugExporter getInstance() { | ||
return InstanceHolder.INSTANCE; | ||
} | ||
|
||
/** | ||
* Write the list of SearchQueryRecord to debug log | ||
* | ||
* @param records list of {@link SearchQueryRecord} | ||
*/ | ||
@Override | ||
public void export(final List<SearchQueryRecord> records) { | ||
logger.debug("QUERY_INSIGHTS_RECORDS: " + records.toString()); | ||
} | ||
|
||
/** | ||
* Close the debugger exporter sink | ||
*/ | ||
@Override | ||
public void close() { | ||
logger.debug("Closing the DebugExporter.."); | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...sights/src/main/java/org/opensearch/plugin/insights/core/exporter/LocalIndexExporter.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,113 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.core.exporter; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.action.bulk.BulkRequestBuilder; | ||
import org.opensearch.action.bulk.BulkResponse; | ||
import org.opensearch.action.index.IndexRequest; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.common.xcontent.XContentFactory; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.xcontent.ToXContent; | ||
import org.opensearch.plugin.insights.rules.model.SearchQueryRecord; | ||
import org.joda.time.DateTime; | ||
import org.joda.time.DateTimeZone; | ||
import org.joda.time.format.DateTimeFormatter; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Local index exporter for exporting query insights data to local OpenSearch indices. | ||
*/ | ||
public final class LocalIndexExporter implements QueryInsightsExporter { | ||
/** | ||
* Logger of the local index exporter | ||
*/ | ||
private final Logger logger = LogManager.getLogger(); | ||
private final Client client; | ||
private DateTimeFormatter indexPattern; | ||
|
||
/** | ||
* Constructor of LocalIndexExporter | ||
* | ||
* @param client OS client | ||
* @param indexPattern the pattern of index to export to | ||
*/ | ||
public LocalIndexExporter(final Client client, final DateTimeFormatter indexPattern) { | ||
this.indexPattern = indexPattern; | ||
this.client = client; | ||
} | ||
|
||
/** | ||
* Getter of indexPattern | ||
* | ||
* @return indexPattern | ||
*/ | ||
public DateTimeFormatter getIndexPattern() { | ||
return indexPattern; | ||
} | ||
|
||
/** | ||
* Setter of indexPattern | ||
* | ||
* @param indexPattern index pattern | ||
* @return the current LocalIndexExporter | ||
*/ | ||
public LocalIndexExporter setIndexPattern(DateTimeFormatter indexPattern) { | ||
this.indexPattern = indexPattern; | ||
return this; | ||
} | ||
|
||
/** | ||
* Export a list of SearchQueryRecord to a local index | ||
* | ||
* @param records list of {@link SearchQueryRecord} | ||
*/ | ||
@Override | ||
public void export(final List<SearchQueryRecord> records) { | ||
if (records == null || records.size() == 0) { | ||
return; | ||
} | ||
try { | ||
final String index = getDateTimeFromFormat(); | ||
final BulkRequestBuilder bulkRequestBuilder = client.prepareBulk().setTimeout(TimeValue.timeValueMinutes(1)); | ||
for (SearchQueryRecord record : records) { | ||
bulkRequestBuilder.add( | ||
new IndexRequest(index).source(record.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)) | ||
); | ||
} | ||
bulkRequestBuilder.execute(new ActionListener<BulkResponse>() { | ||
@Override | ||
public void onResponse(BulkResponse bulkItemResponses) {} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
logger.error("Failed to execute bulk operation for query insights data: ", e); | ||
} | ||
}); | ||
} catch (final Exception e) { | ||
logger.error("Unable to index query insights data: ", e); | ||
} | ||
} | ||
|
||
/** | ||
* Close the exporter sink | ||
*/ | ||
@Override | ||
public void close() { | ||
logger.debug("Closing the LocalIndexExporter.."); | ||
} | ||
|
||
private String getDateTimeFromFormat() { | ||
return indexPattern.print(DateTime.now(DateTimeZone.UTC)); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...hts/src/main/java/org/opensearch/plugin/insights/core/exporter/QueryInsightsExporter.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,26 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.plugin.insights.core.exporter; | ||
|
||
import org.opensearch.plugin.insights.rules.model.SearchQueryRecord; | ||
|
||
import java.io.Closeable; | ||
import java.util.List; | ||
|
||
/** | ||
* Base interface for Query Insights exporters | ||
*/ | ||
public interface QueryInsightsExporter extends Closeable { | ||
/** | ||
* Export a list of SearchQueryRecord to the exporter sink | ||
* | ||
* @param records list of {@link SearchQueryRecord} | ||
*/ | ||
void export(final List<SearchQueryRecord> records); | ||
} |
Oops, something went wrong.