-
Notifications
You must be signed in to change notification settings - Fork 25.7k
WIP: Index size records #97860
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
WIP: Index size records #97860
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
59f2a4b
IX Plugin WIP
stu-elastic 62ad4dd
Merge branch 'main' of github.com:elastic/elasticsearch into ix-meter…
stu-elastic a4c8a61
Move to x-pack so the plugin loads
stu-elastic b0a9245
Schedule and grab stats
stu-elastic a0d319b
Checkpoint
stu-elastic fa8a4df
Basic IX polling via engine
stu-elastic 589fd59
spotless
stu-elastic f50ebee
license headers
stu-elastic 9fdcbd5
logger
stu-elastic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * 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-es-plugin' | ||
|
|
||
| esplugin { | ||
| name 'metering-ix' | ||
| description 'Metering IX' | ||
| classname 'org.elasticsearch.xpack.meter.ix.MeterIXPlugin' | ||
| extendedPlugins = ['x-pack-core'] | ||
| } | ||
|
|
||
| base { | ||
| archivesName = 'x-pack-monitoring' | ||
| } | ||
|
|
||
| dependencies { | ||
| compileOnly project(":server") | ||
| compileOnly project(path: xpackModule('core')) | ||
| } |
50 changes: 50 additions & 0 deletions
50
x-pack/plugin/metering-ix/src/main/java/org/elasticsearch/xpack/meter/ix/MeterIXPlugin.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.meter.ix; | ||
|
|
||
| import org.elasticsearch.client.internal.Client; | ||
| import org.elasticsearch.cluster.metadata.IndexNameExpressionResolver; | ||
| import org.elasticsearch.cluster.routing.allocation.AllocationService; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
| import org.elasticsearch.env.Environment; | ||
| import org.elasticsearch.env.NodeEnvironment; | ||
| import org.elasticsearch.indices.IndicesService; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.repositories.RepositoriesService; | ||
| import org.elasticsearch.script.ScriptService; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
| import org.elasticsearch.tracing.Tracer; | ||
| import org.elasticsearch.watcher.ResourceWatcherService; | ||
| import org.elasticsearch.xcontent.NamedXContentRegistry; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
| import java.util.function.Supplier; | ||
|
|
||
| public class MeterIXPlugin extends Plugin { | ||
| @Override | ||
| public Collection<Object> createComponents( | ||
| Client client, | ||
| ClusterService clusterService, | ||
| ThreadPool threadPool, | ||
| ResourceWatcherService resourceWatcherService, | ||
| ScriptService scriptService, | ||
| NamedXContentRegistry xContentRegistry, | ||
| Environment environment, | ||
| NodeEnvironment nodeEnvironment, | ||
| NamedWriteableRegistry namedWriteableRegistry, | ||
| IndexNameExpressionResolver indexNameExpressionResolver, | ||
| Supplier<RepositoriesService> repositoriesServiceSupplier, | ||
| Tracer tracer, | ||
| AllocationService allocationService, | ||
| IndicesService indicesService | ||
| ) { | ||
| return List.of(new MeterIXPoller(threadPool, indicesService)); | ||
| } | ||
| } |
153 changes: 153 additions & 0 deletions
153
x-pack/plugin/metering-ix/src/main/java/org/elasticsearch/xpack/meter/ix/MeterIXPoller.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| /* | ||
| * 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; you may not use this file except in compliance with the Elastic License | ||
| * 2.0. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.meter.ix; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.apache.lucene.index.SegmentCommitInfo; | ||
| import org.apache.lucene.util.StringHelper; | ||
| import org.elasticsearch.common.component.Lifecycle; | ||
| import org.elasticsearch.common.component.LifecycleComponent; | ||
| import org.elasticsearch.common.component.LifecycleListener; | ||
| import org.elasticsearch.core.TimeValue; | ||
| import org.elasticsearch.index.IndexService; | ||
| import org.elasticsearch.index.engine.Engine; | ||
| import org.elasticsearch.index.shard.IndexShard; | ||
| import org.elasticsearch.indices.IndicesService; | ||
| import org.elasticsearch.threadpool.Scheduler; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.locks.ReentrantLock; | ||
|
|
||
| public class MeterIXPoller implements LifecycleComponent { | ||
| private static final Logger logger = LogManager.getLogger(MeterIXPoller.class); | ||
| final ThreadPool threadPool; | ||
| final IndicesService indicesService; | ||
| Lifecycle.State state = Lifecycle.State.INITIALIZED; | ||
| Scheduler.ScheduledCancellable next = null; | ||
| private final ReentrantLock mutex = new ReentrantLock(); | ||
|
|
||
| public MeterIXPoller(ThreadPool threadPool, IndicesService indicesService) { | ||
| this.threadPool = threadPool; | ||
| this.indicesService = indicesService; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| mutex.lock(); | ||
| try { | ||
| if (state != Lifecycle.State.STOPPED && state != Lifecycle.State.CLOSED) { | ||
| state = Lifecycle.State.CLOSED; | ||
| if (next != null) { | ||
| next.cancel(); | ||
| } | ||
| next = null; | ||
| } | ||
| } finally { | ||
| mutex.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public Lifecycle.State lifecycleState() { | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public void addLifecycleListener(LifecycleListener listener) { | ||
|
|
||
| } | ||
|
|
||
| @Override | ||
| public void start() { | ||
| mutex.lock(); | ||
| try { | ||
| if (state == Lifecycle.State.INITIALIZED) { | ||
| state = Lifecycle.State.STARTED; | ||
| setScheduleNext(); | ||
| } | ||
| } finally { | ||
| mutex.unlock(); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void stop() { | ||
| mutex.lock(); | ||
| try { | ||
| if (state != Lifecycle.State.STOPPED && state != Lifecycle.State.CLOSED) { | ||
| state = Lifecycle.State.STOPPED; | ||
| if (next != null) { | ||
| next.cancel(); | ||
| } | ||
| next = null; | ||
| } | ||
| } finally { | ||
| mutex.unlock(); | ||
| } | ||
| } | ||
|
|
||
| private void setScheduleNext() { | ||
| next = threadPool.schedule(this::logAndSchedule, TimeValue.timeValueSeconds(20), ThreadPool.Names.GENERIC); | ||
| } | ||
|
|
||
| public void logAndSchedule() { | ||
| logIndexStats(); | ||
| mutex.lock(); | ||
| try { | ||
| if (state == Lifecycle.State.STARTED) { | ||
| setScheduleNext(); | ||
| } | ||
| } finally { | ||
| mutex.unlock(); | ||
| } | ||
| } | ||
|
|
||
| public void logIndexStats() { | ||
| logger.warn("[IX] logIndexStats"); | ||
| collectRecords(); | ||
| logger.warn("[IX] done logIndexStats"); | ||
| } | ||
|
|
||
| public List<IXRecord> collectRecords() { | ||
| List<IXRecord> records = new ArrayList<>(); | ||
| for (final IndexService indexService : indicesService) { | ||
| String index = indexService.index().getName(); | ||
| for (final IndexShard shard : indexService) { | ||
| Engine engine = shard.getEngineOrNull(); | ||
| if (engine == null) { | ||
| continue; | ||
| } | ||
| long term = shard.getOperationPrimaryTerm(); | ||
| int shardId = shard.shardId().id(); | ||
| for (final SegmentCommitInfo commitInfo : engine.getLastCommittedSegmentInfos()) { | ||
| try { | ||
| var record = new IXRecord( | ||
| index, | ||
| shardId, | ||
| term, | ||
| commitInfo.getDocValuesGen(), | ||
| StringHelper.idToString(commitInfo.getId()), | ||
| commitInfo.sizeInBytes() | ||
| ); | ||
| records.add(record); | ||
| logger.info("{}", record); | ||
| } catch (IOException err) { | ||
| logger.warn("error: [{}], index: [{}], shard: [{}], id: [{}]", err, index, shardId, commitInfo.getId()); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| return records; | ||
| } | ||
|
|
||
| private record IXRecord(String index, int shardId, long term, long generation, String commitId, long size) {} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the term, generation, and commitId recorded for?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed in #97978 |
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AbstractLifecycleComponent does a lot of the logistics already?