Skip to content

Commit f3969f4

Browse files
committed
Query insights plugin implementation
Signed-off-by: Chenyang Ji <[email protected]>
1 parent 6aab360 commit f3969f4

27 files changed

+1643
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
194194
- Capture information for additional query types and aggregation types ([#11582](https://github.com/opensearch-project/OpenSearch/pull/11582))
195195
- Use slice_size == shard_size heuristic in terms aggs for concurrent segment search and properly calculate the doc_count_error ([#11732](https://github.com/opensearch-project/OpenSearch/pull/11732))
196196
- Added Support for dynamically adding SearchRequestOperationsListeners with SearchRequestOperationsCompositeListenerFactory ([#11526](https://github.com/opensearch-project/OpenSearch/pull/11526))
197+
- [Query Insights] Query Insights Plugin Implementation ([#11903](https://github.com/opensearch-project/OpenSearch/pull/11903))
197198

198199
### Deprecated
199200

gradle/missing-javadoc.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ configure([
141141
project(":plugins:mapper-annotated-text"),
142142
project(":plugins:mapper-murmur3"),
143143
project(":plugins:mapper-size"),
144+
project(":plugins:query-insights"),
144145
project(":plugins:repository-azure"),
145146
project(":plugins:repository-gcs"),
146147
project(":plugins:repository-hdfs"),

plugins/query-insights/build.gradle

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
apply plugin: 'opensearch.java-rest-test'
12+
apply plugin: 'opensearch.internal-cluster-test'
13+
14+
opensearchplugin {
15+
description 'OpenSearch Query Insights Plugin.'
16+
classname 'org.opensearch.plugin.insights.QueryInsightsPlugin'
17+
}
18+
19+
dependencies {
20+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights;
10+
11+
import org.opensearch.action.ActionRequest;
12+
import org.opensearch.client.Client;
13+
import org.opensearch.cluster.metadata.IndexNameExpressionResolver;
14+
import org.opensearch.cluster.node.DiscoveryNodes;
15+
import org.opensearch.cluster.service.ClusterService;
16+
import org.opensearch.common.settings.ClusterSettings;
17+
import org.opensearch.common.settings.IndexScopedSettings;
18+
import org.opensearch.common.settings.Setting;
19+
import org.opensearch.common.settings.Settings;
20+
import org.opensearch.common.settings.SettingsFilter;
21+
import org.opensearch.core.action.ActionResponse;
22+
import org.opensearch.core.common.io.stream.NamedWriteableRegistry;
23+
import org.opensearch.core.xcontent.NamedXContentRegistry;
24+
import org.opensearch.env.Environment;
25+
import org.opensearch.env.NodeEnvironment;
26+
import org.opensearch.plugins.ActionPlugin;
27+
import org.opensearch.plugins.Plugin;
28+
import org.opensearch.plugins.SearchPlugin;
29+
import org.opensearch.repositories.RepositoriesService;
30+
import org.opensearch.rest.RestController;
31+
import org.opensearch.rest.RestHandler;
32+
import org.opensearch.script.ScriptService;
33+
import org.opensearch.threadpool.ThreadPool;
34+
import org.opensearch.watcher.ResourceWatcherService;
35+
36+
import java.util.Collection;
37+
import java.util.List;
38+
import java.util.function.Supplier;
39+
40+
/**
41+
* Plugin class for Query Insights.
42+
*/
43+
public class QueryInsightsPlugin extends Plugin implements ActionPlugin, SearchPlugin {
44+
/**
45+
* Default constructor
46+
*/
47+
public QueryInsightsPlugin() {}
48+
49+
@Override
50+
public Collection<Object> createComponents(
51+
Client client,
52+
ClusterService clusterService,
53+
ThreadPool threadPool,
54+
ResourceWatcherService resourceWatcherService,
55+
ScriptService scriptService,
56+
NamedXContentRegistry xContentRegistry,
57+
Environment environment,
58+
NodeEnvironment nodeEnvironment,
59+
NamedWriteableRegistry namedWriteableRegistry,
60+
IndexNameExpressionResolver indexNameExpressionResolver,
61+
Supplier<RepositoriesService> repositoriesServiceSupplier
62+
) {
63+
return List.of();
64+
}
65+
66+
@Override
67+
public List<RestHandler> getRestHandlers(
68+
Settings settings,
69+
RestController restController,
70+
ClusterSettings clusterSettings,
71+
IndexScopedSettings indexScopedSettings,
72+
SettingsFilter settingsFilter,
73+
IndexNameExpressionResolver indexNameExpressionResolver,
74+
Supplier<DiscoveryNodes> nodesInCluster
75+
) {
76+
return List.of();
77+
}
78+
79+
@Override
80+
public List<ActionHandler<? extends ActionRequest, ? extends ActionResponse>> getActions() {
81+
return List.of();
82+
}
83+
84+
@Override
85+
public List<Setting<?>> getSettings() {
86+
return List.of();
87+
}
88+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.core.exporter;
10+
11+
import org.opensearch.plugin.insights.rules.model.SearchQueryRecord;
12+
13+
import java.util.List;
14+
15+
/**
16+
* Simple abstract class to export data collected by search query analyzers
17+
* <p>
18+
* Mainly for use within the Query Insight framework
19+
*
20+
* @opensearch.internal
21+
*/
22+
public abstract class QueryInsightsExporter<T extends SearchQueryRecord<?>> {
23+
private QueryInsightsExporterType type;
24+
private String identifier;
25+
26+
QueryInsightsExporter(QueryInsightsExporterType type, String identifier) {
27+
this.type = type;
28+
this.identifier = identifier;
29+
}
30+
31+
/**
32+
* Export the data with the exporter.
33+
*
34+
* @param records the data to export
35+
*/
36+
public abstract void export(List<T> records) throws Exception;
37+
38+
public void setType(QueryInsightsExporterType type) {
39+
this.type = type;
40+
}
41+
42+
public QueryInsightsExporterType getType() {
43+
return type;
44+
}
45+
46+
public void setIdentifier(String identifier) {
47+
this.identifier = identifier;
48+
}
49+
50+
public String getIdentifier() {
51+
return identifier;
52+
}
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.plugin.insights.core.exporter;
10+
11+
import java.util.Locale;
12+
13+
/**
14+
* Types for the Query Insights Exporters
15+
*
16+
* @opensearch.internal
17+
*/
18+
public enum QueryInsightsExporterType {
19+
/* local index exporter */
20+
LOCAL_INDEX("local_index");
21+
22+
private final String type;
23+
24+
QueryInsightsExporterType(String type) {
25+
this.type = type;
26+
}
27+
28+
public static QueryInsightsExporterType parse(String type) {
29+
return valueOf(type.toUpperCase(Locale.ROOT));
30+
}
31+
}

0 commit comments

Comments
 (0)