瀏覽代碼

Make the ShardsAvailabilityIndicator pluggable (#101394)

* Make the ShardsAvailabilityIndicator pluggable

This commit makes the `ShardsAvailabilityIndicator` pluggable. It currently provides the existing `ShardsAvailabilityHealthIndicatorService` (without moving it) for the `shards_availability` output in the health report API.

This will allow us in the future to provide a separate `shards_availability` plugin to override the way that health is reported for shards.
Lee Hinman 2 年之前
父節點
當前提交
f35cf032e8

+ 25 - 0
modules/health-shards-availability/build.gradle

@@ -0,0 +1,25 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+apply plugin: 'elasticsearch.internal-yaml-rest-test'
+apply plugin: 'elasticsearch.yaml-rest-compat-test'
+apply plugin: 'elasticsearch.internal-cluster-test'
+
+esplugin {
+  description 'Health report API extension providing the shards_availability output'
+  classname 'org.elasticsearch.health.plugin.ShardsAvailabilityPlugin'
+}
+
+restResources {
+  restApi {
+    include '_common', 'indices', 'index', 'cluster', 'nodes', 'get', 'ingest'
+  }
+}
+
+tasks.named("yamlRestTestV7CompatTransform").configure {task ->
+  task.addAllowedWarningRegex("setting \\[ecs\\] is deprecated as ECS format is the default and only option")
+}

+ 41 - 0
modules/health-shards-availability/src/main/java/org/elasticsearch/health/plugin/ShardsAvailabilityPlugin.java

@@ -0,0 +1,41 @@
+/*
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
+ * or more contributor license agreements. Licensed under the Elastic License
+ * 2.0 and the Server Side Public License, v 1; you may not use this file except
+ * in compliance with, at your election, the Elastic License 2.0 or the Server
+ * Side Public License, v 1.
+ */
+
+package org.elasticsearch.health.plugin;
+
+import org.apache.lucene.util.SetOnce;
+import org.elasticsearch.cluster.routing.allocation.ShardsAvailabilityHealthIndicatorService;
+import org.elasticsearch.common.settings.Settings;
+import org.elasticsearch.health.HealthIndicatorService;
+import org.elasticsearch.plugin.Inject;
+import org.elasticsearch.plugins.HealthPlugin;
+import org.elasticsearch.plugins.Plugin;
+
+import java.util.Collection;
+import java.util.Set;
+
+public class ShardsAvailabilityPlugin extends Plugin implements HealthPlugin {
+
+    private final SetOnce<ShardsAvailabilityHealthIndicatorService> shardHealthService = new SetOnce<>();
+
+    @Inject
+    public ShardsAvailabilityPlugin(Settings settings) {}
+
+    @Override
+    public Collection<?> createComponents(PluginServices services) {
+        this.shardHealthService.set(
+            new ShardsAvailabilityHealthIndicatorService(services.clusterService(), services.allocationService(), services.systemIndices())
+        );
+        return Set.of(this.shardHealthService.get());
+    }
+
+    @Override
+    public Collection<HealthIndicatorService> getHealthIndicatorServices() {
+        return Set.of(this.shardHealthService.get());
+    }
+}

+ 1 - 0
qa/smoke-test-multinode/build.gradle

@@ -18,6 +18,7 @@ dependencies {
   clusterModules project(":modules:ingest-common")
   clusterModules project(":modules:reindex")
   clusterModules project(":modules:analysis-common")
+  clusterModules project(":modules:health-shards-availability")
 }
 
 tasks.named("yamlRestTest").configure {

+ 1 - 0
qa/smoke-test-multinode/src/yamlRestTest/java/org/elasticsearch/smoketest/SmokeTestMultiNodeClientYamlTestSuiteIT.java

@@ -29,6 +29,7 @@ public class SmokeTestMultiNodeClientYamlTestSuiteIT extends ESClientYamlSuiteTe
         .module("ingest-common")
         .module("reindex")
         .module("analysis-common")
+        .module("health-shards-availability")
         // The first node does not have the ingest role so we're sure ingest requests are forwarded:
         .node(0, n -> n.setting("node.roles", "[master,data,ml,remote_cluster_client,transform]"))
         .feature(FeatureFlag.TIME_SERIES_MODE)

+ 1 - 0
rest-api-spec/build.gradle

@@ -37,6 +37,7 @@ dependencies {
   clusterModules project(":modules:rest-root")
   clusterModules project(":modules:reindex")
   clusterModules project(':modules:analysis-common')
+  clusterModules project(':modules:health-shards-availability')
 }
 
 tasks.named("yamlRestTestV7CompatTransform").configure { task ->

+ 1 - 0
rest-api-spec/src/yamlRestTest/java/org/elasticsearch/test/rest/ClientYamlTestSuiteIT.java

@@ -31,6 +31,7 @@ public class ClientYamlTestSuiteIT extends ESClientYamlSuiteTestCase {
         .module("rest-root")
         .module("reindex")
         .module("analysis-common")
+        .module("health-shards-availability")
         .feature(FeatureFlag.TIME_SERIES_MODE)
         .build();
 

+ 4 - 4
server/src/main/java/org/elasticsearch/node/NodeConstruction.java

@@ -55,7 +55,6 @@ import org.elasticsearch.cluster.routing.BatchedRerouteService;
 import org.elasticsearch.cluster.routing.RerouteService;
 import org.elasticsearch.cluster.routing.allocation.AllocationService;
 import org.elasticsearch.cluster.routing.allocation.DiskThresholdMonitor;
-import org.elasticsearch.cluster.routing.allocation.ShardsAvailabilityHealthIndicatorService;
 import org.elasticsearch.cluster.routing.allocation.WriteLoadForecaster;
 import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.cluster.service.TransportVersionsFixupListener;
@@ -755,7 +754,8 @@ class NodeConstruction {
             Supplier<RepositoriesService> repositoriesServiceSupplier,
             TelemetryProvider telemetryProvider,
             AllocationService allocationService,
-            IndicesService indicesService
+            IndicesService indicesService,
+            SystemIndices systemIndices
         ) implements Plugin.PluginServices {}
         PluginServiceInstances pluginServices = new PluginServiceInstances(
             client,
@@ -771,7 +771,8 @@ class NodeConstruction {
             repositoriesServiceReference::get,
             telemetryProvider,
             clusterModule.getAllocationService(),
-            indicesService
+            indicesService,
+            systemIndices
         );
 
         Collection<?> pluginComponents = pluginsService.flatMap(p -> p.createComponents(pluginServices)).toList();
@@ -1268,7 +1269,6 @@ class NodeConstruction {
         var serverHealthIndicatorServices = Stream.of(
             new StableMasterHealthIndicatorService(coordinationDiagnosticsService, clusterService),
             new RepositoryIntegrityHealthIndicatorService(clusterService),
-            new ShardsAvailabilityHealthIndicatorService(clusterService, clusterModule.getAllocationService(), systemIndices),
             new DiskHealthIndicatorService(clusterService),
             new ShardsCapacityHealthIndicatorService(clusterService)
         );

+ 6 - 0
server/src/main/java/org/elasticsearch/plugins/Plugin.java

@@ -24,6 +24,7 @@ import org.elasticsearch.env.NodeEnvironment;
 import org.elasticsearch.index.IndexModule;
 import org.elasticsearch.index.IndexSettingProvider;
 import org.elasticsearch.indices.IndicesService;
+import org.elasticsearch.indices.SystemIndices;
 import org.elasticsearch.repositories.RepositoriesService;
 import org.elasticsearch.script.ScriptService;
 import org.elasticsearch.telemetry.TelemetryProvider;
@@ -137,6 +138,11 @@ public abstract class Plugin implements Closeable {
          * A service to manage indices in the cluster
          */
         IndicesService indicesService();
+
+        /**
+         * The system indices for the cluster
+         */
+        SystemIndices systemIndices();
     }
 
     /**

+ 1 - 0
x-pack/plugin/core/build.gradle

@@ -58,6 +58,7 @@ dependencies {
   testImplementation project(path: ':modules:lang-mustache')
   testImplementation project(path: ':modules:analysis-common')
   testImplementation project(path: ':modules:rest-root')
+  testImplementation project(path: ':modules:health-shards-availability')
   testImplementation project(":client:rest-high-level")
   // Needed for Fips140ProviderVerificationTests
   testCompileOnly('org.bouncycastle:bc-fips:1.0.2')

+ 2 - 1
x-pack/plugin/core/src/internalClusterTest/java/org/elasticsearch/xpack/cluster/routing/allocation/DataTierShardAvailabilityHealthIndicatorIT.java

@@ -25,6 +25,7 @@ import org.elasticsearch.health.Diagnosis;
 import org.elasticsearch.health.GetHealthAction;
 import org.elasticsearch.health.HealthIndicatorResult;
 import org.elasticsearch.health.HealthStatus;
+import org.elasticsearch.health.plugin.ShardsAvailabilityPlugin;
 import org.elasticsearch.plugins.Plugin;
 import org.elasticsearch.test.ESIntegTestCase;
 import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
@@ -49,7 +50,7 @@ public class DataTierShardAvailabilityHealthIndicatorIT extends ESIntegTestCase
 
     @Override
     protected Collection<Class<? extends Plugin>> nodePlugins() {
-        return List.of(LocalStateCompositeXPackPlugin.class);
+        return List.of(LocalStateCompositeXPackPlugin.class, ShardsAvailabilityPlugin.class);
     }
 
     /**

+ 1 - 0
x-pack/qa/core-rest-tests-with-security/build.gradle

@@ -8,6 +8,7 @@ dependencies {
   clusterModules project(':modules:ingest-common')
   clusterModules project(':modules:reindex')
   clusterModules project(':modules:analysis-common')
+  clusterModules project(':modules:health-shards-availability')
   clusterModules project(xpackModule('stack'))
   clusterModules project(xpackModule('ilm'))
   clusterModules project(xpackModule('mapper-constant-keyword'))

+ 1 - 0
x-pack/qa/core-rest-tests-with-security/src/yamlRestTest/java/org/elasticsearch/xpack/security/CoreWithSecurityClientYamlTestSuiteIT.java

@@ -39,6 +39,7 @@ public class CoreWithSecurityClientYamlTestSuiteIT extends ESClientYamlSuiteTest
         .module("reindex")
         .module("wildcard")
         .module("analysis-common")
+        .module("health-shards-availability")
         .setting("xpack.security.enabled", "true")
         .setting("xpack.watcher.enabled", "false")
         .setting("xpack.ml.enabled", "false")