Skip to content

Commit b34ca93

Browse files
authored
Enable DEBUG logging for FileSettingsServiceTests (#116192)
#115280 still mystifies me. It does not reproduce on a buildkite instance either. This PR turns up logging for the file watching service steps (in particular the polled events should be useful) and adds some logging to the test.
1 parent eef2ba4 commit b34ca93

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,6 @@ tests:
184184
- class: org.elasticsearch.search.StressSearchServiceReaperIT
185185
method: testStressReaper
186186
issue: https://github.com/elastic/elasticsearch/issues/115816
187-
- class: org.elasticsearch.reservedstate.service.FileSettingsServiceTests
188-
method: testProcessFileChanges
189-
issue: https://github.com/elastic/elasticsearch/issues/115280
190187
- class: org.elasticsearch.search.SearchServiceTests
191188
method: testWaitOnRefreshTimeout
192189
issue: https://github.com/elastic/elasticsearch/issues/115935

server/src/test/java/org/elasticsearch/reservedstate/service/FileSettingsServiceTests.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
package org.elasticsearch.reservedstate.service;
1111

12+
import org.apache.logging.log4j.Level;
13+
import org.apache.logging.log4j.LogManager;
14+
import org.apache.logging.log4j.Logger;
1215
import org.elasticsearch.action.ActionListener;
1316
import org.elasticsearch.cluster.ClusterChangedEvent;
1417
import org.elasticsearch.cluster.ClusterName;
@@ -22,6 +25,8 @@
2225
import org.elasticsearch.cluster.routing.RerouteService;
2326
import org.elasticsearch.cluster.service.ClusterService;
2427
import org.elasticsearch.common.component.Lifecycle;
28+
import org.elasticsearch.common.file.AbstractFileWatchingService;
29+
import org.elasticsearch.common.logging.Loggers;
2530
import org.elasticsearch.common.settings.ClusterSettings;
2631
import org.elasticsearch.common.settings.Settings;
2732
import org.elasticsearch.core.IOUtils;
@@ -67,6 +72,7 @@
6772
import static org.mockito.Mockito.verify;
6873

6974
public class FileSettingsServiceTests extends ESTestCase {
75+
private static final Logger logger = LogManager.getLogger(FileSettingsServiceTests.class);
7076
private Environment env;
7177
private ClusterService clusterService;
7278
private ReservedClusterStateService controller;
@@ -76,6 +82,8 @@ public class FileSettingsServiceTests extends ESTestCase {
7682
@Before
7783
public void setUp() throws Exception {
7884
super.setUp();
85+
// TODO remove me once https://github.com/elastic/elasticsearch/issues/115280 is closed
86+
Loggers.setLevel(LogManager.getLogger(AbstractFileWatchingService.class), Level.DEBUG);
7987

8088
threadpool = new TestThreadPool("file_settings_service_tests");
8189

@@ -120,16 +128,23 @@ public void setUp() throws Exception {
120128

121129
@After
122130
public void tearDown() throws Exception {
123-
if (fileSettingsService.lifecycleState() == Lifecycle.State.STARTED) {
124-
fileSettingsService.stop();
125-
}
126-
if (fileSettingsService.lifecycleState() == Lifecycle.State.STOPPED) {
127-
fileSettingsService.close();
128-
}
131+
try {
132+
if (fileSettingsService.lifecycleState() == Lifecycle.State.STARTED) {
133+
logger.info("Stopping file settings service");
134+
fileSettingsService.stop();
135+
}
136+
if (fileSettingsService.lifecycleState() == Lifecycle.State.STOPPED) {
137+
logger.info("Closing file settings service");
138+
fileSettingsService.close();
139+
}
129140

130-
super.tearDown();
131-
clusterService.close();
132-
threadpool.shutdownNow();
141+
super.tearDown();
142+
clusterService.close();
143+
threadpool.shutdownNow();
144+
} finally {
145+
// TODO remove me once https://github.com/elastic/elasticsearch/issues/115280 is closed
146+
Loggers.setLevel(LogManager.getLogger(AbstractFileWatchingService.class), Level.INFO);
147+
}
133148
}
134149

135150
public void testStartStop() {
@@ -355,17 +370,25 @@ public void testHandleSnapshotRestoreResetsMetadata() throws Exception {
355370
private static void writeTestFile(Path path, String contents) {
356371
Path tempFile = null;
357372
try {
373+
logger.info("Creating settings temp file under [{}]", path.toAbsolutePath());
358374
tempFile = Files.createTempFile(path.getParent(), path.getFileName().toString(), "tmp");
375+
logger.info("Created settings temp file [{}]", tempFile.getFileName());
359376
Files.writeString(tempFile, contents);
360377

361378
try {
379+
logger.info("Moving settings temp file to replace [{}]", tempFile.getFileName());
362380
Files.move(tempFile, path, REPLACE_EXISTING, ATOMIC_MOVE);
363381
} catch (AtomicMoveNotSupportedException e) {
382+
logger.info(
383+
"Atomic move was not available. Falling back on non-atomic move for settings temp file to replace [{}]",
384+
tempFile.getFileName()
385+
);
364386
Files.move(tempFile, path, REPLACE_EXISTING);
365387
}
366388
} catch (final IOException e) {
367389
throw new UncheckedIOException(Strings.format("could not write file [%s]", path.toAbsolutePath()), e);
368390
} finally {
391+
logger.info("Deleting settings temp file [{}]", tempFile != null ? tempFile.getFileName() : null);
369392
// we are ignoring exceptions here, so we do not need handle whether or not tempFile was initialized nor if the file exists
370393
IOUtils.deleteFilesIgnoringExceptions(tempFile);
371394
}

0 commit comments

Comments
 (0)