Skip to content

Commit

Permalink
[Profiling] Consider static settings in status
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danielmitterdorfer committed Jul 24, 2023
1 parent 5c386f1 commit de9b0fa
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
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;
Expand Down Expand Up @@ -51,12 +53,21 @@ protected void masterOperation(
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);
Expand Down

0 comments on commit de9b0fa

Please sign in to comment.