Search in sources :

Example 11 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class PersistentTasksDecidersTestCase method updateSettings.

protected void updateSettings(final Settings settings) {
    ClusterSettings clusterSettings = clusterService.getClusterSettings();
    Settings.Builder updated = Settings.builder();
    clusterSettings.updateDynamicSettings(settings, updated, Settings.builder(), getTestClass().getName());
    clusterSettings.applySettings(updated.build());
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) ClusterSettings(org.opensearch.common.settings.ClusterSettings)

Example 12 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class ResponseCollectorServiceTests method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    threadpool = new TestThreadPool("response_collector_tests");
    clusterService = new ClusterService(Settings.EMPTY, new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), threadpool);
    collector = new ResponseCollectorService(clusterService);
}
Also used : ClusterService(org.opensearch.cluster.service.ClusterService) ClusterSettings(org.opensearch.common.settings.ClusterSettings) TestThreadPool(org.opensearch.threadpool.TestThreadPool) Before(org.junit.Before)

Example 13 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class FsHealthServiceTests method testLoggingOnHungIO.

@TestLogging(value = "org.opensearch.monitor.fs:WARN", reason = "to ensure that we log on hung IO at WARN level")
public void testLoggingOnHungIO() throws Exception {
    long slowLogThreshold = randomLongBetween(100, 200);
    final Settings settings = Settings.builder().put(FsHealthService.SLOW_PATH_LOGGING_THRESHOLD_SETTING.getKey(), slowLogThreshold + "ms").build();
    FileSystem fileSystem = PathUtils.getDefaultFileSystem();
    TestThreadPool testThreadPool = new TestThreadPool(getClass().getName(), settings);
    FileSystemFsyncHungProvider disruptFileSystemProvider = new FileSystemFsyncHungProvider(fileSystem, randomLongBetween(slowLogThreshold + 1, 400), testThreadPool);
    fileSystem = disruptFileSystemProvider.getFileSystem(null);
    PathUtilsForTesting.installMock(fileSystem);
    final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    try (MockLogAppender mockAppender = MockLogAppender.createForLoggers(LogManager.getLogger(FsHealthService.class));
        NodeEnvironment env = newNodeEnvironment()) {
        FsHealthService fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
        int counter = 0;
        for (Path path : env.nodeDataPaths()) {
            mockAppender.addExpectation(new MockLogAppender.SeenEventExpectation("test" + ++counter, FsHealthService.class.getCanonicalName(), Level.WARN, "health check of [" + path + "] took [*ms] which is above the warn threshold*"));
        }
        // disrupt file system
        disruptFileSystemProvider.injectIODelay.set(true);
        fsHealthService.new FsHealthMonitor().run();
        assertEquals(env.nodeDataPaths().length, disruptFileSystemProvider.getInjectedPathCount());
        assertBusy(mockAppender::assertAllExpectationsMatched);
    } finally {
        PathUtilsForTesting.teardown();
        ThreadPool.terminate(testThreadPool, 500, TimeUnit.MILLISECONDS);
    }
}
Also used : Path(java.nio.file.Path) ClusterSettings(org.opensearch.common.settings.ClusterSettings) MockLogAppender(org.opensearch.test.MockLogAppender) NodeEnvironment(org.opensearch.env.NodeEnvironment) TestThreadPool(org.opensearch.threadpool.TestThreadPool) FileSystem(java.nio.file.FileSystem) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings) TestLogging(org.opensearch.test.junit.annotations.TestLogging)

Example 14 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class FsHealthServiceTests method testFailsHealthOnUnexpectedLockFileSize.

public void testFailsHealthOnUnexpectedLockFileSize() throws IOException {
    FileSystem fileSystem = PathUtils.getDefaultFileSystem();
    final Settings settings = Settings.EMPTY;
    TestThreadPool testThreadPool = new TestThreadPool(getClass().getName(), settings);
    FileSystemUnexpectedLockFileSizeProvider unexpectedLockFileSizeFileSystemProvider = new FileSystemUnexpectedLockFileSizeProvider(fileSystem, 1, testThreadPool);
    fileSystem = unexpectedLockFileSizeFileSystemProvider.getFileSystem(null);
    PathUtilsForTesting.installMock(fileSystem);
    final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    try (NodeEnvironment env = newNodeEnvironment()) {
        FsHealthService fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
        fsHealthService.new FsHealthMonitor().run();
        assertEquals(HEALTHY, fsHealthService.getHealth().getStatus());
        assertEquals("health check passed", fsHealthService.getHealth().getInfo());
        // enabling unexpected file size injection
        unexpectedLockFileSizeFileSystemProvider.injectUnexpectedFileSize.set(true);
        fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
        fsHealthService.new FsHealthMonitor().run();
        assertEquals(UNHEALTHY, fsHealthService.getHealth().getStatus());
        assertThat(fsHealthService.getHealth().getInfo(), is("health check failed due to broken node lock"));
        assertEquals(1, unexpectedLockFileSizeFileSystemProvider.getInjectedPathCount());
    } finally {
        unexpectedLockFileSizeFileSystemProvider.injectUnexpectedFileSize.set(false);
        PathUtilsForTesting.teardown();
        ThreadPool.terminate(testThreadPool, 500, TimeUnit.MILLISECONDS);
    }
}
Also used : ClusterSettings(org.opensearch.common.settings.ClusterSettings) NodeEnvironment(org.opensearch.env.NodeEnvironment) FileSystem(java.nio.file.FileSystem) TestThreadPool(org.opensearch.threadpool.TestThreadPool) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Example 15 with ClusterSettings

use of org.opensearch.common.settings.ClusterSettings in project OpenSearch by opensearch-project.

the class FsHealthServiceTests method testFailsHealthOnSinglePathWriteFailure.

public void testFailsHealthOnSinglePathWriteFailure() throws IOException {
    FileSystem fileSystem = PathUtils.getDefaultFileSystem();
    FileSystemIOExceptionProvider disruptWritesFileSystemProvider = new FileSystemIOExceptionProvider(fileSystem);
    fileSystem = disruptWritesFileSystemProvider.getFileSystem(null);
    PathUtilsForTesting.installMock(fileSystem);
    final Settings settings = Settings.EMPTY;
    final ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
    TestThreadPool testThreadPool = new TestThreadPool(getClass().getName(), settings);
    try (NodeEnvironment env = newNodeEnvironment()) {
        Path[] paths = env.nodeDataPaths();
        FsHealthService fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
        fsHealthService.new FsHealthMonitor().run();
        assertEquals(HEALTHY, fsHealthService.getHealth().getStatus());
        assertEquals("health check passed", fsHealthService.getHealth().getInfo());
        // disrupt file system writes on single path
        String disruptedPath = randomFrom(paths).toString();
        disruptWritesFileSystemProvider.restrictPathPrefix(disruptedPath);
        disruptWritesFileSystemProvider.injectIOException.set(true);
        fsHealthService = new FsHealthService(settings, clusterSettings, testThreadPool, env);
        fsHealthService.new FsHealthMonitor().run();
        assertEquals(UNHEALTHY, fsHealthService.getHealth().getStatus());
        assertThat(fsHealthService.getHealth().getInfo(), is("health check failed on [" + disruptedPath + "]"));
        assertEquals(1, disruptWritesFileSystemProvider.getInjectedPathCount());
    } finally {
        disruptWritesFileSystemProvider.injectIOException.set(false);
        PathUtilsForTesting.teardown();
        ThreadPool.terminate(testThreadPool, 500, TimeUnit.MILLISECONDS);
    }
}
Also used : Path(java.nio.file.Path) ClusterSettings(org.opensearch.common.settings.ClusterSettings) NodeEnvironment(org.opensearch.env.NodeEnvironment) FileSystem(java.nio.file.FileSystem) TestThreadPool(org.opensearch.threadpool.TestThreadPool) ClusterSettings(org.opensearch.common.settings.ClusterSettings) Settings(org.opensearch.common.settings.Settings)

Aggregations

ClusterSettings (org.opensearch.common.settings.ClusterSettings)218 Settings (org.opensearch.common.settings.Settings)136 ClusterState (org.opensearch.cluster.ClusterState)70 ClusterService (org.opensearch.cluster.service.ClusterService)67 HashSet (java.util.HashSet)46 Metadata (org.opensearch.cluster.metadata.Metadata)37 Matchers.containsString (org.hamcrest.Matchers.containsString)36 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)36 Before (org.junit.Before)33 ArrayList (java.util.ArrayList)31 IndexMetadata (org.opensearch.cluster.metadata.IndexMetadata)31 ClusterName (org.opensearch.cluster.ClusterName)30 ThreadPool (org.opensearch.threadpool.ThreadPool)29 RoutingTable (org.opensearch.cluster.routing.RoutingTable)26 TestThreadPool (org.opensearch.threadpool.TestThreadPool)25 AtomicReference (java.util.concurrent.atomic.AtomicReference)23 Setting (org.opensearch.common.settings.Setting)23 ThreadContext (org.opensearch.common.util.concurrent.ThreadContext)23 IOException (java.io.IOException)19 BalancedShardsAllocator (org.opensearch.cluster.routing.allocation.allocator.BalancedShardsAllocator)19