Преглед изворни кода

[Profiling] Consider static settings in status (#97890)

* [Profiling] Consider static settings in status

Previously the profiling status check only considered the dynamically
set value for `xpack.profiling.templates.enabled`. If a user set a
value statically in `elasticsearch.yml` the status check did not reflect
that leading to puzzling responses. With this commit we check not only
dynamically defined cluster settings but also the static ones before
returning the setting's default value.

* Update docs/changelog/97890.yaml
Daniel Mitterdorfer пре 2 година
родитељ
комит
082ff1d461

+ 5 - 0
docs/changelog/97890.yaml

@@ -0,0 +1,5 @@
+pr: 97890
+summary: "[Profiling] Consider static settings in status"
+area: Application
+type: bug
+issues: []

+ 13 - 2
x-pack/plugin/profiling/src/main/java/org/elasticsearch/xpack/profiling/TransportGetStatusAction.java

@@ -14,8 +14,10 @@ import org.elasticsearch.cluster.ClusterState;
 import org.elasticsearch.cluster.block.ClusterBlockException;
 import org.elasticsearch.cluster.block.ClusterBlockLevel;
 import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver;
+import org.elasticsearch.cluster.metadata.Metadata;
 import org.elasticsearch.cluster.service.ClusterService;
 import org.elasticsearch.common.inject.Inject;
+import org.elasticsearch.common.settings.Setting;
 import org.elasticsearch.tasks.Task;
 import org.elasticsearch.threadpool.ThreadPool;
 import org.elasticsearch.transport.TransportService;
@@ -51,12 +53,21 @@ public class TransportGetStatusAction extends TransportMasterNodeAction<GetStatu
         ClusterState state,
         ActionListener<GetStatusAction.Response> listener
     ) {
-        boolean pluginEnabled = XPackSettings.PROFILING_ENABLED.get(state.getMetadata().settings());
-        boolean resourceManagementEnabled = ProfilingPlugin.PROFILING_TEMPLATES_ENABLED.get(state.getMetadata().settings());
+        boolean pluginEnabled = getValue(state, XPackSettings.PROFILING_ENABLED);
+        boolean resourceManagementEnabled = getValue(state, ProfilingPlugin.PROFILING_TEMPLATES_ENABLED);
         boolean resourcesCreated = ProfilingIndexTemplateRegistry.isAllResourcesCreated(state);
         listener.onResponse(new GetStatusAction.Response(pluginEnabled, resourceManagementEnabled, resourcesCreated));
     }
 
+    private boolean getValue(ClusterState state, Setting<Boolean> setting) {
+        Metadata metadata = state.getMetadata();
+        if (metadata.settings().hasValue(setting.getKey())) {
+            return setting.get(metadata.settings());
+        } else {
+            return setting.get(clusterService.getSettings());
+        }
+    }
+
     @Override
     protected ClusterBlockException checkBlock(GetStatusAction.Request request, ClusterState state) {
         return state.blocks().globalBlockedException(ClusterBlockLevel.METADATA_READ);