[CPS] Use single CrossProjectModeDecider instance#144030
[CPS] Use single CrossProjectModeDecider instance#144030alexey-ivanov-es merged 4 commits intoelastic:mainfrom
Conversation
Updated constructors and method signatures to accept a shared `CrossProjectModeDecider` instance instead of creating new instances for every component
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
There was a problem hiding this comment.
Pull request overview
This PR centralizes Cross-Project Search (CPS) enablement logic by creating a single CrossProjectModeDecider instance and threading it through REST handlers, transport actions, and plugin/service wiring instead of repeatedly instantiating it from Settings.
Changes:
- Add
CrossProjectModeDeciderto core service wiring (PluginServices,ActionPlugin.RestHandlersServices, node construction, transport/remote-cluster services). - Update REST handlers/transport actions across server modules and x-pack plugins to accept/use the shared decider instance.
- Adjust affected tests/fixtures to pass
CrossProjectModeDecider.NOOP(or injected decider) instead ofSettings.
Reviewed changes
Copilot reviewed 58 out of 58 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/rest/RestVectorTileAction.java | Accept shared CrossProjectModeDecider instead of creating one from Settings. |
| x-pack/plugin/vector-tile/src/main/java/org/elasticsearch/xpack/vectortile/VectorTilePlugin.java | Pass decider from RestHandlersServices when constructing REST handler. |
| x-pack/plugin/transform/src/main/java/org/elasticsearch/xpack/transform/Transform.java | Use services.crossProjectModeDecider() instead of constructing per-component. |
| x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/analysis/CancellationTests.java | Update test construction to supply CrossProjectModeDecider.NOOP. |
| x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlTranslateAction.java | Inject and use shared CPS decider. |
| x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/TransportSqlQueryAction.java | Inject decider and plumb through static operation(...). |
| x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/SqlPlugin.java | Pass decider to SQL REST handlers via RestHandlersServices. |
| x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlTranslateAction.java | Accept shared decider (remove Settings dependency). |
| x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/plugin/RestSqlQueryAction.java | Accept shared decider (remove Settings dependency). |
| x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java | Update test wiring to pass CrossProjectModeDecider.NOOP. |
| x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/privilege/RestGetBuiltinPrivilegesAction.java | Inject shared decider rather than constructing it from Settings. |
| x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java | Thread decider via services.crossProjectModeDecider() and into REST handler ctor. |
| x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/telemetry/PlanExecutorMetricsTests.java | Update test wiring to pass CrossProjectModeDecider.NOOP. |
| x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/telemetry/Metrics.java | Replace Settings-based CPS check with boolean flag provided by callers. |
| x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/TransportEsqlQueryAction.java | Inject and pass shared decider to TransportActionServices. |
| x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/EsqlPlugin.java | Pass shared decider into PlanExecutor wiring. |
| x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/execution/PlanExecutor.java | Accept decider and use it for metrics environment flag. |
| x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/EsqlTestUtils.java | Replace per-test instantiation with CrossProjectModeDecider.NOOP. |
| x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/RestEqlSearchAction.java | Accept shared decider (remove Settings dependency). |
| x-pack/plugin/eql/src/main/java/org/elasticsearch/xpack/eql/plugin/EqlPlugin.java | Provide decider from RestHandlersServices. |
| x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/RestSubmitAsyncSearchActionTests.java | Update test wiring to pass CrossProjectModeDecider.NOOP. |
| x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/RestSubmitAsyncSearchAction.java | Accept shared decider (remove Settings dependency). |
| x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/AsyncSearch.java | Provide decider from RestHandlersServices. |
| test/framework/src/main/java/org/elasticsearch/plugins/PluginTestUtil.java | Update helper to construct RestHandlersServices with CrossProjectModeDecider.NOOP. |
| test/framework/src/main/java/org/elasticsearch/node/MockNode.java | Extend transport service creation signature to include decider. |
| server/src/test/java/org/elasticsearch/rest/action/RestFieldCapabilitiesActionTests.java | Update test to pass CrossProjectModeDecider.NOOP to REST action. |
| server/src/test/java/org/elasticsearch/http/AbstractHttpServerTransportTests.java | Update ActionModule test wiring to include decider. |
| server/src/test/java/org/elasticsearch/action/search/RestOpenPointInTimeActionTests.java | Update test to pass CrossProjectModeDecider.NOOP to REST action. |
| server/src/test/java/org/elasticsearch/action/ActionModuleTests.java | Update ActionModule test wiring to include decider. |
| server/src/main/java/org/elasticsearch/transport/TransportService.java | Pass shared decider into RemoteClusterService; add constructor parameter. |
| server/src/main/java/org/elasticsearch/transport/RemoteClusterService.java | Accept decider via constructor instead of instantiating from Settings. |
| server/src/main/java/org/elasticsearch/search/crossproject/CrossProjectModeDecider.java | Add NOOP singleton instance. |
| server/src/main/java/org/elasticsearch/rest/action/search/RestSearchAction.java | Accept shared decider (remove Settings dependency). |
| server/src/main/java/org/elasticsearch/rest/action/search/RestMultiSearchAction.java | Accept shared decider and store it rather than constructing from Settings. |
| server/src/main/java/org/elasticsearch/rest/action/search/RestCountAction.java | Accept shared decider (remove Settings dependency). |
| server/src/main/java/org/elasticsearch/rest/action/cat/RestCountAction.java | Accept shared decider (remove Settings dependency). |
| server/src/main/java/org/elasticsearch/rest/action/admin/indices/RestResolveIndexAction.java | Accept shared decider (remove Settings dependency). |
| server/src/main/java/org/elasticsearch/rest/action/RestFieldCapabilitiesAction.java | Accept shared decider (remove stored Settings). |
| server/src/main/java/org/elasticsearch/plugins/Plugin.java | Extend PluginServices to expose crossProjectModeDecider(). |
| server/src/main/java/org/elasticsearch/plugins/ActionPlugin.java | Extend RestHandlersServices record with CrossProjectModeDecider. |
| server/src/main/java/org/elasticsearch/node/PluginServiceInstances.java | Carry shared decider via PluginServices implementation record. |
| server/src/main/java/org/elasticsearch/node/NodeServiceProvider.java | Thread decider into TransportService construction. |
| server/src/main/java/org/elasticsearch/node/NodeConstruction.java | Construct and bind a single CrossProjectModeDecider instance for the node. |
| server/src/main/java/org/elasticsearch/action/search/TransportSearchAction.java | Inject shared decider instead of constructing from Settings. |
| server/src/main/java/org/elasticsearch/action/search/TransportOpenPointInTimeAction.java | Inject shared decider instead of constructing from ClusterService settings. |
| server/src/main/java/org/elasticsearch/action/search/RestOpenPointInTimeAction.java | Accept shared decider (remove Settings dependency). |
| server/src/main/java/org/elasticsearch/action/fieldcaps/TransportFieldCapabilitiesAction.java | Inject shared decider instead of constructing from settings. |
| server/src/main/java/org/elasticsearch/action/admin/indices/resolve/ResolveIndexAction.java | Inject shared decider into transport action ctor. |
| server/src/main/java/org/elasticsearch/action/ActionModule.java | Carry shared decider, pass it into built-in and plugin REST handlers. |
| modules/reindex/src/test/java/org/elasticsearch/reindex/RestReindexActionTests.java | Update test wiring to pass CrossProjectModeDecider.NOOP. |
| modules/reindex/src/main/java/org/elasticsearch/reindex/RestReindexAction.java | Accept shared decider (remove Settings dependency). |
| modules/reindex/src/main/java/org/elasticsearch/reindex/ReindexPlugin.java | Provide decider from RestHandlersServices. |
| modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java | Accept shared decider in REST action ctor. |
| modules/lang-painless/src/main/java/org/elasticsearch/painless/PainlessPlugin.java | Provide decider from RestHandlersServices. |
| modules/lang-mustache/src/test/java/org/elasticsearch/script/mustache/MultiSearchTemplateRequestTests.java | Update test wiring to pass CrossProjectModeDecider.NOOP. |
| modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestSearchTemplateAction.java | Accept shared decider (remove Settings dependency). |
| modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/RestMultiSearchTemplateAction.java | Accept shared decider and keep Settings only for allow-explicit-index flag. |
| modules/lang-mustache/src/main/java/org/elasticsearch/script/mustache/MustachePlugin.java | Provide decider from RestHandlersServices. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public static final CrossProjectModeDecider NOOP = new CrossProjectModeDecider(Settings.EMPTY); | ||
|
|
||
| private static final String CROSS_PROJECT_ENABLED_SETTING_KEY = "serverless.cross_project.enabled"; | ||
| private final boolean crossProjectEnabled; | ||
|
|
There was a problem hiding this comment.
NOOP currently relies on the default value of serverless.cross_project.enabled via Settings.EMPTY. If the default ever changes, NOOP would no longer be guaranteed to disable CPS. Consider constructing NOOP with an explicit serverless.cross_project.enabled=false setting (or a dedicated private constructor) so its semantics remain stable.
| public static final CrossProjectModeDecider NOOP = new CrossProjectModeDecider(Settings.EMPTY); | |
| private static final String CROSS_PROJECT_ENABLED_SETTING_KEY = "serverless.cross_project.enabled"; | |
| private final boolean crossProjectEnabled; | |
| public static final CrossProjectModeDecider NOOP = new CrossProjectModeDecider(false); | |
| private static final String CROSS_PROJECT_ENABLED_SETTING_KEY = "serverless.cross_project.enabled"; | |
| private final boolean crossProjectEnabled; | |
| private CrossProjectModeDecider(boolean crossProjectEnabled) { | |
| this.crossProjectEnabled = crossProjectEnabled; | |
| } |
| public Metrics(EsqlFunctionRegistry functionRegistry, boolean isServerless) { | ||
| this(functionRegistry, Build.current().isSnapshot(), isServerless); | ||
| } |
There was a problem hiding this comment.
The Metrics(EsqlFunctionRegistry, boolean isServerless) constructor is now typically called with crossProjectModeDecider.crossProjectEnabled(). Since isServerless is used to gate serverlessOnly() settings metrics, consider renaming the parameter (or updating the javadoc) to make it clear whether this flag represents serverless deployment vs CPS enabled; the current naming/usage is easy to misread.
There was a problem hiding this comment.
This name is used in this class and I don't want to change it in this PR
…elocations * upstream/main: (49 commits) CCS logging fixes (elastic#144070) Improve CPS cluster exclusion handling (elastic#143488) Remove snapshot condition now that node_reduce phase is in non-snapshot builds (elastic#144090) Drop deprecation warnings when updating a mapping in the cluster state applier (elastic#143884) (elastic#144040) Add ensureGreenAndNoInitializingShards helper (elastic#144044) Removed unnecessary applies_to blocks from deprecated query (elastic#144096) [CPS] Use single CrossProjectModeDecider instance (elastic#144030) Fix ESQL TS requests with LIMIT 0 (elastic#144031) ESQL: Remove `create` methods in aggs (elastic#144098) ES|QL: Refactor ChangeLimitOperator (elastic#144017) Add Paginated Hit Source Tests (elastic#142592) Fix test failure not preferred (elastic#144019) Remove serialization logic from EIS authorization response (elastic#144021) ESQL: CSV schema inference and parsing enhancements (elastic#144050) ESQL: Fix incorrectly optimized fork with nullify unmapped_fields (elastic#143030) Fix MMR release test using subqueries (elastic#144087) Refactoring `UserAgentPlugin` (elastic#140712) Drop non-finite samples in Prometheus remote write (elastic#144055) [TEST] Wait for internal inference indices to be created in authorization IT (elastic#143885) Disable ndjson datasource QA tests in release-tests (elastic#143992) ...
Updated constructors and method signatures to accept a shared `CrossProjectModeDecider` instance instead of creating new instances for every component
There are 37 instances of
CrossProjectModeDecider, since every component creates its own. This change introduces a single instance ofCrossProjectModeDeciderand updates constructors and method signatures to use it instead of creating new instances.