Skip to content

Commit

Permalink
Added initial metrics for synthetic source
Browse files Browse the repository at this point in the history
This PR adds basic infra for mapper metrics and adds first metrics for
synthetic source load latency.
  • Loading branch information
lkts committed Mar 25, 2024
1 parent cbc4182 commit 906bc40
Show file tree
Hide file tree
Showing 36 changed files with 387 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.index.mapper.ProvidedIdFieldMapper;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.script.ScriptContext;
Expand Down Expand Up @@ -71,7 +72,8 @@ public static MapperService create(String mappings) {
public <T> T compile(Script script, ScriptContext<T> scriptContext) {
throw new UnsupportedOperationException();
}
}
},
MapperMetrics.NOOP
);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.elasticsearch.index.shard.IndexShard;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.indices.breaker.NoneCircuitBreakerService;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptCompiler;
Expand Down Expand Up @@ -186,7 +187,8 @@ protected final MapperService createMapperService(String mappings) {
public <T> T compile(Script script, ScriptContext<T> scriptContext) {
throw new UnsupportedOperationException();
}
}
},
MapperMetrics.NOOP
);

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.elasticsearch.index.mapper.MapperRegistry;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.script.ScriptService;
import org.elasticsearch.xcontent.NamedXContentRegistry;
Expand Down Expand Up @@ -58,14 +59,16 @@ public class IndexMetadataVerifier {
private final MapperRegistry mapperRegistry;
private final IndexScopedSettings indexScopedSettings;
private final ScriptCompiler scriptService;
private final MapperMetrics mapperMetrics;

public IndexMetadataVerifier(
Settings settings,
ClusterService clusterService,
NamedXContentRegistry xContentRegistry,
MapperRegistry mapperRegistry,
IndexScopedSettings indexScopedSettings,
ScriptCompiler scriptCompiler
ScriptCompiler scriptCompiler,
MapperMetrics mapperMetrics
) {
this.settings = settings;
this.clusterService = clusterService;
Expand All @@ -74,6 +77,7 @@ public IndexMetadataVerifier(
this.mapperRegistry = mapperRegistry;
this.indexScopedSettings = indexScopedSettings;
this.scriptService = scriptCompiler;
this.mapperMetrics = mapperMetrics;
}

/**
Expand Down Expand Up @@ -182,7 +186,8 @@ protected TokenStreamComponents createComponents(String fieldName) {
mapperRegistry,
() -> null,
indexSettings.getMode().idFieldMapperWithoutFieldData(),
scriptService
scriptService,
mapperMetrics
)
) {
mapperService.merge(indexMetadata, MapperService.MergeReason.MAPPING_RECOVERY);
Expand Down
13 changes: 9 additions & 4 deletions server/src/main/java/org/elasticsearch/index/IndexModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.store.FsDirectoryFactory;
import org.elasticsearch.indices.IndicesQueryCache;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
import org.elasticsearch.indices.recovery.RecoveryState;
Expand Down Expand Up @@ -475,7 +476,8 @@ public IndexService newIndexService(
IdFieldMapper idFieldMapper,
ValuesSourceRegistry valuesSourceRegistry,
IndexStorePlugin.IndexFoldersDeletionListener indexFoldersDeletionListener,
Map<String, IndexStorePlugin.SnapshotCommitSupplier> snapshotCommitSuppliers
Map<String, IndexStorePlugin.SnapshotCommitSupplier> snapshotCommitSuppliers,
MapperMetrics metrics
) throws IOException {
final IndexEventListener eventListener = freeze();
Function<IndexService, CheckedFunction<DirectoryReader, DirectoryReader, IOException>> readerWrapperFactory = indexReaderWrapper
Expand Down Expand Up @@ -536,7 +538,8 @@ public IndexService newIndexService(
recoveryStateFactory,
indexFoldersDeletionListener,
snapshotCommitSupplier,
indexCommitListener.get()
indexCommitListener.get(),
metrics
);
success = true;
return indexService;
Expand Down Expand Up @@ -633,7 +636,8 @@ public MapperService newIndexMapperService(
ClusterService clusterService,
XContentParserConfiguration parserConfiguration,
MapperRegistry mapperRegistry,
ScriptService scriptService
ScriptService scriptService,
MapperMetrics mapperMetrics
) throws IOException {
return new MapperService(
clusterService,
Expand All @@ -646,7 +650,8 @@ public MapperService newIndexMapperService(
throw new UnsupportedOperationException("no index query shard context available");
},
indexSettings.getMode().idFieldMapperWithoutFieldData(),
scriptService
scriptService,
mapperMetrics
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.index.store.Store;
import org.elasticsearch.index.translog.Translog;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.indices.cluster.IndicesClusterStateService;
import org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache;
Expand Down Expand Up @@ -191,7 +192,8 @@ public IndexService(
IndexStorePlugin.RecoveryStateFactory recoveryStateFactory,
IndexStorePlugin.IndexFoldersDeletionListener indexFoldersDeletionListener,
IndexStorePlugin.SnapshotCommitSupplier snapshotCommitSupplier,
Engine.IndexCommitListener indexCommitListener
Engine.IndexCommitListener indexCommitListener,
MapperMetrics mapperMetrics
) {
super(indexSettings);
assert indexCreationContext != IndexCreationContext.RELOAD_ANALYZERS
Expand All @@ -218,7 +220,8 @@ public IndexService(
// we parse all percolator queries as they would be parsed on shard 0
() -> newSearchExecutionContext(0, 0, null, System::currentTimeMillis, null, emptyMap()),
idFieldMapper,
scriptService
scriptService,
mapperMetrics
);
this.indexFieldData = new IndexFieldDataService(indexSettings, indicesFieldDataCache, circuitBreakerService);
if (indexSettings.getIndexSortConfig().hasIndexSort()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,7 @@ private GetResult innerGetFetch(
Map<String, DocumentField> documentFields = null;
Map<String, DocumentField> metadataFields = null;
DocIdAndVersion docIdAndVersion = get.docIdAndVersion();
SourceLoader loader = forceSyntheticSource
? new SourceLoader.Synthetic(mappingLookup.getMapping())
: mappingLookup.newSourceLoader();
SourceLoader loader = mapperService.getSourceLoader(mappingLookup, forceSyntheticSource);
StoredFieldLoader storedFieldLoader = buildStoredFieldLoader(storedFields, fetchSourceContext, loader);
LeafStoredFieldLoader leafStoredFieldLoader = storedFieldLoader.getLoader(docIdAndVersion.reader.getContext(), null);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.similarity.SimilarityService;
import org.elasticsearch.indices.IndicesModule;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.script.ScriptCompiler;
import org.elasticsearch.xcontent.NamedXContentRegistry;
import org.elasticsearch.xcontent.ToXContent;
Expand Down Expand Up @@ -152,6 +153,7 @@ public boolean isAutoUpdate() {
private final IndexVersion indexVersionCreated;
private final MapperRegistry mapperRegistry;
private final Supplier<MappingParserContext> mappingParserContextSupplier;
private final MapperMetrics mapperMetrics;

private volatile DocumentMapper mapper;
private volatile long mappingVersion;
Expand All @@ -165,7 +167,8 @@ public MapperService(
MapperRegistry mapperRegistry,
Supplier<SearchExecutionContext> searchExecutionContextSupplier,
IdFieldMapper idFieldMapper,
ScriptCompiler scriptCompiler
ScriptCompiler scriptCompiler,
MapperMetrics metrics
) {
this(
() -> clusterService.state().getMinTransportVersion(),
Expand All @@ -176,7 +179,8 @@ public MapperService(
mapperRegistry,
searchExecutionContextSupplier,
idFieldMapper,
scriptCompiler
scriptCompiler,
metrics
);
}

Expand All @@ -190,7 +194,8 @@ public MapperService(
MapperRegistry mapperRegistry,
Supplier<SearchExecutionContext> searchExecutionContextSupplier,
IdFieldMapper idFieldMapper,
ScriptCompiler scriptCompiler
ScriptCompiler scriptCompiler,
MapperMetrics mapperMetrics
) {
super(indexSettings);
this.indexVersionCreated = indexSettings.getIndexVersionCreated();
Expand All @@ -206,7 +211,8 @@ public MapperService(
scriptCompiler,
indexAnalyzers,
indexSettings,
idFieldMapper
idFieldMapper,
mapperMetrics
);
this.documentParser = new DocumentParser(parserConfiguration, this.mappingParserContextSupplier.get());
Map<String, MetadataFieldMapper.TypeParser> metadataMapperParsers = mapperRegistry.getMetadataMapperParsers(
Expand All @@ -218,6 +224,7 @@ public MapperService(
this::getMetadataMappers,
this::resolveDocumentType
);
this.mapperMetrics = mapperMetrics;
}

public boolean hasNested() {
Expand Down Expand Up @@ -779,4 +786,12 @@ public DynamicTemplate[] getAllDynamicTemplates() {
public MapperRegistry getMapperRegistry() {
return mapperRegistry;
}

public SourceLoader getSourceLoader(MappingLookup mappingLookup, boolean forceSyntheticSource) {
if (forceSyntheticSource) {
return new SourceLoader.Synthetic(mappingLookup.getMapping(), mapperMetrics.getSyntheticSourceMetrics());
}

return mappingLookup.newSourceLoader();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.elasticsearch.index.analysis.IndexAnalyzers;
import org.elasticsearch.index.query.SearchExecutionContext;
import org.elasticsearch.index.similarity.SimilarityProvider;
import org.elasticsearch.indices.MapperMetrics;
import org.elasticsearch.script.ScriptCompiler;

import java.util.function.Function;
Expand All @@ -38,6 +39,7 @@ public class MappingParserContext {
private final IndexSettings indexSettings;
private final IdFieldMapper idFieldMapper;
private final long mappingObjectDepthLimit;
private final MapperMetrics mapperMetrics;
private long mappingObjectDepth = 0;

public MappingParserContext(
Expand All @@ -50,7 +52,8 @@ public MappingParserContext(
ScriptCompiler scriptCompiler,
IndexAnalyzers indexAnalyzers,
IndexSettings indexSettings,
IdFieldMapper idFieldMapper
IdFieldMapper idFieldMapper,
MapperMetrics mapperMetrics
) {
this.similarityLookupService = similarityLookupService;
this.typeParsers = typeParsers;
Expand All @@ -63,6 +66,7 @@ public MappingParserContext(
this.indexSettings = indexSettings;
this.idFieldMapper = idFieldMapper;
this.mappingObjectDepthLimit = indexSettings.getMappingDepthLimit();
this.mapperMetrics = mapperMetrics;
}

public IndexAnalyzers getIndexAnalyzers() {
Expand Down Expand Up @@ -132,6 +136,10 @@ public ScriptCompiler scriptCompiler() {
return scriptCompiler;
}

public MapperMetrics getIndicesMetrics() {
return mapperMetrics;
}

void incrementMappingObjectDepth() throws MapperParsingException {
mappingObjectDepth++;
if (mappingObjectDepth > mappingObjectDepthLimit) {
Expand Down Expand Up @@ -159,7 +167,8 @@ private static class MultiFieldParserContext extends MappingParserContext {
in.scriptCompiler,
in.indexAnalyzers,
in.indexSettings,
in.idFieldMapper
in.idFieldMapper,
in.mapperMetrics
);
}

Expand Down Expand Up @@ -188,7 +197,8 @@ private static class DynamicTemplateParserContext extends MappingParserContext {
in.scriptCompiler,
in.indexAnalyzers,
in.indexSettings,
in.idFieldMapper
in.idFieldMapper,
in.mapperMetrics
);
this.dateFormatter = dateFormatter;
}
Expand Down
Loading

0 comments on commit 906bc40

Please sign in to comment.