Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
package org.elasticsearch.index;

/**
* Interface for providing additional fields to the slow log from a plugin.
* Interface for providing additional fields to the action log from a plugin.
* Intended to be loaded through SPI.
*/
public interface SlowLogFieldProvider {
public interface ActionLogFieldProvider {
/**
* Create a field provider with index level settings to be able to listen for updates and set initial values
* @param indexSettings settings for the index
*/
SlowLogFields create(IndexSettings indexSettings);
ActionLogFields create(IndexSettings indexSettings);

/**
* Create a field provider without index level settings
*/
SlowLogFields create();
ActionLogFields create();
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@
import java.util.Map;

/**
* Fields for the slow log. These may be different each call depending on the state of the system.
* Fields for the action log. These may be different each call depending on the state of the system.
*/
public interface SlowLogFields {
public interface ActionLogFields {

/**
* Slow log fields for indexing events
* Log fields for indexing events
* @return map of field name to value
*/
Map<String, String> indexFields();

/**
* Slow log fields for search events
* Log fields for search events
* @return map of field name to value
*/
Map<String, String> searchFields();

/**
* Slow log fields for query
* Log fields for query
* @return map of field name to value
*/
default Map<String, String> queryFields() {
Expand Down
8 changes: 4 additions & 4 deletions server/src/main/java/org/elasticsearch/index/IndexModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public IndexModule(
final BooleanSupplier allowExpensiveQueries,
final IndexNameExpressionResolver expressionResolver,
final Map<String, IndexStorePlugin.RecoveryStateFactory> recoveryStateFactories,
final SlowLogFieldProvider slowLogFieldProvider,
final ActionLogFieldProvider slowLogFieldProvider,
final MapperMetrics mapperMetrics,
final List<SearchOperationListener> searchOperationListeners,
final IndexingStatsSettings indexingStatsSettings,
Expand All @@ -214,9 +214,9 @@ public IndexModule(
this.engineFactory = Objects.requireNonNull(engineFactory);
// Need to have a mutable arraylist for plugins to add listeners to it
this.searchOperationListeners = new ArrayList<>(searchOperationListeners);
SlowLogFields slowLogFields = slowLogFieldProvider.create(indexSettings);
this.searchOperationListeners.add(new SearchSlowLog(indexSettings, slowLogFields));
this.indexOperationListeners.add(new IndexingSlowLog(indexSettings, slowLogFields));
ActionLogFields actionLogFields = slowLogFieldProvider.create(indexSettings);
this.searchOperationListeners.add(new SearchSlowLog(indexSettings, actionLogFields));
this.indexOperationListeners.add(new IndexingSlowLog(indexSettings, actionLogFields));
this.directoryFactories = Collections.unmodifiableMap(directoryFactories);
this.allowExpensiveQueries = allowExpensiveQueries;
this.expressionResolver = expressionResolver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public final class IndexingSlowLog implements IndexingOperationListener {
* <em>characters</em> of the source.
*/
private int maxSourceCharsToLog;
private final SlowLogFields slowLogFields;
private final ActionLogFields slowLogFields;

/**
* Reads how much of the source to log. The user can specify any value they
Expand All @@ -125,7 +125,7 @@ public final class IndexingSlowLog implements IndexingOperationListener {
Property.IndexScope
);

IndexingSlowLog(IndexSettings indexSettings, SlowLogFields slowLogFields) {
IndexingSlowLog(IndexSettings indexSettings, ActionLogFields slowLogFields) {
this.slowLogFields = slowLogFields;
this.index = indexSettings.getIndex();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public final class SearchSlowLog implements SearchOperationListener {
private static final Logger queryLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".query");
private static final Logger fetchLogger = LogManager.getLogger(INDEX_SEARCH_SLOWLOG_PREFIX + ".fetch");

private final SlowLogFields slowLogFields;
private final ActionLogFields slowLogFields;

public static final Setting<Boolean> INDEX_SEARCH_SLOWLOG_INCLUDE_USER_SETTING = Setting.boolSetting(
INDEX_SEARCH_SLOWLOG_PREFIX + ".include.user",
Expand Down Expand Up @@ -126,7 +126,7 @@ public final class SearchSlowLog implements SearchOperationListener {

private static final ToXContent.Params FORMAT_PARAMS = new ToXContent.MapParams(Collections.singletonMap("pretty", "false"));

public SearchSlowLog(IndexSettings indexSettings, SlowLogFields slowLogFields) {
public SearchSlowLog(IndexSettings indexSettings, ActionLogFields slowLogFields) {
this.slowLogFields = slowLogFields;
indexSettings.getScopedSettings()
.addSettingsUpdateConsumer(INDEX_SEARCH_SLOWLOG_THRESHOLD_QUERY_WARN_SETTING, this::setQueryWarnThreshold);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@
import org.elasticsearch.env.ShardLockObtainFailedException;
import org.elasticsearch.gateway.MetaStateService;
import org.elasticsearch.gateway.MetadataStateFormat;
import org.elasticsearch.index.ActionLogFieldProvider;
import org.elasticsearch.index.CloseUtils;
import org.elasticsearch.index.Index;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexNotFoundException;
import org.elasticsearch.index.IndexService;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.SlowLogFieldProvider;
import org.elasticsearch.index.analysis.AnalysisRegistry;
import org.elasticsearch.index.bulk.stats.BulkStats;
import org.elasticsearch.index.cache.request.ShardRequestCache;
Expand Down Expand Up @@ -284,7 +284,7 @@ public class IndicesService extends AbstractLifecycleComponent
private final PostRecoveryMerger postRecoveryMerger;
private final List<SearchOperationListener> searchOperationListeners;
private final QueryRewriteInterceptor queryRewriteInterceptor;
final SlowLogFieldProvider slowLogFieldProvider; // pkg-private for testingå
final ActionLogFieldProvider actionLogFieldProvider; // pkg-private for testingå
private final IndexingStatsSettings indexStatsSettings;
private final SearchStatsSettings searchStatsSettings;
private final MergeMetrics mergeMetrics;
Expand Down Expand Up @@ -414,7 +414,7 @@ public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, lon
this.timestampFieldMapperService = new TimestampFieldMapperService(settings, threadPool, this);
this.postRecoveryMerger = new PostRecoveryMerger(settings, threadPool.executor(ThreadPool.Names.FORCE_MERGE), this::getShardOrNull);
this.searchOperationListeners = builder.searchOperationListener;
this.slowLogFieldProvider = builder.slowLogFieldProvider;
this.actionLogFieldProvider = builder.slowLogFieldProvider;
this.indexStatsSettings = new IndexingStatsSettings(clusterService.getClusterSettings());
this.searchStatsSettings = new SearchStatsSettings(clusterService.getClusterSettings());
}
Expand Down Expand Up @@ -810,7 +810,7 @@ private synchronized IndexService createIndexService(
() -> allowExpensiveQueries,
indexNameExpressionResolver,
recoveryStateFactories,
slowLogFieldProvider,
actionLogFieldProvider,
mapperMetrics,
searchOperationListeners,
indexStatsSettings,
Expand Down Expand Up @@ -909,7 +909,7 @@ public synchronized MapperService createIndexMapperServiceForValidation(IndexMet
() -> allowExpensiveQueries,
indexNameExpressionResolver,
recoveryStateFactories,
slowLogFieldProvider,
actionLogFieldProvider,
mapperMetrics,
searchOperationListeners,
indexStatsSettings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
import org.elasticsearch.core.Nullable;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.gateway.MetaStateService;
import org.elasticsearch.index.ActionLogFieldProvider;
import org.elasticsearch.index.ActionLogFields;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.SlowLogFieldProvider;
import org.elasticsearch.index.SlowLogFields;
import org.elasticsearch.index.analysis.AnalysisRegistry;
import org.elasticsearch.index.engine.EngineFactory;
import org.elasticsearch.index.engine.MergeMetrics;
Expand Down Expand Up @@ -83,10 +83,10 @@ public class IndicesServiceBuilder {
MergeMetrics mergeMetrics;
List<SearchOperationListener> searchOperationListener = List.of();
QueryRewriteInterceptor queryRewriteInterceptor = null;
SlowLogFieldProvider slowLogFieldProvider = new SlowLogFieldProvider() {
ActionLogFieldProvider slowLogFieldProvider = new ActionLogFieldProvider() {
@Override
public SlowLogFields create() {
return new SlowLogFields() {
public ActionLogFields create() {
return new ActionLogFields() {
@Override
public Map<String, String> indexFields() {
return Map.of();
Expand All @@ -100,7 +100,7 @@ public Map<String, String> searchFields() {
}

@Override
public SlowLogFields create(IndexSettings indexSettings) {
public ActionLogFields create(IndexSettings indexSettings) {
return create();
}

Expand Down Expand Up @@ -222,8 +222,8 @@ public IndicesServiceBuilder searchOperationListeners(List<SearchOperationListen
return this;
}

public IndicesServiceBuilder slowLogFieldProvider(SlowLogFieldProvider slowLogFieldProvider) {
this.slowLogFieldProvider = slowLogFieldProvider;
public IndicesServiceBuilder slowLogFieldProvider(ActionLogFieldProvider actionLogFieldProvider) {
this.slowLogFieldProvider = actionLogFieldProvider;
return this;
}

Expand Down
24 changes: 12 additions & 12 deletions server/src/main/java/org/elasticsearch/node/NodeConstruction.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@
import org.elasticsearch.health.node.tracker.RepositoriesHealthTracker;
import org.elasticsearch.health.stats.HealthApiStats;
import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.index.ActionLogFieldProvider;
import org.elasticsearch.index.ActionLogFields;
import org.elasticsearch.index.IndexMode;
import org.elasticsearch.index.IndexSettingProvider;
import org.elasticsearch.index.IndexSettingProviders;
import org.elasticsearch.index.IndexSettings;
import org.elasticsearch.index.IndexingPressure;
import org.elasticsearch.index.SlowLogFieldProvider;
import org.elasticsearch.index.SlowLogFields;
import org.elasticsearch.index.analysis.AnalysisRegistry;
import org.elasticsearch.index.engine.MergeMetrics;
import org.elasticsearch.index.mapper.DefaultRootObjectMapperNamespaceValidator;
Expand Down Expand Up @@ -868,16 +868,16 @@ private void construct(
new ShardSearchPhaseAPMMetrics(telemetryProvider.getMeterRegistry())
);

List<? extends SlowLogFieldProvider> slowLogFieldProviders = pluginsService.loadServiceProviders(SlowLogFieldProvider.class);
List<? extends ActionLogFieldProvider> slowLogFieldProviders = pluginsService.loadServiceProviders(ActionLogFieldProvider.class);
// NOTE: the response of index/search slow log fields below must be calculated dynamically on every call
// because the responses may change dynamically at runtime
SlowLogFieldProvider slowLogFieldProvider = new SlowLogFieldProvider() {
public SlowLogFields create() {
final List<SlowLogFields> fields = new ArrayList<>();
ActionLogFieldProvider actionLogFieldProvider = new ActionLogFieldProvider() {
public ActionLogFields create() {
final List<ActionLogFields> fields = new ArrayList<>();
for (var provider : slowLogFieldProviders) {
fields.add(provider.create());
}
return new SlowLogFields() {
return new ActionLogFields() {
@Override
public Map<String, String> indexFields() {
return fields.stream()
Expand All @@ -901,12 +901,12 @@ public Map<String, String> queryFields() {
};
}

public SlowLogFields create(IndexSettings indexSettings) {
final List<SlowLogFields> fields = new ArrayList<>();
public ActionLogFields create(IndexSettings indexSettings) {
final List<ActionLogFields> fields = new ArrayList<>();
for (var provider : slowLogFieldProviders) {
fields.add(provider.create(indexSettings));
}
return new SlowLogFields() {
return new ActionLogFields() {
@Override
public Map<String, String> indexFields() {
return fields.stream()
Expand Down Expand Up @@ -954,7 +954,7 @@ public Map<String, String> queryFields() {
.mapperMetrics(mapperMetrics)
.mergeMetrics(mergeMetrics)
.searchOperationListeners(searchOperationListeners)
.slowLogFieldProvider(slowLogFieldProvider)
.slowLogFieldProvider(actionLogFieldProvider)
.build();

final var parameters = new IndexSettingProvider.Parameters(clusterService, indicesService::createIndexMapperServiceForValidation);
Expand Down Expand Up @@ -1046,7 +1046,7 @@ public Map<String, String> queryFields() {
documentParsingProvider,
taskManager,
projectResolver,
slowLogFieldProvider,
actionLogFieldProvider,
indexingLimits,
linkedProjectConfigService,
projectRoutingResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.features.FeatureService;
import org.elasticsearch.index.ActionLogFieldProvider;
import org.elasticsearch.index.IndexingPressure;
import org.elasticsearch.index.SlowLogFieldProvider;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.SystemIndices;
import org.elasticsearch.plugins.Plugin;
Expand Down Expand Up @@ -58,7 +58,7 @@ public record PluginServiceInstances(
DocumentParsingProvider documentParsingProvider,
TaskManager taskManager,
ProjectResolver projectResolver,
SlowLogFieldProvider slowLogFieldProvider,
ActionLogFieldProvider actionLogFieldProvider,
IndexingPressure indexingPressure,
LinkedProjectConfigService linkedProjectConfigService,
ProjectRoutingResolver projectRoutingResolver
Expand Down
4 changes: 2 additions & 2 deletions server/src/main/java/org/elasticsearch/plugins/Plugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.features.FeatureService;
import org.elasticsearch.index.ActionLogFieldProvider;
import org.elasticsearch.index.IndexModule;
import org.elasticsearch.index.IndexSettingProvider;
import org.elasticsearch.index.IndexingPressure;
import org.elasticsearch.index.SlowLogFieldProvider;
import org.elasticsearch.indices.IndicesService;
import org.elasticsearch.indices.SystemIndices;
import org.elasticsearch.plugins.internal.DocumentParsingProvider;
Expand Down Expand Up @@ -188,7 +188,7 @@ public interface PluginServices {
/**
* Provider for additional SlowLog fields
*/
SlowLogFieldProvider slowLogFieldProvider();
ActionLogFieldProvider actionLogFieldProvider();

/**
* Provider for indexing pressure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void testWrapperIsBound() throws IOException {
() -> true,
indexNameExpressionResolver,
Collections.emptyMap(),
mock(SlowLogFieldProvider.class),
mock(ActionLogFieldProvider.class),
MapperMetrics.NOOP,
emptyList(),
new IndexingStatsSettings(ClusterSettings.createBuiltInClusterSettings()),
Expand Down Expand Up @@ -289,7 +289,7 @@ public void testRegisterIndexStore() throws IOException {
() -> true,
indexNameExpressionResolver,
Collections.emptyMap(),
mock(SlowLogFieldProvider.class),
mock(ActionLogFieldProvider.class),
MapperMetrics.NOOP,
emptyList(),
new IndexingStatsSettings(ClusterSettings.createBuiltInClusterSettings()),
Expand Down Expand Up @@ -318,7 +318,7 @@ public void testDirectoryWrapper() throws IOException {
() -> true,
indexNameExpressionResolver,
Collections.emptyMap(),
mock(SlowLogFieldProvider.class),
mock(ActionLogFieldProvider.class),
MapperMetrics.NOOP,
emptyList(),
new IndexingStatsSettings(ClusterSettings.createBuiltInClusterSettings()),
Expand Down Expand Up @@ -675,7 +675,7 @@ public void testRegisterCustomRecoveryStateFactory() throws IOException {
() -> true,
indexNameExpressionResolver,
recoveryStateFactories,
mock(SlowLogFieldProvider.class),
mock(ActionLogFieldProvider.class),
MapperMetrics.NOOP,
emptyList(),
new IndexingStatsSettings(ClusterSettings.createBuiltInClusterSettings()),
Expand All @@ -701,7 +701,7 @@ public void testIndexCommitListenerIsBound() throws IOException, ExecutionExcept
() -> true,
indexNameExpressionResolver,
Collections.emptyMap(),
mock(SlowLogFieldProvider.class),
mock(ActionLogFieldProvider.class),
MapperMetrics.NOOP,
emptyList(),
new IndexingStatsSettings(ClusterSettings.createBuiltInClusterSettings()),
Expand Down Expand Up @@ -807,7 +807,7 @@ private static IndexModule createIndexModule(
() -> true,
indexNameExpressionResolver,
Collections.emptyMap(),
mock(SlowLogFieldProvider.class),
mock(ActionLogFieldProvider.class),
MapperMetrics.NOOP,
emptyList(),
new IndexingStatsSettings(ClusterSettings.createBuiltInClusterSettings()),
Expand Down
Loading