Search in sources :

Example 1 with MeanMetric

use of org.opensearch.common.metrics.MeanMetric in project OpenSearch by opensearch-project.

the class RefreshListenersTests method setupListeners.

@Before
public void setupListeners() throws Exception {
    // Setup dependencies of the listeners
    maxListeners = randomIntBetween(1, 1000);
    // Now setup the InternalEngine which is much more complicated because we aren't mocking anything
    threadPool = new TestThreadPool(getTestName());
    refreshMetric = new MeanMetric();
    listeners = new RefreshListeners(() -> maxListeners, () -> engine.refresh("too-many-listeners"), logger, threadPool.getThreadContext(), refreshMetric);
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings("index", Settings.EMPTY);
    ShardId shardId = new ShardId(new Index("index", "_na_"), 1);
    String allocationId = UUIDs.randomBase64UUID(random());
    Directory directory = newDirectory();
    store = new Store(shardId, indexSettings, directory, new DummyShardLock(shardId));
    IndexWriterConfig iwc = newIndexWriterConfig();
    TranslogConfig translogConfig = new TranslogConfig(shardId, createTempDir("translog"), indexSettings, BigArrays.NON_RECYCLING_INSTANCE);
    Engine.EventListener eventListener = new Engine.EventListener() {

        @Override
        public void onFailedEngine(String reason, @Nullable Exception e) {
        // we don't need to notify anybody in this test
        }
    };
    store.createEmpty(Version.CURRENT.luceneVersion);
    final long primaryTerm = randomNonNegativeLong();
    final String translogUUID = Translog.createEmptyTranslog(translogConfig.getTranslogPath(), SequenceNumbers.NO_OPS_PERFORMED, shardId, primaryTerm);
    store.associateIndexWithNewTranslog(translogUUID);
    EngineConfig config = new EngineConfig(shardId, threadPool, indexSettings, null, store, newMergePolicy(), iwc.getAnalyzer(), iwc.getSimilarity(), new CodecService(null, logger), eventListener, IndexSearcher.getDefaultQueryCache(), IndexSearcher.getDefaultQueryCachingPolicy(), translogConfig, TimeValue.timeValueMinutes(5), Collections.singletonList(listeners), Collections.emptyList(), null, new NoneCircuitBreakerService(), () -> SequenceNumbers.NO_OPS_PERFORMED, () -> RetentionLeases.EMPTY, () -> primaryTerm, EngineTestCase.tombstoneDocSupplier());
    engine = new InternalEngine(config);
    engine.recoverFromTranslog((e, s) -> 0, Long.MAX_VALUE);
    listeners.setCurrentRefreshLocationSupplier(engine::getTranslogLastWriteLocation);
}
Also used : TranslogConfig(org.opensearch.index.translog.TranslogConfig) IndexSettings(org.opensearch.index.IndexSettings) Store(org.opensearch.index.store.Store) Index(org.opensearch.index.Index) TestThreadPool(org.opensearch.threadpool.TestThreadPool) IOException(java.io.IOException) InternalEngine(org.opensearch.index.engine.InternalEngine) MeanMetric(org.opensearch.common.metrics.MeanMetric) CodecService(org.opensearch.index.codec.CodecService) DummyShardLock(org.opensearch.test.DummyShardLock) EngineConfig(org.opensearch.index.engine.EngineConfig) InternalEngine(org.opensearch.index.engine.InternalEngine) Engine(org.opensearch.index.engine.Engine) Nullable(org.opensearch.common.Nullable) Directory(org.apache.lucene.store.Directory) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) NoneCircuitBreakerService(org.opensearch.indices.breaker.NoneCircuitBreakerService) Before(org.junit.Before)

Example 2 with MeanMetric

use of org.opensearch.common.metrics.MeanMetric in project OpenSearch by opensearch-project.

the class TcpTransport method getStats.

@Override
public final TransportStats getStats() {
    final MeanMetric writeBytesMetric = statsTracker.getWriteBytes();
    final long bytesWritten = statsTracker.getBytesWritten();
    final long messagesSent = statsTracker.getMessagesSent();
    final long messagesReceived = statsTracker.getMessagesReceived();
    final long bytesRead = statsTracker.getBytesRead();
    return new TransportStats(acceptedChannels.size(), outboundConnectionCount.get(), messagesReceived, bytesRead, messagesSent, bytesWritten);
}
Also used : MeanMetric(org.opensearch.common.metrics.MeanMetric)

Aggregations

MeanMetric (org.opensearch.common.metrics.MeanMetric)2 IOException (java.io.IOException)1 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)1 Directory (org.apache.lucene.store.Directory)1 Before (org.junit.Before)1 Nullable (org.opensearch.common.Nullable)1 Index (org.opensearch.index.Index)1 IndexSettings (org.opensearch.index.IndexSettings)1 CodecService (org.opensearch.index.codec.CodecService)1 Engine (org.opensearch.index.engine.Engine)1 EngineConfig (org.opensearch.index.engine.EngineConfig)1 InternalEngine (org.opensearch.index.engine.InternalEngine)1 Store (org.opensearch.index.store.Store)1 TranslogConfig (org.opensearch.index.translog.TranslogConfig)1 NoneCircuitBreakerService (org.opensearch.indices.breaker.NoneCircuitBreakerService)1 DummyShardLock (org.opensearch.test.DummyShardLock)1 TestThreadPool (org.opensearch.threadpool.TestThreadPool)1